From 9bfd2ee4a074aeec251bb00c2cd9bfa49bae6399 Mon Sep 17 00:00:00 2001 From: Peter Petrik Date: Wed, 16 Oct 2019 09:27:51 +0200 Subject: [PATCH] add summary to pygeodiff api (#19) --- geodiff/src/geodiff.cpp | 2 +- pygeodiff/__about__.py | 2 +- pygeodiff/geodifflib.py | 11 +++++++++++ pygeodiff/main.py | 18 ++++++++++++++++++ pygeodiff/tests/testutils.py | 13 ++++++++++--- setup.py | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/geodiff/src/geodiff.cpp b/geodiff/src/geodiff.cpp index f396a5ec..973864d6 100644 --- a/geodiff/src/geodiff.cpp +++ b/geodiff/src/geodiff.cpp @@ -23,7 +23,7 @@ const char *GEODIFF_version() { - return "0.5.0"; + return "0.5.1"; } void _errorLogCallback( void *pArg, int iErrCode, const char *zMsg ) diff --git a/pygeodiff/__about__.py b/pygeodiff/__about__.py index 39085e9b..a989002d 100644 --- a/pygeodiff/__about__.py +++ b/pygeodiff/__about__.py @@ -1,7 +1,7 @@ __title__ = 'PyGeoDiff' __description__ = 'Diff tool for geo-spatial data' __url__ = 'https://github.com/lutraconsulting/geodiff' -__version__ = '0.5.0' +__version__ = '0.5.1' __author__ = 'Peter Petrik' __author_email__ = 'zilolv@gmail.com' __maintainer__ = 'Peter Petrik' diff --git a/pygeodiff/geodifflib.py b/pygeodiff/geodifflib.py index 4048059f..60ba8309 100644 --- a/pygeodiff/geodifflib.py +++ b/pygeodiff/geodifflib.py @@ -137,6 +137,17 @@ def list_changes(self, changeset, result): res = func(b_string1, b_string2) _parse_return_code(res, "list_changes") + def list_changes_summary(self, changeset, result): + func = self.lib.GEODIFF_listChangesSummary + func.argtypes = [ctypes.c_char_p] + func.restype = ctypes.c_int + + # create byte objects from the strings + b_string1 = changeset.encode('utf-8') + b_string2 = result.encode('utf-8') + res = func(b_string1, b_string2) + _parse_return_code(res, "list_changes_summary") + def has_changes(self, changeset): func = self.lib.GEODIFF_hasChanges func.argtypes = [ctypes.c_char_p] diff --git a/pygeodiff/main.py b/pygeodiff/main.py index ab6d941f..44016aa6 100644 --- a/pygeodiff/main.py +++ b/pygeodiff/main.py @@ -68,6 +68,7 @@ def apply_changeset(self, base, patched, changeset): """ Lists changeset content JSON file + JSON contains all changes in human/machine readable name \returns number of changes raises SqliteDiffError on error @@ -81,6 +82,23 @@ def list_changes(self, changeset, json): raises SqliteDiffError on error """ + """ + Lists changeset summary content JSON file + JSON contains a list of how many inserts/edits/deletes is contained in changeset for each table + \returns number of changes + + raises SqliteDiffError on error + """ + + def list_changes_summary(self, changeset, json): + return self.clib.list_changes_summary(changeset, json) + + """ + \returns whether changeset contains at least one change + + raises SqliteDiffError on error + """ + def has_changes(self, changeset): return self.clib.has_changes(changeset) diff --git a/pygeodiff/tests/testutils.py b/pygeodiff/tests/testutils.py index 3ee48f56..6a95caa8 100644 --- a/pygeodiff/tests/testutils.py +++ b/pygeodiff/tests/testutils.py @@ -47,10 +47,9 @@ def is_valid_json(stream): raise TestError("JSON:\n " + stream + "\n is not valid :\n" + str(e)) -def test_json(geodiff, changeset, json, expect_success ): - print("check export to JSON ") +def _test_json(function, changeset, json, expect_success ): try: - geodiff.list_changes(changeset, json) + function(changeset, json) if not expect_success: raise TestError("json generation succeeded, but should have failed") except: @@ -66,6 +65,14 @@ def test_json(geodiff, changeset, json, expect_success ): is_valid_json(data) +def test_json(geodiff, changeset, json, expect_success ): + print("check export to JSON summary") + _test_json(geodiff.list_changes_summary, changeset, json, expect_success) + + print("check export to JSON ") + _test_json(geodiff.list_changes, changeset, json, expect_success) + + def compare_json(json, expected_json): print ("comparing JSON to " + expected_json) if not os.path.exists(json): diff --git a/setup.py b/setup.py index e788e22b..9667835c 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ #from setuptools import setup from skbuild import setup -VERSION = '0.5.0' +VERSION = '0.5.1' setup( name="pygeodiff",