Skip to content

Commit

Permalink
Fix python CI crash in mergin-py-client (#184)
Browse files Browse the repository at this point in the history
* Switch from nose2 to pytest for auto tests

* Update argument types of functions (hopefully fixing crashes)

* fix pytest command
  • Loading branch information
wonder-sk authored Aug 5, 2022
1 parent e5633f4 commit 465b16a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/coverage_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jobs:
sudo apt-get install -y lcov
sudo apt-get install libpq-dev
sudo apt-get install postgresql-12 postgresql-contrib-12 postgresql-12-postgis-3 postgresql-common postgis
sudo apt-get install -y python3 libsqlite3-dev cmake cmake-data
sudo python3 scripts/ci/get-pip.py
sudo python3 -m pip install nose2
sudo apt-get install -y python3 python3-pytest libsqlite3-dev cmake cmake-data
- name: start PG database
run: |
Expand Down Expand Up @@ -54,7 +52,7 @@ jobs:
- name: Run python tests
run: |
GEODIFFLIB=`pwd`/build_coverage_lnx/libgeodiff.so nose2
GEODIFFLIB=`pwd`/build_coverage_lnx/libgeodiff.so pytest-3 pygeodiff/
- name: Prepare coverage report
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
- name: Install Deps
run: |
brew install sqlite3
pip install setuptools scikit-build wheel cmake nose2
pip install setuptools scikit-build wheel cmake
- name: Build wheels
uses: pypa/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ C++ tests: run `make test` or `ctest` to run all tests. Alternatively run just a

Python tests: you need to setup GEODIFFLIB with path to .so/.dylib from build step
```bash
GEODIFFLIB=`pwd`/../build/libgeodiff.dylib nose2
GEODIFFLIB=`pwd`/../build/libgeodiff.dylib pytest
```

### Releasing new version
Expand Down
8 changes: 4 additions & 4 deletions pygeodiff/geodifflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _register_functions(self):

# ChangesetReader
self._CR_nextEntry = self.lib.GEODIFF_CR_nextEntry
self._CR_nextEntry.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
self._CR_nextEntry.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
self._CR_nextEntry.restype = ctypes.c_void_p

self._CR_destroy = self.lib.GEODIFF_CR_destroy
Expand All @@ -102,11 +102,11 @@ def _register_functions(self):
self._CE_count.restype = ctypes.c_int

self._CE_old_value = self.lib.GEODIFF_CE_oldValue
self._CE_old_value.argtypes = [ctypes.c_void_p, ctypes.c_int]
self._CE_old_value.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int]
self._CE_old_value.restype = ctypes.c_void_p

self._CE_new_value = self.lib.GEODIFF_CE_newValue
self._CE_new_value.argtypes = [ctypes.c_void_p, ctypes.c_int]
self._CE_new_value.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int]
self._CE_new_value.restype = ctypes.c_void_p

self._CE_destroy = self.lib.GEODIFF_CE_destroy
Expand All @@ -122,7 +122,7 @@ def _register_functions(self):
self._CT_column_count.restype = ctypes.c_int

self._CT_column_is_pkey = self.lib.GEODIFF_CT_columnIsPkey
self._CT_column_is_pkey.argtypes = [ctypes.c_void_p, ctypes.c_int]
self._CT_column_is_pkey.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int]
self._CT_column_is_pkey.restype = ctypes.c_bool

# Value
Expand Down
14 changes: 8 additions & 6 deletions pygeodiff/tests/test_changeset_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def test_iterator(self):
self.assertEqual(entry.old_values[0], 'simple')
else: # change in 'simple' table
self.assertEqual(entry.table.name, 'simple')
self.assertEqual(entry.table.column_is_pkey[0], True)
self.assertEqual(entry.table.column_is_pkey[1], False)
self.assertEqual(entry.old_values[0], 1)
self.assertIsInstance(entry.new_values[0], UndefinedValue)
self.assertIsInstance(entry.old_values[1], bytes)
Expand All @@ -56,9 +58,9 @@ def test_insert(self):
changeset = os.path.join(testdir(), "2_inserts", "base-inserted_1_A.diff")
i = 0
for entry in self.geodiff.read_changeset(changeset):
self.assertEquals(entry.table.name, 'simple')
self.assertEquals(entry.new_values[0], 4)
self.assertEquals(entry.new_values[2], 'my new point A')
self.assertEqual(entry.table.name, 'simple')
self.assertEqual(entry.new_values[0], 4)
self.assertEqual(entry.new_values[2], 'my new point A')
with self.assertRaises(AttributeError):
print(entry.old_values) # with INSERT the "old_values" attribute is not set
i += 1
Expand All @@ -68,9 +70,9 @@ def test_delete(self):
changeset = os.path.join(testdir(), "2_deletes", "base-deleted_A.diff")
i = 0
for entry in self.geodiff.read_changeset(changeset):
self.assertEquals(entry.table.name, 'simple')
self.assertEquals(entry.old_values[0], 2)
self.assertEquals(entry.old_values[2], 'feature2')
self.assertEqual(entry.table.name, 'simple')
self.assertEqual(entry.old_values[0], 2)
self.assertEqual(entry.old_values[2], 'feature2')
with self.assertRaises(AttributeError):
print(entry.new_values) # with DELETE the "new_values" attribute is not set
i += 1
Expand Down
5 changes: 4 additions & 1 deletion pygeodiff/tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import shutil

class TestError(Exception):
pass
__test__ = False # this is not a test class, this will make pytest to ignore it


REFDIF = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -78,6 +78,9 @@ def test_json(geodiff, changeset, json, expect_success ):
_test_json(geodiff.list_changes, changeset, json, expect_success)


test_json.__test__ = False # this is not a standalone test, this will make pytest to ignore it


def compare_json(json_file, expected_json):
print ("comparing JSON to " + expected_json)
if not os.path.exists(json_file):
Expand Down

0 comments on commit 465b16a

Please sign in to comment.