From cc01fc523b6f26ffdf5721baac6696e464c2fbeaa79b71cc9a8050dd4480e103 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Date: Wed, 22 Mar 2023 07:37:23 +0000 Subject: [PATCH] - Fix the version in the package, it was set to 2.2.0, but the version provided was 2.0.0. - Disable broken tests with python 3.11, related to ordering of sets - Remove six dependency - Update to version 2.1.0: * Bump version * Seems like this is never used * Better exception testing pattern, better test coverage :) * Remove python <2.6 stuff; and an adhoc nose test runner * Only round, not convert to hashable, when comparing dict values * Coverage reporting * PEP8 and other good practice fixes * Add LICENSE file, build wheels * Move tests into package subdir * Add tox.ini and test against more versions of python * fix __bool__ case when dict only has equal type diffs * fuzzy matching for float comparisons, fix empty set diffs * test_hashable_dict_values * revert datadiff/tools.py hashable to maintain module_nose.tools compatibility * use hashable when comparing OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-datadiff?expand=0&rev=4 --- _service | 4 +- _servicedata | 2 +- datadiff-2.1.0.tar.xz | 3 + datadiff-2.2.0.tar.xz | 3 - python-datadiff.changes | 24 +++ python-datadiff.spec | 16 +- switch-to-pytest.patch | 317 ++++++++++++++++++++++------------------ 7 files changed, 214 insertions(+), 155 deletions(-) create mode 100644 datadiff-2.1.0.tar.xz delete mode 100644 datadiff-2.2.0.tar.xz diff --git a/_service b/_service index 609194b..f112117 100644 --- a/_service +++ b/_service @@ -2,11 +2,11 @@ https://git.code.sf.net/p/datadiff/code git - 43ef717 + 8ee0ad3 no enable datadiff - 2.2.0 + 2.1.0 *.tar diff --git a/_servicedata b/_servicedata index 84681c9..5f2c118 100644 --- a/_servicedata +++ b/_servicedata @@ -1,4 +1,4 @@ https://git.code.sf.net/p/datadiff/code - 43ef717bdbb03aeb708a34754c932ce4f3aaa637 \ No newline at end of file + 8ee0ad35cac2df636c04fdb55c4f81d1b3260430 \ No newline at end of file diff --git a/datadiff-2.1.0.tar.xz b/datadiff-2.1.0.tar.xz new file mode 100644 index 0000000..551abc7 --- /dev/null +++ b/datadiff-2.1.0.tar.xz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e497fa882a0cfc0e53e19490efc6d25605f2b4465b1be63fe105b7a704344a2e +size 10988 diff --git a/datadiff-2.2.0.tar.xz b/datadiff-2.2.0.tar.xz deleted file mode 100644 index 5fe2064..0000000 --- a/datadiff-2.2.0.tar.xz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c412dfdc93eee7adc6e8e8afbc65ee8a262b72c543698c6d1cda8db95b24e58a -size 7120 diff --git a/python-datadiff.changes b/python-datadiff.changes index 11b11c1..9deb56e 100644 --- a/python-datadiff.changes +++ b/python-datadiff.changes @@ -1,3 +1,27 @@ +------------------------------------------------------------------- +Wed Mar 22 06:43:10 UTC 2023 - daniel.garcia@suse.com + +- Fix the version in the package, it was set to 2.2.0, but the version + provided was 2.0.0. +- Disable broken tests with python 3.11, related to ordering of sets +- Remove six dependency +- Update to version 2.1.0: + * Bump version + * Seems like this is never used + * Better exception testing pattern, better test coverage :) + * Remove python <2.6 stuff; and an adhoc nose test runner + * Only round, not convert to hashable, when comparing dict values + * Coverage reporting + * PEP8 and other good practice fixes + * Add LICENSE file, build wheels + * Move tests into package subdir + * Add tox.ini and test against more versions of python + * fix __bool__ case when dict only has equal type diffs + * fuzzy matching for float comparisons, fix empty set diffs + * test_hashable_dict_values + * revert datadiff/tools.py hashable to maintain module_nose.tools compatibility + * use hashable when comparing + ------------------------------------------------------------------- Thu Sep 16 05:42:47 UTC 2021 - Steve Kowalik diff --git a/python-datadiff.spec b/python-datadiff.spec index dfea85c..4d5d710 100644 --- a/python-datadiff.spec +++ b/python-datadiff.spec @@ -1,7 +1,7 @@ # # spec file for package python-datadiff # -# Copyright (c) 2021 SUSE LLC +# Copyright (c) 2023 SUSE LLC # Copyright (c) 2019, Martin Hauke # # All modifications and additions to the file contributed by third parties @@ -17,9 +17,8 @@ # -%{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-datadiff -Version: 2.2.0 +Version: 2.1.0 Release: 0 Summary: DataDiff is a library to provide human-readable diffs of python data structures License: Apache-2.0 @@ -35,8 +34,8 @@ BuildRequires: python-rpm-macros BuildArch: noarch # SECTION test requirements BuildRequires: %{python_module pytest} -BuildRequires: %{python_module six} # /SECTION + %python_subpackages %description @@ -48,8 +47,7 @@ Drop-in replacements for some nose assertions are available. If the assertion f a nice data diff is shown, letting you easily pinpoint the root difference. %prep -%setup -q -n datadiff-%{version} -%autopatch -p1 +%autosetup -p1 -n datadiff-%{version} cp %{SOURCE1} . %build @@ -60,10 +58,12 @@ cp %{SOURCE1} . %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -%pytest +# Broken tests with py311 +%pytest -k "not (test_diff_set or test_diff_frozenset)" %files %{python_files} %license LICENSE-2.0.txt -%{python_sitelib}/* +%{python_sitelib}/datadiff +%{python_sitelib}/datadiff-%{version}*-info %changelog diff --git a/switch-to-pytest.patch b/switch-to-pytest.patch index 4b7655d..0a2578e 100644 --- a/switch-to-pytest.patch +++ b/switch-to-pytest.patch @@ -1,214 +1,247 @@ -Index: datadiff-2.2.0/test_datadiff.py +Index: datadiff-2.2.0/datadiff/tests/test_datadiff.py =================================================================== ---- datadiff-2.2.0.orig/test_datadiff.py -+++ datadiff-2.2.0/test_datadiff.py -@@ -5,7 +5,7 @@ from datetime import datetime - import sys +--- datadiff-2.2.0.orig/datadiff/tests/test_datadiff.py ++++ datadiff-2.2.0/datadiff/tests/test_datadiff.py +@@ -4,8 +4,7 @@ from textwrap import dedent + from datetime import datetime + from unittest.case import SkipTest - import six --from nose.tools import assert_raises, assert_equal, raises +-import six +-from nose.tools import assert_raises, assert_equal, assert_false, raises +from pytest import raises from datadiff import diff, DataDiff, NotHashable, DiffNotImplementedForType, DiffTypeError -@@ -28,9 +28,8 @@ def test_diff_objects(): +@@ -19,16 +18,17 @@ class Foo(object): + + + def test_diff_objects(): +- with assert_raises(DiffNotImplementedForType) as raised: ++ with raises(DiffNotImplementedForType) as raised: diff(Foo(), Foo(), fromfile="x", tofile="y") - except Exception: - e = sys.exc_info()[1] -- assert_equal(type(e), DiffNotImplementedForType, -- "Raised exception should be DiffNotImplementedForType") -- assert_equal(e.attempted_type, Foo) -+ assert type(e) is DiffNotImplementedForType -+ assert e.attempted_type is Foo - else: - raise AssertionError("Should've raised a DiffNotImplementedForType") +- assert_equal(raised.exception.attempted_type, Foo) +- assert_equal(str(raised.exception), "diff() not implemented for ") ++ assert raised.value.attempted_type is Foo ++ assert type(raised.value) is DiffNotImplementedForType -@@ -39,9 +38,8 @@ def test_diff_oneline_strings(): + + def test_diff_oneline_strings(): +- with assert_raises(DiffNotImplementedForType) as raised: ++ with raises(DiffNotImplementedForType) as raised: diff('foobar', 'baz', fromfile="x", tofile="y") - except Exception: - e = sys.exc_info()[1] -- assert_equal(type(e), DiffNotImplementedForType, -- "Raised exception should be DiffNotImplementedForType") -- assert_equal(e.attempted_type, str) -+ assert type(e) is DiffNotImplementedForType -+ assert e.attempted_type is str - else: - raise AssertionError("Should've raised a DiffNotImplementedForType") +- assert_equal(raised.exception.attempted_type, str) ++ assert type(raised.value) is DiffNotImplementedForType ++ assert raised.value.attempted_type is str -@@ -56,7 +54,7 @@ def test_diff_multiline_strings(): + + def test_diff_multiline_strings(): +@@ -40,12 +40,11 @@ def test_diff_multiline_strings(): abc -def ghi''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_unicode_vs_str(): - if six.PY3: -@@ -71,7 +69,7 @@ def test_diff_unicode_vs_str(): +- if six.PY3: +- raise SkipTest("Unicode and bytes are different types") ++ raise SkipTest("Unicode and bytes are different types") + d = diff(u'abc\ndef\nghi', b'abc\nghi', fromfile="x", tofile="y") + expected = dedent('''\ + --- x +@@ -54,7 +53,7 @@ def test_diff_unicode_vs_str(): abc -def ghi''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_list(): - a = [1,'xyz', 2, 3, 4, 5] -@@ -91,7 +89,7 @@ def test_diff_list(): +@@ -75,7 +74,7 @@ def test_diff_list(): -5, +6, ]''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_list_context(): - a = [1]*50 + [2, 3, 4, 5, 6, 7, 8] + [1]*10 -@@ -119,7 +117,7 @@ def test_diff_list_context(): +@@ -104,7 +103,7 @@ def test_diff_list_context(): 1, @@ @@ ]''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_list_2nd_longer(): - a = [3] -@@ -134,7 +132,7 @@ def test_diff_list_2nd_longer(): +@@ -120,7 +119,7 @@ def test_diff_list_2nd_longer(): +4, +5, ]''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_list_list(): - a = [1, [2, 3], 4] -@@ -149,7 +147,7 @@ def test_diff_list_list(): +@@ -136,7 +135,7 @@ def test_diff_list_list(): -[2, 3], 4, ]''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_list_dict(): - a = [1, {'a': 'b'}, 4] -@@ -164,7 +162,7 @@ def test_diff_list_dict(): +@@ -152,7 +151,7 @@ def test_diff_list_dict(): -{'a': 'b'}, 4, ]''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_list_set(): - a = [1, set([8, 9]), 4] -@@ -179,7 +177,7 @@ def test_diff_list_set(): +@@ -168,7 +167,7 @@ def test_diff_list_set(): -%s8, 9%s, 4, ]''') % (set_start, set_end) - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_seq_objects(): - class FooSeq(object): -@@ -201,7 +199,7 @@ def test_diff_seq_objects(): +@@ -194,7 +193,7 @@ def test_diff_seq_objects(): 1, +2, ])''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_almost_seq_objects(): - class FooSeq(object): -@@ -210,7 +208,7 @@ def test_diff_almost_seq_objects(): +@@ -205,7 +204,7 @@ def test_diff_almost_seq_objects(): def __iter__(self): return iter(self.list) -- assert_raises(DiffTypeError, diff, FooSeq([1]), FooSeq([1,2])) -+ raises(DiffTypeError, diff, FooSeq([1]), FooSeq([1,2])) +- assert_raises(DiffTypeError, diff, FooSeq([1]), FooSeq([1, 2])) ++ raises(DiffTypeError, diff, FooSeq([1]), FooSeq([1, 2])) + def test_tuple(): - d = diff((1,2), (1,3), fromfile="x", tofile="y") -@@ -223,7 +221,7 @@ def test_tuple(): +@@ -219,7 +218,7 @@ def test_tuple(): -2, +3, )''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_dict(): - a = dict(zero=0, one=1, two=2, three=3, nine=9, ten=10) -@@ -251,7 +249,7 @@ def test_diff_dict(): +@@ -248,7 +247,7 @@ def test_diff_dict(): assert "-'zero': 0," in diff_str assert "+'zero': '@'," in diff_str - context_pattern = "^ '\w+': \d+,$" + context_pattern = r"^ '\w+': \d+,$" - assert_equal(_count_lines(context_pattern, diff_str), 3) + assert _count_lines(context_pattern, diff_str) == 3 - def _count_lines(pattern, str): - """ -@@ -274,7 +272,7 @@ def test_diff_dict_keytypes(): + + def _count_lines(pattern, string): +@@ -273,7 +272,7 @@ def test_diff_dict_keytypes(): +2: 2, +datetime.datetime(2010, 10, 28, 0, 0): 1, }''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_dict_complex(): - a = dict(a=1, b=dict(foo='bar')) -@@ -287,7 +285,7 @@ def test_diff_dict_complex(): +@@ -287,7 +286,7 @@ def test_diff_dict_complex(): 'a': 1, -'b': {'foo': 'bar'}, }''') - assert_equal(str(d), expected) + assert str(d) == expected + + def test_diff_dict_similar_nested(): +@@ -301,7 +300,7 @@ def test_diff_dict_similar_nested(): + -'a': [1, 2], + +'a': (1, 2), + }''') +- assert_equal(str(d), expected) ++ assert str(d) == expected + + def test_diff_set(set_type=set): - a = set_type([1, 3, 5, 7, 'abc', 'def']) -@@ -305,7 +303,7 @@ def test_diff_set(set_type=set): +@@ -320,7 +319,7 @@ def test_diff_set(set_type=set): 'abc', 7, ])''') % set_type.__name__ - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_set_context(): - a = set([1, 2, 3, 4, 5, 6, 7, 8, 9]) -@@ -321,42 +319,42 @@ def test_diff_set_context(): +@@ -337,7 +336,7 @@ def test_diff_set_context(): 3, @@ @@ ])''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_diff_frozenset(): - return test_diff_set(set_type=frozenset) +@@ -345,52 +344,50 @@ def test_diff_frozenset(): + + + def test_equal_set(): +- assert_false(diff(set([1]), set([1]))) ++ assert not diff(set([1]), set([1])) + + + def test_empty_set(): +- assert_false(diff(set([]), set([]))) ++ assert not diff(set([]), set([])) + def test_eval_bool(): d = diff([1], [1], fromfile="x", tofile="y") - assert_equal(bool(d), False) -+ assert bool(d) is False ++ assert bool(d) == False d = diff([1], [2], fromfile="x", tofile="y") - assert_equal(bool(d), True) -+ assert bool(d) is True ++ assert bool(d) == True d = diff(dict(a=1), dict(a=1), fromfile="x", tofile="y") - assert_equal(bool(d), False) -+ assert bool(d) is False ++ assert bool(d) == False + + d = diff(dict(a=1, b=2, c=3, d=4), dict(a=1, b=2, c=3, d=4), fromfile="x", tofile="y") +- assert_equal(bool(d), False) ++ assert bool(d) == False + def test_equal(): d = diff([1], [1], fromfile="x", tofile="y") - assert_equal(str(d), '') + assert str(d) == '' + -@raises(DiffTypeError) def test_diff_types(): -- d = diff([1], {1:1}, fromfile="x", tofile="y") -+ with raises(DiffTypeError): -+ d = diff([1], {1:1}, fromfile="x", tofile="y") +- d = diff([1], {1: 1}, fromfile="x", tofile="y") ++ raises(DiffTypeError, diff, [1], {1: 1}, fromfile="x", tofile="y") + -@raises(Exception) def test_DataDiff_init_params(): - DataDiff(list, '[') -+ with raises(Exception): -+ DataDiff(list, '[') ++ raises(Exception, DataDiff, list, '[') + def test_DataDiff_change_type(): dd = DataDiff(list, '[', ']') @@ -216,140 +249,142 @@ Index: datadiff-2.2.0/test_datadiff.py - assert_raises(Exception, str, dd) + raises(Exception, str, dd) + def test_unhashable_type(): a = [] b = [slice(1)] - assert_raises(NotHashable, diff, a, b) + raises(NotHashable, diff, a, b) + def test_recursive_list(): - a = [1, [7, 8, 9, 10, 11], 3] -@@ -378,7 +376,7 @@ def test_recursive_list(): +@@ -413,7 +410,7 @@ def test_recursive_list(): ], 3, ]''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_recursive_tuple_different_types(): - a = (1, (7, 8, 9, 10, 11), 3) -@@ -401,7 +399,7 @@ def test_recursive_tuple_different_types +@@ -437,7 +434,7 @@ def test_recursive_tuple_different_types ), 3, )''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_recursive_dict(): - a = dict(a=1, b=dict(foo=17, bar=19), c=3) -@@ -418,7 +416,7 @@ def test_recursive_dict(): +@@ -455,7 +452,7 @@ def test_recursive_dict(): }, 'c': 3, }''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_recursive_set(): - a = set([1, 2, frozenset([3, 4, 5]), 8]) -@@ -435,7 +433,7 @@ def test_recursive_set(): +@@ -473,7 +470,7 @@ def test_recursive_set(): 2, ])''' % (frozenset_start, frozenset_end, frozenset_start, frozenset_end)) - assert_equal(str(d), expected) + assert str(d) == expected + def test_nested_unhashable(): - # dict is unhashable, and nested in a list -@@ -457,7 +455,7 @@ def test_nested_unhashable(): +@@ -496,7 +493,7 @@ def test_nested_unhashable(): }, ), ]''') - assert_equal(str(d), expected) + assert str(d) == expected + def test_nested_unhashable2(): - # dict is unhashable, and nested in another dict -@@ -477,4 +475,4 @@ def test_nested_unhashable2(): +@@ -517,4 +514,4 @@ def test_nested_unhashable2(): }, }, ]''') - assert_equal(str(d), expected) + assert str(d) == expected -Index: datadiff-2.2.0/test_datadiff_tools.py +Index: datadiff-2.2.0/datadiff/tests/test_datadiff_tools.py =================================================================== ---- datadiff-2.2.0.orig/test_datadiff_tools.py -+++ datadiff-2.2.0/test_datadiff_tools.py -@@ -3,20 +3,18 @@ from textwrap import dedent +--- datadiff-2.2.0.orig/datadiff/tests/test_datadiff_tools.py ++++ datadiff-2.2.0/datadiff/tests/test_datadiff_tools.py +@@ -2,20 +2,19 @@ import sys + from textwrap import dedent from datadiff import tools +-from datadiff.tests.test_datadiff import assert_equal + +-from nose.tools import assert_raises ++from pytest import raises --from test_datadiff import assert_equal -- def test_assert_equal_true(): # nothing raised - assert_equal(None, tools.assert_equals(7, 7)) + assert tools.assert_equals(7, 7) is None - + + def test_assert_equal_false(): - try: - tools.assert_equals([3,4], [5,6]) - except: - e = sys.exc_info()[1] -- assert_equal(type(e), AssertionError) -- assert_equal(str(e), dedent('''\ -+ assert type(e) is AssertionError -+ assert str(e) == dedent('''\ - - --- a - +++ b -@@ -26,7 +24,7 @@ def test_assert_equal_false(): - -4, - +5, - +6, -- ]''')) -+ ]''') - else: - raise AssertionError("Should've raised an AssertionError") - -@@ -35,23 +33,21 @@ def test_assert_equal_msg(): +- with assert_raises(AssertionError) as raised: ++ with raises(AssertionError) as raised: + tools.assert_equals([3, 4], [5, 6]) +- assert_equal(str(raised.exception), dedent('''\ ++ assert str(raised.value) == dedent('''\ + + --- a + +++ b +@@ -25,29 +24,29 @@ def test_assert_equal_false(): + -4, + +5, + +6, +- ]''')) ++ ]''') + + + def test_assert_equal_msg(): +- with assert_raises(AssertionError) as raised: ++ with raises(AssertionError) as raised: tools.assert_equals(3, 4, "whoops") - except: - e = sys.exc_info()[1] -- assert_equal(type(e), AssertionError, -- "Raised exception should be AssertionError") -- assert_equal(str(e), "whoops") -+ assert type(e) is AssertionError -+ assert str(e) == "whoops" - else: - raise AssertionError("Should've raised an AssertionError") - +- assert_equal(str(raised.exception), "whoops") ++ assert str(raised.value) == "whoops" + + def test_assert_equals(): - assert_equal(tools.assert_equal, tools.assert_equals) + assert tools.assert_equal == tools.assert_equals + def test_assert_equal_simple(): - try: +- with assert_raises(AssertionError) as raised: ++ with raises(AssertionError) as raised: tools.assert_equals(True, False) - except: - e = sys.exc_info()[1] -- assert_equal(type(e), AssertionError) -- assert_equal(str(e), dedent('''\ -- True != False''')) -+ assert type(e) is AssertionError -+ assert str(e) == 'True != False' - else: - raise AssertionError("Should've raised an AssertionError") +- assert_equal(str(raised.exception), 'True != False') ++ assert str(raised.value) == 'True != False' -@@ -60,9 +56,8 @@ def test_assert_equal_simple_types(): + + def test_assert_equal_simple_types(): +- with assert_raises(AssertionError) as raised: ++ with raises(AssertionError) as raised: tools.assert_equals('a', 7) - except: - e = sys.exc_info()[1] -- assert_equal(type(e), AssertionError) -- assert_equal(str(e), dedent('''\ -- 'a' != 7''')) -+ assert type(e) is AssertionError -+ assert str(e) == "'a' != 7" - else: - raise AssertionError("Should've raised an AssertionError") +- assert_equal(str(raised.exception), dedent("'a' != 7")) ++ assert str(raised.value) == dedent("'a' != 7") + + def test_assert_almost_equal(): +@@ -59,7 +58,7 @@ def test_assert_almost_equal(): + + + def test_assert_not_almost_equal(): +- assert_raises(AssertionError, tools.assertAlmostEqual, [1.0], [1.00001]) +- assert_raises(AssertionError, tools.assertAlmostEqual, [1.0], [1.0001], places=4) +- assert_raises(AssertionError, tools.assertAlmostEqual, {"k": 1.0}, {"k": 1.1}, places=4) +- assert_raises(AssertionError, tools.assertAlmostEqual, {1.0}, {1.1}, places=4) ++ raises(AssertionError, tools.assertAlmostEqual, [1.0], [1.00001]) ++ raises(AssertionError, tools.assertAlmostEqual, [1.0], [1.0001], places=4) ++ raises(AssertionError, tools.assertAlmostEqual, {"k": 1.0}, {"k": 1.1}, places=4) ++ raises(AssertionError, tools.assertAlmostEqual, {1.0}, {1.1}, places=4)