Skip to content

Commit a989432

Browse files
committed
properly handle the error and its passsing to pygeodiff
1 parent 89a5b01 commit a989432

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

geodiff/src/geodiff.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,14 @@ int GEODIFF_CX_setTablesToSkip( GEODIFF_ContextH contextHandle, int tablesCount,
158158
tables.push_back( tableName );
159159
}
160160

161-
context->setTablesToSkip( tables );
161+
try
162+
{
163+
context->setTablesToSkip( tables );
164+
}
165+
catch ( const GeoDiffException &exc )
166+
{
167+
return handleException( context, exc );
168+
}
162169
return GEODIFF_SUCCESS;
163170
}
164171

@@ -182,7 +189,14 @@ int GEODIFF_CX_setTablesToInclude( GEODIFF_ContextH contextHandle, int tablesCou
182189
tables.push_back( tablesToInclude[i] );
183190
}
184191

185-
context->setTablesToInclude( tables );
192+
try
193+
{
194+
context->setTablesToInclude( tables );
195+
}
196+
catch ( const GeoDiffException &exc )
197+
{
198+
return handleException( context, exc );
199+
}
186200
return GEODIFF_SUCCESS;
187201
}
188202

pygeodiff/geodifflib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,20 @@ def set_tables_to_skip(self, context, tables):
248248
for i in range(len(tables)):
249249
arr[i] = tables[i].encode("utf-8")
250250

251-
self.lib.GEODIFF_CX_setTablesToSkip(
252-
ctypes.c_void_p(context), ctypes.c_int(len(tables)), arr
253-
)
251+
func = self.lib.GEODIFF_CX_setTablesToSkip
252+
func.restype = ctypes.c_int
253+
rc = func(ctypes.c_void_p(context), ctypes.c_int(len(tables)), arr)
254+
self._parse_return_code(context, rc, "set_tables_to_skip")
254255

255256
def set_tables_to_include(self, context, tables):
256257
arr = (ctypes.c_char_p * len(tables))()
257258
for i in range(len(tables)):
258259
arr[i] = tables[i].encode("utf-8")
259260

260-
self.lib.GEODIFF_CX_setTablesToInclude(
261-
ctypes.c_void_p(context), ctypes.c_int(len(tables)), arr
262-
)
261+
func = self.lib.GEODIFF_CX_setTablesToInclude
262+
func.restype = ctypes.c_int
263+
rc = func(ctypes.c_void_p(context), ctypes.c_int(len(tables)), arr)
264+
self._parse_return_code(context, rc, "set_tables_to_include")
263265

264266
def version(self):
265267
func = self.lib.GEODIFF_version

pygeodiff/tests/test_skip_tables.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
geodiff_test_dir,
1414
tmpdir,
1515
)
16+
from pygeodiff import GeoDiffLibError
1617

1718

1819
class UnitTestsPythonSingleCommit(GeoDiffTests):
@@ -183,3 +184,14 @@ def test_include_apply(self):
183184
check_nchanges(self.geodiff, changeset2, 0)
184185

185186
self.geodiff.set_tables_to_include([])
187+
188+
def test_skip_and_include_raises_error(self):
189+
with self.assertRaises(GeoDiffLibError):
190+
self.geodiff.set_tables_to_skip(["lines"])
191+
self.geodiff.set_tables_to_include(["points"])
192+
193+
def test_include_and_skip_raises_error(self):
194+
with self.assertRaises(GeoDiffLibError):
195+
self.geodiff.set_tables_to_include(["points"])
196+
self.geodiff.set_tables_to_skip(["lines"])
197+

0 commit comments

Comments
 (0)