Drop python 2 unicode tests for approx repr
This commit is contained in:
parent
ed9fda84d3
commit
34a02121ad
|
@ -24,37 +24,18 @@ class MyDocTestRunner(doctest.DocTestRunner):
|
||||||
|
|
||||||
|
|
||||||
class TestApprox:
|
class TestApprox:
|
||||||
@pytest.fixture
|
def test_repr_string(self):
|
||||||
def plus_minus(self):
|
assert repr(approx(1.0)) == "1.0 ± 1.0e-06"
|
||||||
return "\u00b1"
|
assert repr(approx([1.0, 2.0])) == "approx([1.0 ± 1.0e-06, 2.0 ± 2.0e-06])"
|
||||||
|
assert repr(approx((1.0, 2.0))) == "approx((1.0 ± 1.0e-06, 2.0 ± 2.0e-06))"
|
||||||
def test_repr_string(self, plus_minus):
|
|
||||||
tol1, tol2, infr = "1.0e-06", "2.0e-06", "inf"
|
|
||||||
assert repr(approx(1.0)) == "1.0 {pm} {tol1}".format(pm=plus_minus, tol1=tol1)
|
|
||||||
assert repr(
|
|
||||||
approx([1.0, 2.0])
|
|
||||||
) == "approx([1.0 {pm} {tol1}, 2.0 {pm} {tol2}])".format(
|
|
||||||
pm=plus_minus, tol1=tol1, tol2=tol2
|
|
||||||
)
|
|
||||||
assert repr(
|
|
||||||
approx((1.0, 2.0))
|
|
||||||
) == "approx((1.0 {pm} {tol1}, 2.0 {pm} {tol2}))".format(
|
|
||||||
pm=plus_minus, tol1=tol1, tol2=tol2
|
|
||||||
)
|
|
||||||
assert repr(approx(inf)) == "inf"
|
assert repr(approx(inf)) == "inf"
|
||||||
assert repr(approx(1.0, rel=nan)) == "1.0 {pm} ???".format(pm=plus_minus)
|
assert repr(approx(1.0, rel=nan)) == "1.0 ± ???"
|
||||||
assert repr(approx(1.0, rel=inf)) == "1.0 {pm} {infr}".format(
|
assert repr(approx(1.0, rel=inf)) == "1.0 ± inf"
|
||||||
pm=plus_minus, infr=infr
|
|
||||||
)
|
|
||||||
|
|
||||||
# Dictionaries aren't ordered, so we need to check both orders.
|
# Dictionaries aren't ordered, so we need to check both orders.
|
||||||
assert repr(approx({"a": 1.0, "b": 2.0})) in (
|
assert repr(approx({"a": 1.0, "b": 2.0})) in (
|
||||||
"approx({{'a': 1.0 {pm} {tol1}, 'b': 2.0 {pm} {tol2}}})".format(
|
"approx({'a': 1.0 ± 1.0e-06, 'b': 2.0 ± 2.0e-06})",
|
||||||
pm=plus_minus, tol1=tol1, tol2=tol2
|
"approx({'b': 2.0 ± 2.0e-06, 'a': 1.0 ± 1.0e-06})",
|
||||||
),
|
|
||||||
"approx({{'b': 2.0 {pm} {tol2}, 'a': 1.0 {pm} {tol1}}})".format(
|
|
||||||
pm=plus_minus, tol1=tol1, tol2=tol2
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_repr_complex_numbers(self):
|
def test_repr_complex_numbers(self):
|
||||||
|
@ -73,20 +54,20 @@ class TestApprox:
|
||||||
assert repr(approx(3.3 + 4.4 * 1j, abs=0.02)) == "(3.3+4.4j) ± 2.0e-02 ∠ ±180°"
|
assert repr(approx(3.3 + 4.4 * 1j, abs=0.02)) == "(3.3+4.4j) ± 2.0e-02 ∠ ±180°"
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"value, repr_string",
|
"value, expected_repr_string",
|
||||||
[
|
[
|
||||||
(5.0, "approx(5.0 {pm} 5.0e-06)"),
|
(5.0, "approx(5.0 ± 5.0e-06)"),
|
||||||
([5.0], "approx([5.0 {pm} 5.0e-06])"),
|
([5.0], "approx([5.0 ± 5.0e-06])"),
|
||||||
([[5.0]], "approx([[5.0 {pm} 5.0e-06]])"),
|
([[5.0]], "approx([[5.0 ± 5.0e-06]])"),
|
||||||
([[5.0, 6.0]], "approx([[5.0 {pm} 5.0e-06, 6.0 {pm} 6.0e-06]])"),
|
([[5.0, 6.0]], "approx([[5.0 ± 5.0e-06, 6.0 ± 6.0e-06]])"),
|
||||||
([[5.0], [6.0]], "approx([[5.0 {pm} 5.0e-06], [6.0 {pm} 6.0e-06]])"),
|
([[5.0], [6.0]], "approx([[5.0 ± 5.0e-06], [6.0 ± 6.0e-06]])"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_repr_nd_array(self, plus_minus, value, repr_string):
|
def test_repr_nd_array(self, value, expected_repr_string):
|
||||||
"""Make sure that arrays of all different dimensions are repr'd correctly."""
|
"""Make sure that arrays of all different dimensions are repr'd correctly."""
|
||||||
np = pytest.importorskip("numpy")
|
np = pytest.importorskip("numpy")
|
||||||
np_array = np.array(value)
|
np_array = np.array(value)
|
||||||
assert repr(approx(np_array)) == repr_string.format(pm=plus_minus)
|
assert repr(approx(np_array)) == expected_repr_string
|
||||||
|
|
||||||
def test_operator_overloading(self):
|
def test_operator_overloading(self):
|
||||||
assert 1 == approx(1, rel=1e-6, abs=1e-12)
|
assert 1 == approx(1, rel=1e-6, abs=1e-12)
|
||||||
|
|
Loading…
Reference in New Issue