Skip to content

bpo-40331: Increase test coverage for the statistics module #19608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 13, 2020
Prev Previous commit
Next Next commit
Use assertRaises as a context manager in the tests
  • Loading branch information
tzabal committed Apr 25, 2020
commit 50a843fceff657a2107b37a7563deeec46a2e7b2
16 changes: 10 additions & 6 deletions Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,8 @@ def test_nan(self):
self.assertTrue(_nan_equal(x, nan))

def test_raise_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.

Let's rename this test_invalid_input_type()

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.assertRaises(TypeError, statistics._convert, None, float)
with self.assertRaises(TypeError):
statistics._convert(None, float)


class FailNegTest(unittest.TestCase):
Expand Down Expand Up @@ -1045,7 +1046,8 @@ def test_raise_value_error(self):
([1, 2], 3), # non-existing max value triggers `i != len(a)`
([1, 3], 2) # non-existing value triggers `a[i] == x`
]:
self.assertRaises(ValueError, statistics._find_lteq, a, x)
with self.assertRaises(ValueError):
statistics._find_lteq(a, x)

def test_locate_successfully(self):
for a, x, expected_i in [
Expand All @@ -1064,7 +1066,8 @@ def test_raise_value_error(self):
([1], 2, 1), # when l=len(a)+1 triggers `i != (len(a)+1)`
([1, 3], 0, 2) # non-existing value triggers `a[i-1] == x`
]:
self.assertRaises(ValueError, statistics._find_rteq, a, l, x)
with self.assertRaises(ValueError):
statistics._find_rteq(a, l, x)

def test_locate_successfully(self):
for a, l, x, expected_i in [
Expand Down Expand Up @@ -1496,9 +1499,6 @@ class TestHarmonicMean(NumericTestCase, AverageMixin, UnivariateTypeMixin):
def setUp(self):
self.func = statistics.harmonic_mean

def test_single_value_unsupported_type(self):
self.assertRaises(TypeError, self.func, ['3.14'])

def prepare_data(self):
# Override mixin method.
values = super().prepare_data()
Expand All @@ -1521,6 +1521,10 @@ def test_negative_error(self):
with self.subTest(values=values):
self.assertRaises(exc, self.func, values)

def test_single_value_unsupported_type(self):
with self.assertRaises(TypeError):
self.func(['3.14'])

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

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy