Skip to content

Commit

Permalink
add summary to pygeodiff api (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored Oct 16, 2019
1 parent 62ba0bd commit 9bfd2ee
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion geodiff/src/geodiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion pygeodiff/__about__.py
Original file line number Diff line number Diff line change
@@ -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__ = '[email protected]'
__maintainer__ = 'Peter Petrik'
Expand Down
11 changes: 11 additions & 0 deletions pygeodiff/geodifflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 18 additions & 0 deletions pygeodiff/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions pygeodiff/tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#from setuptools import setup
from skbuild import setup

VERSION = '0.5.0'
VERSION = '0.5.1'

setup(
name="pygeodiff",
Expand Down

0 comments on commit 9bfd2ee

Please sign in to comment.