The test for randlast in test_last_name_year currently checks that the returned value is a string, but does not verify additional constraints on the output format and value. To improve test coverage and robustness, we should add assertions to ensure:
- The returned last name is non-empty.
- The last name contains only alphabetic characters (no digits or special characters).
- The length of the last name is at least 2 characters and less than 50 characters.
Suggested code for the test:
def test_last_name_year(self):
year = random.choice(self.last_names_year_range)
result = randname.core.randlast(country=self.country, year=year)
self.assertIsInstance(result, str)
self.assertTrue(result, "Returned last name should not be empty")
self.assertTrue(result.isalpha(), "Last name should contain only alphabetic characters")
self.assertGreaterEqual(len(result), 2, "Last name should be at least 2 characters long")
self.assertLess(len(result), 50, "Last name should be less than 50 characters long")
Action items:
- Update the test to include the above assertions.
- Review other similar tests to ensure output constraints are consistently checked.
I created this issue for @ajwalkiewicz from #17 (comment).
Tips and commands
Getting Help
The test for
randlastintest_last_name_yearcurrently checks that the returned value is a string, but does not verify additional constraints on the output format and value. To improve test coverage and robustness, we should add assertions to ensure:Suggested code for the test:
Action items:
I created this issue for @ajwalkiewicz from #17 (comment).
Tips and commands
Getting Help