forked from pool/python-jsondiff
- Convert to libalternatives on SLE-16-based and newer systems only
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-jsondiff?expand=0&rev=30
This commit is contained in:
23
.gitattributes
vendored
Normal file
23
.gitattributes
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
## Default LFS
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.bsp filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.gem filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.jar filter=lfs diff=lfs merge=lfs -text
|
||||
*.lz filter=lfs diff=lfs merge=lfs -text
|
||||
*.lzma filter=lfs diff=lfs merge=lfs -text
|
||||
*.obscpio filter=lfs diff=lfs merge=lfs -text
|
||||
*.oxt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pdf filter=lfs diff=lfs merge=lfs -text
|
||||
*.png filter=lfs diff=lfs merge=lfs -text
|
||||
*.rpm filter=lfs diff=lfs merge=lfs -text
|
||||
*.tbz filter=lfs diff=lfs merge=lfs -text
|
||||
*.tbz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.ttf filter=lfs diff=lfs merge=lfs -text
|
||||
*.txz filter=lfs diff=lfs merge=lfs -text
|
||||
*.whl filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.osc
|
||||
3
jsondiff-2.0.0.tar.gz
Normal file
3
jsondiff-2.0.0.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:5cf3dfb212dcdc6ee104f40e30824a2f3ddaa05938d111ce0eea6646518b8339
|
||||
size 15405
|
||||
3
jsondiff-2.2.0.tar.gz
Normal file
3
jsondiff-2.2.0.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:060e9a10fe136c643e9d2bf264ea1fbe966ed17d2fd37348dd65b1c650c2df4f
|
||||
size 26597
|
||||
BIN
jsondiff-2.2.1.tar.gz
(Stored with Git LFS)
Normal file
BIN
jsondiff-2.2.1.tar.gz
(Stored with Git LFS)
Normal file
Binary file not shown.
126
python-jsondiff.changes
Normal file
126
python-jsondiff.changes
Normal file
@@ -0,0 +1,126 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu Aug 21 09:14:03 UTC 2025 - Markéta Machová <mmachova@suse.com>
|
||||
|
||||
- Convert to libalternatives on SLE-16-based and newer systems only
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Jul 10 14:29:55 UTC 2025 - Markéta Machová <mmachova@suse.com>
|
||||
|
||||
- Convert to libalternatives
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Oct 10 14:30:38 UTC 2024 - John Paul Adrian Glaubitz <adrian.glaubitz@suse.com>
|
||||
|
||||
- Update to 2.2.1
|
||||
* Protect Symbol.eq by instance check
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Aug 13 03:18:20 UTC 2024 - Steve Kowalik <steven.kowalik@suse.com>
|
||||
|
||||
- Update to 2.2.0:
|
||||
* Exclude a list of paths from diff.
|
||||
* really drop python<=3.7 support
|
||||
* remove last bits of python2 support
|
||||
* Fix pypi release readme formatting
|
||||
* Minimal conversion to pytest+hypothesis
|
||||
* Added simple equality operator for class Symbol
|
||||
* jsondiff: fix symbol equality
|
||||
* setup.py: migrate to pyproject.toml
|
||||
* fix: better diffing of empty containers
|
||||
* add rightonly jsondiff syntax
|
||||
* Introduce YAML support
|
||||
* packaging: revert to requirements files
|
||||
- Switch back to PyPi tarball. (required for setuptools_scm)
|
||||
- Drop patch remove_nose.patch, no longer required.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Mar 26 12:08:46 UTC 2024 - John Paul Adrian Glaubitz <adrian.glaubitz@suse.com>
|
||||
|
||||
- Switch build system from setuptools to pyproject.toml
|
||||
+ Add python-pip and python-wheel to BuildRequires
|
||||
+ Replace %python_build with %pyproject_wheel
|
||||
+ Replace %python_install with %pyproject_install
|
||||
- Limit Python files matched in %files section
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Jun 13 12:15:54 UTC 2023 - ecsos <ecsos@opensuse.org>
|
||||
|
||||
- Add %{?sle15_python_module_pythons}
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue May 24 13:11:04 UTC 2022 - John Paul Adrian Glaubitz <adrian.glaubitz@suse.com>
|
||||
|
||||
- Update to version 2.0.0
|
||||
* Removed deprecated function
|
||||
* Remove deprecated jsondiff entry point
|
||||
- from version 1.3.1
|
||||
* Optionally allow different escape_str than '$'
|
||||
* Clarified the readme, closes #23
|
||||
* Fixed readme
|
||||
- Remove jsondiff command from %install, %post, %postun and %files sections
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Dec 7 09:32:07 UTC 2021 - John Paul Adrian Glaubitz <adrian.glaubitz@suse.com>
|
||||
|
||||
- Update to version 1.3.0
|
||||
* Update README.rst
|
||||
* Add license to setup.py
|
||||
* Upating travis config to explicitly set ubuntu versions to use
|
||||
for each python version.
|
||||
* Fix long list diffing bug by converting recursive code to iterative.
|
||||
* Add failing test for list-diff recursion error bug
|
||||
- Refresh patches for new version
|
||||
* remove_nose.patch
|
||||
- Switch Source field to point to Github tarball URL
|
||||
* The tarball from PyPi does not contain the tests
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Sun Sep 13 17:39:27 UTC 2020 - Matej Cepl <mcepl@suse.com>
|
||||
|
||||
- Add remove_nose.patch to remove requirement for nose.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Mon May 25 10:59:35 UTC 2020 - Petr Gajdos <pgajdos@suse.com>
|
||||
|
||||
- %python3_only -> %python_alternative
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Oct 4 15:22:38 UTC 2019 - Marketa Calabkova <mcalabkova@suse.com>
|
||||
|
||||
- Update to version 1.2.0
|
||||
* Deprecate the jsondiff command due to conflicts with json-patch
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Sun Jun 2 20:34:43 UTC 2019 - Jan Engelhardt <jengelh@inai.de>
|
||||
|
||||
- Use noun phrase in summary.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri May 17 21:48:19 UTC 2019 - Scott Wulf <swulf@suse.com>
|
||||
|
||||
- Removing conflict with jsonpatch
|
||||
* Reasoning:
|
||||
- moto requires cfn-lint and jsondiff
|
||||
- cfn-lint requires jsonpatch
|
||||
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue May 14 22:18:30 UTC 2019 - Gary Smith <GSmith@suse.com>
|
||||
|
||||
- Upgraded to 1.1.2
|
||||
* no changelog available
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Mon May 14 11:25:31 UTC 2018 - tchvatal@suse.com
|
||||
|
||||
- Conflict with python-jsonpatch
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed May 9 01:00:26 UTC 2018 - toddrme2178@gmail.com
|
||||
|
||||
- Fix typo to allow building
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue May 8 18:43:02 UTC 2018 - tchvatal@suse.com
|
||||
|
||||
- Initial commit, required by python-moto
|
||||
85
python-jsondiff.spec
Normal file
85
python-jsondiff.spec
Normal file
@@ -0,0 +1,85 @@
|
||||
#
|
||||
# spec file for package python-jsondiff
|
||||
#
|
||||
# Copyright (c) 2025 SUSE LLC
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
# upon. The license for this file, and modifications and additions to the
|
||||
# file, is the same license as for the pristine package itself (unless the
|
||||
# license for the pristine package is not an Open Source License, in which
|
||||
# case the license is the MIT License). An "Open Source License" is a
|
||||
# license that conforms to the Open Source Definition (Version 1.9)
|
||||
# published by the Open Source Initiative.
|
||||
|
||||
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
||||
#
|
||||
|
||||
|
||||
%if 0%{?suse_version} > 1500
|
||||
%bcond_without libalternatives
|
||||
%else
|
||||
%bcond_with libalternatives
|
||||
%endif
|
||||
%{?sle15_python_module_pythons}
|
||||
Name: python-jsondiff
|
||||
Version: 2.2.1
|
||||
Release: 0
|
||||
Summary: Module to diff JSON and JSON-like structures in Python
|
||||
License: MIT
|
||||
URL: https://github.com/ZoomerAnalytics/jsondiff
|
||||
Source: https://files.pythonhosted.org/packages/source/j/jsondiff/jsondiff-%{version}.tar.gz
|
||||
BuildRequires: %{python_module PyYAML}
|
||||
BuildRequires: %{python_module base >= 3.8}
|
||||
BuildRequires: %{python_module hypothesis}
|
||||
BuildRequires: %{python_module pip}
|
||||
BuildRequires: %{python_module pytest}
|
||||
BuildRequires: %{python_module setuptools_scm}
|
||||
BuildRequires: %{python_module wheel}
|
||||
BuildRequires: fdupes
|
||||
BuildRequires: python-rpm-macros
|
||||
Requires: python-PyYAML
|
||||
BuildArch: noarch
|
||||
%if %{with libalternatives}
|
||||
BuildRequires: alts
|
||||
Requires: alts
|
||||
%else
|
||||
Requires(post): update-alternatives
|
||||
Requires(postun): update-alternatives
|
||||
%endif
|
||||
%python_subpackages
|
||||
|
||||
%description
|
||||
Package to show differences between JSON and JSON-like structures in Python
|
||||
|
||||
%prep
|
||||
%autosetup -p1 -n jsondiff-%{version}
|
||||
|
||||
%build
|
||||
%pyproject_wheel
|
||||
|
||||
%install
|
||||
%pyproject_install
|
||||
%python_clone -a %{buildroot}%{_bindir}/jdiff
|
||||
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
||||
|
||||
%check
|
||||
%pytest
|
||||
|
||||
%post
|
||||
%python_install_alternative jdiff
|
||||
|
||||
%postun
|
||||
%python_uninstall_alternative jdiff
|
||||
|
||||
%pre
|
||||
%python_libalternatives_reset_alternative jdiff
|
||||
|
||||
%files %{python_files}
|
||||
%license LICENSE
|
||||
%doc README.md
|
||||
%{python_sitelib}/jsondiff
|
||||
%{python_sitelib}/jsondiff-%{version}.dist-info
|
||||
%python_alternative %{_bindir}/jdiff
|
||||
|
||||
%changelog
|
||||
300
remove_nose.patch
Normal file
300
remove_nose.patch
Normal file
@@ -0,0 +1,300 @@
|
||||
diff -Nru jsondiff-1.3.0.orig/tests/__init__.py jsondiff-1.3.0/tests/__init__.py
|
||||
--- jsondiff-1.3.0.orig/tests/__init__.py 2021-04-19 21:51:14.000000000 +0200
|
||||
+++ jsondiff-1.3.0/tests/__init__.py 2021-12-07 10:25:30.252455974 +0100
|
||||
@@ -1,130 +1,15 @@
|
||||
import sys
|
||||
-import unittest
|
||||
|
||||
-from jsondiff import diff, replace, add, discard, insert, delete, update, JsonDiffer
|
||||
-
|
||||
-from .utils import generate_random_json, perturbate_json
|
||||
-
|
||||
-from nose_random import randomize
|
||||
-
|
||||
-
|
||||
-class JsonDiffTests(unittest.TestCase):
|
||||
-
|
||||
- def test_a(self):
|
||||
-
|
||||
- self.assertEqual({}, diff(1, 1))
|
||||
- self.assertEqual({}, diff(True, True))
|
||||
- self.assertEqual({}, diff('abc', 'abc'))
|
||||
- self.assertEqual({}, diff([1, 2], [1, 2]))
|
||||
- self.assertEqual({}, diff((1, 2), (1, 2)))
|
||||
- self.assertEqual({}, diff({1, 2}, {1, 2}))
|
||||
- self.assertEqual({}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 2}))
|
||||
- self.assertEqual({}, diff([], []))
|
||||
- self.assertEqual({}, diff(None, None))
|
||||
- self.assertEqual({}, diff({}, {}))
|
||||
- self.assertEqual({}, diff(set(), set()))
|
||||
-
|
||||
- self.assertEqual(2, diff(1, 2))
|
||||
- self.assertEqual(False, diff(True, False))
|
||||
- self.assertEqual('def', diff('abc', 'def'))
|
||||
- self.assertEqual([3, 4], diff([1, 2], [3, 4]))
|
||||
- self.assertEqual((3, 4), diff((1, 2), (3, 4)))
|
||||
- self.assertEqual({3, 4}, diff({1, 2}, {3, 4}))
|
||||
- self.assertEqual({replace: {'c': 3, 'd': 4}}, diff({'a': 1, 'b': 2}, {'c': 3, 'd': 4}))
|
||||
-
|
||||
- self.assertEqual({replace: {'c': 3, 'd': 4}}, diff([1, 2], {'c': 3, 'd': 4}))
|
||||
- self.assertEqual(123, diff({'a': 1, 'b': 2}, 123))
|
||||
-
|
||||
- self.assertEqual({delete: ['b']}, diff({'a': 1, 'b': 2}, {'a': 1}))
|
||||
- self.assertEqual({'b': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 3}))
|
||||
- self.assertEqual({'c': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 2, 'c': 3}))
|
||||
- self.assertEqual({delete: ['b'], 'c': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'c': 3}))
|
||||
-
|
||||
- self.assertEqual({add: {3}}, diff({1, 2}, {1, 2, 3}))
|
||||
- self.assertEqual({add: {3}, discard: {4}}, diff({1, 2, 4}, {1, 2, 3}))
|
||||
- self.assertEqual({discard: {4}}, diff({1, 2, 4}, {1, 2}))
|
||||
-
|
||||
- self.assertEqual({insert: [(1, 'b')]}, diff(['a', 'c'], ['a', 'b', 'c']))
|
||||
- self.assertEqual({insert: [(1, 'b')], delete: [3, 0]}, diff(['x', 'a', 'c', 'x'], ['a', 'b', 'c']))
|
||||
- self.assertEqual(
|
||||
- {insert: [(2, 'b')], delete: [4, 0], 1: {'v': 20}},
|
||||
- diff(['x', 'a', {'v': 11}, 'c', 'x'], ['a', {'v': 20}, 'b', 'c'])
|
||||
- )
|
||||
- self.assertEqual(
|
||||
- {insert: [(2, 'b')], delete: [4, 0], 1: {'v': 20}},
|
||||
- diff(['x', 'a', {'u': 10, 'v': 11}, 'c', 'x'], ['a', {'u': 10, 'v': 20}, 'b', 'c'])
|
||||
- )
|
||||
-
|
||||
- def test_marshal(self):
|
||||
- differ = JsonDiffer()
|
||||
-
|
||||
- d = {
|
||||
- delete: 3,
|
||||
- '$delete': 4,
|
||||
- insert: 4,
|
||||
- '$$something': 1
|
||||
- }
|
||||
-
|
||||
- dm = differ.marshal(d)
|
||||
-
|
||||
- self.assertEqual(d, differ.unmarshal(dm))
|
||||
-
|
||||
- def generate_scenario(self, rng):
|
||||
- a = generate_random_json(rng, sets=True)
|
||||
- b = perturbate_json(a, rng, sets=True)
|
||||
- return a, b
|
||||
-
|
||||
- def generate_scenario_no_sets(self, rng):
|
||||
- a = generate_random_json(rng, sets=False)
|
||||
- b = perturbate_json(a, rng, sets=False)
|
||||
- return a, b
|
||||
-
|
||||
- @randomize(1000, generate_scenario_no_sets)
|
||||
- def test_dump(self, scenario):
|
||||
- a, b = scenario
|
||||
- diff(a, b, syntax='compact', dump=True)
|
||||
- diff(a, b, syntax='explicit', dump=True)
|
||||
- diff(a, b, syntax='symmetric', dump=True)
|
||||
-
|
||||
- @randomize(1000, generate_scenario)
|
||||
- def test_compact_syntax(self, scenario):
|
||||
- a, b = scenario
|
||||
- differ = JsonDiffer(syntax='compact')
|
||||
- d = differ.diff(a, b)
|
||||
- self.assertEqual(b, differ.patch(a, d))
|
||||
- dm = differ.marshal(d)
|
||||
- self.assertEqual(d, differ.unmarshal(dm))
|
||||
-
|
||||
-
|
||||
- @randomize(1000, generate_scenario)
|
||||
- def test_explicit_syntax(self, scenario):
|
||||
- a, b = scenario
|
||||
- differ = JsonDiffer(syntax='explicit')
|
||||
- d = differ.diff(a, b)
|
||||
- # self.assertEqual(b, differ.patch(a, d))
|
||||
- dm = differ.marshal(d)
|
||||
- self.assertEqual(d, differ.unmarshal(dm))
|
||||
-
|
||||
- @randomize(1000, generate_scenario)
|
||||
- def test_symmetric_syntax(self, scenario):
|
||||
- a, b = scenario
|
||||
- differ = JsonDiffer(syntax='symmetric')
|
||||
- d = differ.diff(a, b)
|
||||
- self.assertEqual(b, differ.patch(a, d))
|
||||
- self.assertEqual(a, differ.unpatch(b, d))
|
||||
- dm = differ.marshal(d)
|
||||
- self.assertEqual(d, differ.unmarshal(dm))
|
||||
-
|
||||
- def test_long_arrays(self):
|
||||
- size = 100
|
||||
- a = [{'a': i, 'b': 2 * i} for i in range(1, size)]
|
||||
- b = [{'a': i, 'b': 3 * i} for i in range(1, size)]
|
||||
- r = sys.getrecursionlimit()
|
||||
- sys.setrecursionlimit(size - 1)
|
||||
-
|
||||
- try:
|
||||
- diff(a, b)
|
||||
- except RecursionError:
|
||||
- self.fail('cannot diff long arrays')
|
||||
- finally:
|
||||
- sys.setrecursionlimit(r)
|
||||
+def test_long_arrays(self):
|
||||
+ size = 100
|
||||
+ a = [{'a': i, 'b': 2 * i} for i in range(1, size)]
|
||||
+ b = [{'a': i, 'b': 3 * i} for i in range(1, size)]
|
||||
+ r = sys.getrecursionlimit()
|
||||
+ sys.setrecursionlimit(size - 1)
|
||||
+
|
||||
+ try:
|
||||
+ diff(a, b)
|
||||
+ except RecursionError:
|
||||
+ self.fail('cannot diff long arrays')
|
||||
+ finally:
|
||||
+ sys.setrecursionlimit(r)
|
||||
diff -Nru jsondiff-1.3.0.orig/tests/_random.py jsondiff-1.3.0/tests/_random.py
|
||||
--- jsondiff-1.3.0.orig/tests/_random.py 1970-01-01 01:00:00.000000000 +0100
|
||||
+++ jsondiff-1.3.0/tests/_random.py 2021-12-07 10:21:59.457195559 +0100
|
||||
@@ -0,0 +1,33 @@
|
||||
+import sys
|
||||
+from random import Random
|
||||
+
|
||||
+PY3 = (sys.version_info[0] == 3)
|
||||
+
|
||||
+
|
||||
+def _generate_tag(n, rng):
|
||||
+ return ''.join(rng.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
|
||||
+ for _ in range(n))
|
||||
+
|
||||
+
|
||||
+def randomize(n, scenario_generator, seed=12038728732):
|
||||
+ def decorator(test):
|
||||
+ def randomized_test(self):
|
||||
+ rng_seed = Random(seed)
|
||||
+ nseeds = n
|
||||
+ # (rng_seed.getrandbits(32) for i in range(n))
|
||||
+ seeds = (_generate_tag(12, rng_seed) for i in range(n))
|
||||
+ for i, rseed in enumerate(seeds):
|
||||
+ rng = Random(rseed)
|
||||
+ scenario = scenario_generator(self, rng)
|
||||
+ try:
|
||||
+ test(self, scenario)
|
||||
+ except Exception as e:
|
||||
+ import sys
|
||||
+ if PY3:
|
||||
+ raise type(e).with_traceback(type(e)('%s with scenario %s (%i of %i)' %
|
||||
+ (e.message, rseed, i+1, nseeds)), sys.exc_info()[2])
|
||||
+ else:
|
||||
+ raise (type(e), type(e)('%s with scenario %s (%i of %i)'
|
||||
+ % (e.message, rseed, i+1, nseeds)), sys.exc_info()[2])
|
||||
+ return randomized_test
|
||||
+ return decorator
|
||||
diff -Nru jsondiff-1.3.0.orig/tests/test_jsondiff.py jsondiff-1.3.0/tests/test_jsondiff.py
|
||||
--- jsondiff-1.3.0.orig/tests/test_jsondiff.py 1970-01-01 01:00:00.000000000 +0100
|
||||
+++ jsondiff-1.3.0/tests/test_jsondiff.py 2021-12-07 10:21:59.457195559 +0100
|
||||
@@ -0,0 +1,112 @@
|
||||
+import unittest
|
||||
+
|
||||
+from jsondiff import diff, replace, add, discard, insert, delete, update, JsonDiffer
|
||||
+from tests.utils import generate_random_json, perturbate_json
|
||||
+from tests._random import randomize
|
||||
+
|
||||
+
|
||||
+class JsonDiffTests(unittest.TestCase):
|
||||
+
|
||||
+ def test_a(self):
|
||||
+
|
||||
+ self.assertEqual({}, diff(1, 1))
|
||||
+ self.assertEqual({}, diff(True, True))
|
||||
+ self.assertEqual({}, diff('abc', 'abc'))
|
||||
+ self.assertEqual({}, diff([1, 2], [1, 2]))
|
||||
+ self.assertEqual({}, diff((1, 2), (1, 2)))
|
||||
+ self.assertEqual({}, diff({1, 2}, {1, 2}))
|
||||
+ self.assertEqual({}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 2}))
|
||||
+ self.assertEqual({}, diff([], []))
|
||||
+ self.assertEqual({}, diff(None, None))
|
||||
+ self.assertEqual({}, diff({}, {}))
|
||||
+ self.assertEqual({}, diff(set(), set()))
|
||||
+
|
||||
+ self.assertEqual(2, diff(1, 2))
|
||||
+ self.assertEqual(False, diff(True, False))
|
||||
+ self.assertEqual('def', diff('abc', 'def'))
|
||||
+ self.assertEqual([3, 4], diff([1, 2], [3, 4]))
|
||||
+ self.assertEqual((3, 4), diff((1, 2), (3, 4)))
|
||||
+ self.assertEqual({3, 4}, diff({1, 2}, {3, 4}))
|
||||
+ self.assertEqual({replace: {'c': 3, 'd': 4}}, diff({'a': 1, 'b': 2}, {'c': 3, 'd': 4}))
|
||||
+
|
||||
+ self.assertEqual({replace: {'c': 3, 'd': 4}}, diff([1, 2], {'c': 3, 'd': 4}))
|
||||
+ self.assertEqual(123, diff({'a': 1, 'b': 2}, 123))
|
||||
+
|
||||
+ self.assertEqual({delete: ['b']}, diff({'a': 1, 'b': 2}, {'a': 1}))
|
||||
+ self.assertEqual({'b': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 3}))
|
||||
+ self.assertEqual({'c': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 2, 'c': 3}))
|
||||
+ self.assertEqual({delete: ['b'], 'c': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'c': 3}))
|
||||
+
|
||||
+ self.assertEqual({add: {3}}, diff({1, 2}, {1, 2, 3}))
|
||||
+ self.assertEqual({add: {3}, discard: {4}}, diff({1, 2, 4}, {1, 2, 3}))
|
||||
+ self.assertEqual({discard: {4}}, diff({1, 2, 4}, {1, 2}))
|
||||
+
|
||||
+ self.assertEqual({insert: [(1, 'b')]}, diff(['a', 'c'], ['a', 'b', 'c']))
|
||||
+ self.assertEqual({insert: [(1, 'b')], delete: [3, 0]}, diff(['x', 'a', 'c', 'x'], ['a', 'b', 'c']))
|
||||
+ self.assertEqual(
|
||||
+ {insert: [(2, 'b')], delete: [4, 0], 1: {'v': 20}},
|
||||
+ diff(['x', 'a', {'v': 11}, 'c', 'x'], ['a', {'v': 20}, 'b', 'c'])
|
||||
+ )
|
||||
+ self.assertEqual(
|
||||
+ {insert: [(2, 'b')], delete: [4, 0], 1: {'v': 20}},
|
||||
+ diff(['x', 'a', {'u': 10, 'v': 11}, 'c', 'x'], ['a', {'u': 10, 'v': 20}, 'b', 'c'])
|
||||
+ )
|
||||
+
|
||||
+ def test_marshal(self):
|
||||
+ differ = JsonDiffer()
|
||||
+
|
||||
+ d = {
|
||||
+ delete: 3,
|
||||
+ '$delete': 4,
|
||||
+ insert: 4,
|
||||
+ '$$something': 1
|
||||
+ }
|
||||
+
|
||||
+ dm = differ.marshal(d)
|
||||
+
|
||||
+ self.assertEqual(d, differ.unmarshal(dm))
|
||||
+
|
||||
+ def generate_scenario(self, rng):
|
||||
+ a = generate_random_json(rng, sets=True)
|
||||
+ b = perturbate_json(a, rng, sets=True)
|
||||
+ return a, b
|
||||
+
|
||||
+ def generate_scenario_no_sets(self, rng):
|
||||
+ a = generate_random_json(rng, sets=False)
|
||||
+ b = perturbate_json(a, rng, sets=False)
|
||||
+ return a, b
|
||||
+
|
||||
+ @randomize(1000, generate_scenario_no_sets)
|
||||
+ def test_dump(self, scenario):
|
||||
+ a, b = scenario
|
||||
+ diff(a, b, syntax='compact', dump=True)
|
||||
+ diff(a, b, syntax='explicit', dump=True)
|
||||
+ diff(a, b, syntax='symmetric', dump=True)
|
||||
+
|
||||
+ @randomize(1000, generate_scenario)
|
||||
+ def test_compact_syntax(self, scenario):
|
||||
+ a, b = scenario
|
||||
+ differ = JsonDiffer(syntax='compact')
|
||||
+ d = differ.diff(a, b)
|
||||
+ self.assertEqual(b, differ.patch(a, d))
|
||||
+ dm = differ.marshal(d)
|
||||
+ self.assertEqual(d, differ.unmarshal(dm))
|
||||
+
|
||||
+ @randomize(1000, generate_scenario)
|
||||
+ def test_explicit_syntax(self, scenario):
|
||||
+ a, b = scenario
|
||||
+ differ = JsonDiffer(syntax='explicit')
|
||||
+ d = differ.diff(a, b)
|
||||
+ # self.assertEqual(b, differ.patch(a, d))
|
||||
+ dm = differ.marshal(d)
|
||||
+ self.assertEqual(d, differ.unmarshal(dm))
|
||||
+
|
||||
+ @randomize(1000, generate_scenario)
|
||||
+ def test_symmetric_syntax(self, scenario):
|
||||
+ a, b = scenario
|
||||
+ differ = JsonDiffer(syntax='symmetric')
|
||||
+ d = differ.diff(a, b)
|
||||
+ self.assertEqual(b, differ.patch(a, d))
|
||||
+ self.assertEqual(a, differ.unpatch(b, d))
|
||||
+ dm = differ.marshal(d)
|
||||
+ self.assertEqual(d, differ.unmarshal(dm))
|
||||
Reference in New Issue
Block a user