Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for TypeError handling
  • Loading branch information
pganssle committed Apr 29, 2019
commit 46c6458bc0fab491b556b8c8b611b7c1203ff0dc
18 changes: 18 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,24 @@ def test_fromisocalendar_value_errors(self):
with self.assertRaises(ValueError):
self.theclass.fromisocalendar(*isocal)

def test_fromisocalendar_type_errors(self):
isocals = [
("2019", 1, 1),
(2019, "1", 1),
(2019, 1, "1"),
(None, 1, 1),
(2019, None, 1),
(2019, 1, None),
(2019.0, 1, 1),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'll note is that this is consistent with datetime.date itself not accepting floats. I'm not sure how much I agree with that, I just wanted to put it in the tests to ensure consistency between the C and Python versions.

(2019, 1.0, 1),
(2019, 1, 1.0),
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use 3 loops to test all combinations, rather than generate these combinations manualy?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've converted it over. I think it's a little harder to understand what's going on in the version where the test cases are generated (compared to manual), but using a loop also has its advantages.


for isocal in isocals:
with self.subTest(isocal=isocal):
with self.assertRaises(TypeError):
self.theclass.fromisocalendar(*isocal)


#############################################################################
# datetime tests
Expand Down