From 282bebae977021b6f1d19fad0c967eb625af7331 Mon Sep 17 00:00:00 2001 From: selurvedu Date: Fri, 14 Aug 2015 15:45:03 +0000 Subject: Extend tests that check list patching --- tests.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'tests.py') diff --git a/tests.py b/tests.py index 5b0d9e9..bb9e296 100755 --- a/tests.py +++ b/tests.py @@ -327,13 +327,17 @@ class MakePatchTestCase(unittest.TestCase): self.assertEqual(res, dst) def test_use_move_instead_of_add_remove(self): - src = {'foo': [1, 2, 3]} - dst = {'foo': [3, 1, 2]} - patch = list(jsonpatch.make_patch(src, dst)) - self.assertEqual(len(patch), 1) - self.assertEqual(patch[0]['op'], 'move') - res = jsonpatch.apply_patch(src, patch) - self.assertEqual(res, dst) + def fn(_src, _dst): + patch = list(jsonpatch.make_patch(_src, _dst)) + self.assertEqual(len(patch), 1) + self.assertEqual(patch[0]['op'], 'move') + res = jsonpatch.apply_patch(_src, patch) + self.assertEqual(res, _dst) + + fn({'foo': [1, 2, 3]}, {'foo': [3, 1, 2]}) + fn({'foo': [1, 2, 3]}, {'foo': [3, 2, 1]}) + fn([1, 2, 3], [3, 1, 2]) + fn([1, 2, 3], [3, 2, 1]) def test_escape(self): src = {"x/y": 1} -- cgit v1.2.1 From c1067351a798534dda59aadccdfe5eb96fd520b4 Mon Sep 17 00:00:00 2001 From: selurvedu Date: Wed, 19 Aug 2015 17:00:16 +0000 Subject: Allow longer patches in test_use_move_... --- tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests.py') diff --git a/tests.py b/tests.py index bb9e296..c5134d3 100755 --- a/tests.py +++ b/tests.py @@ -329,8 +329,9 @@ class MakePatchTestCase(unittest.TestCase): def test_use_move_instead_of_add_remove(self): def fn(_src, _dst): patch = list(jsonpatch.make_patch(_src, _dst)) - self.assertEqual(len(patch), 1) - self.assertEqual(patch[0]['op'], 'move') + # Check if there are only 'move' operations + for p in patch: + self.assertEqual(p['op'], 'move') res = jsonpatch.apply_patch(_src, patch) self.assertEqual(res, _dst) -- cgit v1.2.1 From 6761340d8b4eae3419eebfb202c09f9956387148 Mon Sep 17 00:00:00 2001 From: Stas Erema Date: Tue, 18 Aug 2015 16:28:07 +0300 Subject: added error-prone cases to default tests --- tests.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests.py') diff --git a/tests.py b/tests.py index c5134d3..8da9cfc 100755 --- a/tests.py +++ b/tests.py @@ -356,6 +356,38 @@ class MakePatchTestCase(unittest.TestCase): res = patch.apply(src) self.assertEqual(res, dst) + def test_fail_prone_list_1(self): + """ Test making and applying a patch of the root is a list """ + src = [u'a', u'r', u'b'] + dst = [u'b', u'o'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + + def test_fail_prone_list_2(self): + """ Test making and applying a patch of the root is a list """ + src = [u'a', u'r', u'b', u'x', u'm', u'n'] + dst = [u'b', u'o', u'm', u'n'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + + def test_fail_prone_list_3(self): + """ Test making and applying a patch of the root is a list """ + src = [u'boo1', u'bar', u'foo1', u'qux'] + dst = [u'qux', u'bar'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + + def test_fail_prone_list_4(self): + """ Test making and applying a patch of the root is a list """ + src = [u'bar1', 59, u'foo1', u'foo'] + dst = [u'foo', u'bar', u'foo1'] + patch = jsonpatch.make_patch(src, dst) + res = patch.apply(src) + self.assertEqual(res, dst) + class InvalidInputTests(unittest.TestCase): -- cgit v1.2.1 From 0734d45eb651ed9dd1d37b6b80265fc3a6263607 Mon Sep 17 00:00:00 2001 From: selurvedu Date: Sun, 18 Oct 2015 21:17:38 +0000 Subject: Update tests from ea80865 to run on Python 3.2 --- tests.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests.py') diff --git a/tests.py b/tests.py index 8da9cfc..d2f9fe9 100755 --- a/tests.py +++ b/tests.py @@ -358,32 +358,32 @@ class MakePatchTestCase(unittest.TestCase): def test_fail_prone_list_1(self): """ Test making and applying a patch of the root is a list """ - src = [u'a', u'r', u'b'] - dst = [u'b', u'o'] + src = ['a', 'r', 'b'] + dst = ['b', 'o'] patch = jsonpatch.make_patch(src, dst) res = patch.apply(src) self.assertEqual(res, dst) def test_fail_prone_list_2(self): """ Test making and applying a patch of the root is a list """ - src = [u'a', u'r', u'b', u'x', u'm', u'n'] - dst = [u'b', u'o', u'm', u'n'] + src = ['a', 'r', 'b', 'x', 'm', 'n'] + dst = ['b', 'o', 'm', 'n'] patch = jsonpatch.make_patch(src, dst) res = patch.apply(src) self.assertEqual(res, dst) def test_fail_prone_list_3(self): """ Test making and applying a patch of the root is a list """ - src = [u'boo1', u'bar', u'foo1', u'qux'] - dst = [u'qux', u'bar'] + src = ['boo1', 'bar', 'foo1', 'qux'] + dst = ['qux', 'bar'] patch = jsonpatch.make_patch(src, dst) res = patch.apply(src) self.assertEqual(res, dst) def test_fail_prone_list_4(self): """ Test making and applying a patch of the root is a list """ - src = [u'bar1', 59, u'foo1', u'foo'] - dst = [u'foo', u'bar', u'foo1'] + src = ['bar1', 59, 'foo1', 'foo'] + dst = ['foo', 'bar', 'foo1'] patch = jsonpatch.make_patch(src, dst) res = patch.apply(src) self.assertEqual(res, dst) -- cgit v1.2.1 From 73acf7ff2a83c411217aff024d35cc8b602180ed Mon Sep 17 00:00:00 2001 From: selurvedu Date: Fri, 8 Apr 2016 04:24:29 +0000 Subject: Move list-related testcases into separate class --- tests.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests.py') diff --git a/tests.py b/tests.py index d2f9fe9..b03b64b 100755 --- a/tests.py +++ b/tests.py @@ -356,6 +356,9 @@ class MakePatchTestCase(unittest.TestCase): res = patch.apply(src) self.assertEqual(res, dst) + +class ListTests(unittest.TestCase): + def test_fail_prone_list_1(self): """ Test making and applying a patch of the root is a list """ src = ['a', 'r', 'b'] @@ -453,6 +456,7 @@ def get_suite(): suite.addTest(unittest.makeSuite(ApplyPatchTestCase)) suite.addTest(unittest.makeSuite(EqualityTestCase)) suite.addTest(unittest.makeSuite(MakePatchTestCase)) + suite.addTest(unittest.makeSuite(ListTests)) suite.addTest(unittest.makeSuite(InvalidInputTests)) suite.addTest(unittest.makeSuite(ConflictTests)) return suite -- cgit v1.2.1