Skip to content
Prev Previous commit
Next Next commit
Add test for inputs with multiple mixed valid/invalid values
  • Loading branch information
tzabal committed Apr 26, 2020
commit 74b047a86a0383fc8a487bc5d89ac5f3fad1218a
10 changes: 10 additions & 0 deletions Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,16 @@ def test_single_value_unsupported_type(self):
with self.assertRaisesRegex(TypeError, '^unsupported type$'):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the value of this regex here: Would it be wrong if we changed the error message in the future? I prefer that we just check that a TypeError is raised.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

self.func(['3.14'])

def test_multiple_values_type_error(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be combined with the previous test method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, now they assert the same behavior, with the same way. I will combine them under a test with name test_invalid_type_error.

# Test TypeError is raised when given multiple (valid/invalid) values
for data in [
['1', '2', '3'], # only strings
[1, '2', 3, '4', 5], # mixed strings and valid integers
[2.3, 3.4, 4.5, '5.6'] # only one string and valid floats
]:
with self.assertRaises(TypeError):
self.func(data)

def test_ints(self):
# Test harmonic mean with ints.
data = [2, 4, 4, 8, 16, 16]
Expand Down