From 0df24bf93401fe06e0694d38492129807c8f11aa Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 1 Mar 2022 00:04:27 +0100 Subject: [PATCH] Simple cleanups. `__ne__` is specced to default to `not __eq__`, so we may just as well use that. Inline "test helpers" which probably made sense back when using nose, but not so much nowadays anymore. --- cycler.py | 3 --- test_cycler.py | 45 ++++++++++++++------------------------------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/cycler.py b/cycler.py index f86b68d..222a617 100644 --- a/cycler.py +++ b/cycler.py @@ -331,9 +331,6 @@ def __eq__(self, other): return False return all(a == b for a, b in zip(self, other)) - def __ne__(self, other): - return not (self == other) - __hash__ = None def __repr__(self): diff --git a/test_cycler.py b/test_cycler.py index 67f708f..a9130ff 100644 --- a/test_cycler.py +++ b/test_cycler.py @@ -153,31 +153,24 @@ def test_fail_getime(): pytest.raises(ValueError, Cycler.__getitem__, c1, [0, 1]) -def _repr_tester_helper(rpr_func, cyc, target_repr): - test_repr = getattr(cyc, rpr_func)() - - assert str(test_repr) == str(target_repr) - - def test_repr(): c = cycler(c='rgb') # Using an identifier that would be not valid as a kwarg c2 = cycler('3rd', range(3)) - c_sum_rpr = "(cycler('c', ['r', 'g', 'b']) + cycler('3rd', [0, 1, 2]))" - c_prod_rpr = "(cycler('c', ['r', 'g', 'b']) * cycler('3rd', [0, 1, 2]))" - - _repr_tester_helper('__repr__', c + c2, c_sum_rpr) - _repr_tester_helper('__repr__', c * c2, c_prod_rpr) + assert repr(c + c2) == ( + "(cycler('c', ['r', 'g', 'b']) + cycler('3rd', [0, 1, 2]))") + assert repr(c * c2) == ( + "(cycler('c', ['r', 'g', 'b']) * cycler('3rd', [0, 1, 2]))") - sum_html = ( + assert (c + c2)._repr_html_() == ( "" "" "" "" "" "
'3rd''c'
0'r'
1'g'
2'b'
") - prod_html = ( + assert (c * c2)._repr_html_() == ( "" "" "" @@ -191,9 +184,6 @@ def test_repr(): "" "
'3rd''c'
0'r'
2'b'
") - _repr_tester_helper('_repr_html_', c + c2, sum_html) - _repr_tester_helper('_repr_html_', c * c2, prod_html) - def test_call(): c = cycler(c='rgb') @@ -276,27 +266,20 @@ def test_keychange(): pytest.raises(KeyError, Cycler.change_key, c, 'c', 'foobar') -def _eq_test_helper(a, b, res): - if res: - assert a == b - else: - assert a != b - - def test_eq(): a = cycler(c='rgb') b = cycler(c='rgb') - _eq_test_helper(a, b, True) - _eq_test_helper(a, b[::-1], False) + assert a == b + assert a != b[::-1] c = cycler(lw=range(3)) - _eq_test_helper(a+c, c+a, True) - _eq_test_helper(a+c, c+b, True) - _eq_test_helper(a*c, c*a, False) - _eq_test_helper(a, c, False) + assert a + c == c + a + assert a + c == c + b + assert a * c != c * a + assert a != c d = cycler(c='ymk') - _eq_test_helper(b, d, False) + assert b != d e = cycler(c='orange') - _eq_test_helper(b, e, False) + assert b != e def test_cycler_exceptions():