Skip to content

Commit

Permalink
Merge 93eb71c into de86164
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Sep 23, 2019
2 parents de86164 + 93eb71c commit 22e069b
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 66 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.2.6";
return "0.3.0";
}

void _errorLogCallback( void *pArg, int iErrCode, const char *zMsg )
Expand Down
8 changes: 6 additions & 2 deletions geodiff/src/geodiffutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,17 @@ void tables( std::shared_ptr<Sqlite3Db> db,
rtree_simple_geometry_node
rtree_simple_geometry_parent
rtree_simple_geometry_rowid
simple
simple (or any other name(s) of layers)
sqlite_sequence
*/
if ( startsWith( tableName, "gpkg_" ) )

// table handled by triggers trigger_*_feature_count_*
if ( startsWith( tableName, "gpkg_ogr_contents" ) )
continue;
// table handled by triggers rtree_*_geometry_*
if ( startsWith( tableName, "rtree_" ) )
continue;
// internal table for AUTOINCREMENT
if ( tableName == "sqlite_sequence" )
continue;

Expand Down
8 changes: 6 additions & 2 deletions geodiff/tests/geodiff_testutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ void finalize_test()
{
}

bool equals( const std::string &file1, const std::string &file2 )
bool equals( const std::string &file1, const std::string &file2, bool ignore_timestamp_change )
{
std::string changeset = file1 + "_changeset.bin";
if ( GEODIFF_createChangeset( file1.c_str(), file2.c_str(), changeset.c_str() ) != GEODIFF_SUCCESS )
return false;

return ( GEODIFF_listChanges( changeset.c_str() ) == 0 );
int expected_changes = 0;
if ( ignore_timestamp_change )
expected_changes = 1;

return ( GEODIFF_listChanges( changeset.c_str() ) == expected_changes );
}

void makedir( const std::string &dir )
Expand Down
2 changes: 1 addition & 1 deletion geodiff/tests/geodiff_testutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ void finalize_test();
std::string test_file( std::string basename );
std::string tmp_file( std::string basename );

bool equals( const std::string &file1, const std::string &file2 );
bool equals( const std::string &file1, const std::string &file2, bool ignore_timestamp_change = false );

#endif // GEODIFF_TESTUTILS_HPP
32 changes: 17 additions & 15 deletions geodiff/tests/test_concurrent_commits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ bool _test(
const std::string &expected_AB,
int expected_changes_A,
int expected_changes_AB,
int expected_changes_XB
int expected_changes_XB,
bool ignore_timestamp_change = false
)
{
makedir( pathjoin( tmpdir(), testname ) );
Expand Down Expand Up @@ -80,7 +81,7 @@ bool _test(

// check that it equals expected result
std::cout << "final file: " << patchedAB << std::endl;
return equals( patchedAB, expected_patchedAB ) ;
return equals( patchedAB, expected_patchedAB, ignore_timestamp_change ) ;
}

TEST( ConcurrentCommitsSqlite3Test, test_2_inserts )
Expand All @@ -95,9 +96,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_2_inserts )
"inserted_1_A.gpkg",
"inserted_1_B.gpkg",
"merged_1_A_1_B.gpkg",
1,
1,
2
2,
2,
3
);
ASSERT_TRUE( ret );
}
Expand All @@ -116,9 +117,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_2_edits )
"updated_A.gpkg",
"updated_B.gpkg",
"merged_1_A_1_B.gpkg",
1,
1,
1
2,
2,
2
);
ASSERT_TRUE( ret );
}
Expand All @@ -135,9 +136,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_2_deletes )
"deleted_A.gpkg",
"deleted_B.gpkg",
"merged_A_B.gpkg",
2,
1,
0,
1
2
);
ASSERT_TRUE( ret );
}
Expand All @@ -154,9 +155,10 @@ TEST( ConcurrentCommitsSqlite3Test, test_delete_update )
"deleted_A.gpkg",
"updated_B.gpkg",
"deleted_A.gpkg",
2,
1,
0,
1
2,
true
);
ASSERT_TRUE( ret );
}
Expand All @@ -173,9 +175,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_update_delete )
"updated_A.gpkg",
"deleted_B.gpkg",
"deleted_B.gpkg",
1,
1,
1
2,
2,
2
);
ASSERT_TRUE( ret );
}
Expand Down
14 changes: 0 additions & 14 deletions geodiff/tests/test_modified_scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,6 @@ TEST( ModifiedSchemeSqlite3Test, rename_attribute )
ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_UNSUPPORTED_CHANGE );
}

TEST( ModifiedSchemeSqlite3Test, retype_attribute )
{
std::cout << "geopackage attribute count is same, have same name, but different type" << std::endl;
std::string testname = "retype_attribute";
makedir( pathjoin( tmpdir(), testname ) );

std::string base = pathjoin( testdir(), "modified_scheme", "added_attribute.gpkg" );
std::string modified = pathjoin( testdir(), "modified_scheme", "added_attribute_different_type.gpkg" );
std::string changeset = pathjoin( tmpdir(), testname, "changeset.bin" );

// this is supported since sqlite3 uses dynamic run-time typing
ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_SUCCESS );
}

int main( int argc, char **argv )
{
testing::InitGoogleTest( &argc, argv );
Expand Down
100 changes: 76 additions & 24 deletions geodiff/tests/test_single_commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,95 @@
#include "geodiff_testutils.hpp"
#include "geodiff.h"

TEST( SingleCommitSqlite3Test, test_sqlite_no_gis )
bool _test(
const std::string &testname,
const std::string &basename,
const std::string &modifiedname,
int expected_changes,
bool ignore_timestamp_change = false
)
{
std::cout << "sqlite 2 updated 1 added 1 deleted" << std::endl;
std::string testname = "pure_sqlite";
std::cout << testname << std::endl;
makedir( pathjoin( tmpdir(), testname ) );

std::string base = pathjoin( testdir(), "base.sqlite" );
std::string modified = pathjoin( testdir(), testname, "modified_base.sqlite" );
std::string changeset = pathjoin( tmpdir(), testname, "changeset_base_sqlite.bin" );
std::string changeset2 = pathjoin( tmpdir(), testname, "changeset_after_apply_base_sqlite.bin" );
std::string patched = pathjoin( tmpdir(), testname, "patched_base_sqlite.gpkg" );
std::string base = pathjoin( testdir(), basename );
std::string modified = pathjoin( testdir(), modifiedname );
std::string changeset = pathjoin( tmpdir(), testname, "changeset.bin" );
std::string patched = pathjoin( tmpdir(), testname, "patched.gpkg" );

if ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ) != GEODIFF_SUCCESS )
{
std::cout << "err GEODIFF_createChangeset" << std::endl;
return false;
}

ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_SUCCESS );
ASSERT_EQ( GEODIFF_listChanges( changeset.c_str() ), 4 );
ASSERT_EQ( GEODIFF_applyChangeset( base.c_str(), patched.c_str(), changeset.c_str() ), GEODIFF_SUCCESS );
int nchanges = GEODIFF_listChanges( changeset.c_str() );
if ( nchanges != expected_changes )
{
std::cout << "err GEODIFF_listChanges " << nchanges << " vs " << expected_changes << std::endl;
return false;
}

if ( GEODIFF_applyChangeset( base.c_str(), patched.c_str(), changeset.c_str() ) != GEODIFF_SUCCESS )
{
std::cout << "err GEODIFF_applyChangeset" << std::endl;
return false;
}

// check that now it is same file
ASSERT_TRUE( equals( patched, modified ) );
if ( !equals( patched, modified, ignore_timestamp_change ) )
{
std::cout << "err equals" << std::endl;
return false;
}

return true;

}


TEST( SingleCommitSqlite3Test, test_sqlite_no_gis )
{
std::cout << "sqlite 2 updated 1 added 1 deleted" << std::endl;
bool ret = _test( "pure_sqlite",
"base.sqlite",
pathjoin( "pure_sqlite", "modified_base.sqlite" ),
4
);
ASSERT_TRUE( ret );
}

TEST( SingleCommitSqlite3Test, geopackage )
{
std::cout << "geopackage 1 updated geometry" << std::endl;
std::string testname = "1_geopackage";
makedir( pathjoin( tmpdir(), testname ) );

std::string base = pathjoin( testdir(), "base.gpkg" );
std::string modified = pathjoin( testdir(), testname, "modified_1_geom.gpkg" );
std::string changeset = pathjoin( tmpdir(), testname, "changeset_base_gpkg.bin" );
std::string patched = pathjoin( tmpdir(), testname, "patched_base_gpkg.gpkg" );
bool ret = _test( "1_geopackage",
"base.gpkg",
pathjoin( "1_geopackage", "modified_1_geom.gpkg" ),
2
);
ASSERT_TRUE( ret );
}

ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_SUCCESS );
ASSERT_EQ( GEODIFF_listChanges( changeset.c_str() ), 1 );
ASSERT_EQ( GEODIFF_applyChangeset( base.c_str(), patched.c_str(), changeset.c_str() ), GEODIFF_SUCCESS );
TEST( SingleCommitSqlite3Test, retype_attribute )
{
std::cout << "geopackage attribute count is same, have same name, but different type" << std::endl;
bool ret = _test( "retype_attribute",
pathjoin( "modified_scheme", "added_attribute.gpkg" ),
pathjoin( "modified_scheme", "added_attribute_different_type.gpkg" ),
4
);
ASSERT_TRUE( ret );
}

// check that now it is same file
ASSERT_TRUE( equals( patched, modified ) );
TEST( SingleCommitSqlite3Test, reprojected )
{
std::cout << "geopackage change of crs" << std::endl;
bool ret = _test( "reprojected",
pathjoin( "modified_scheme", "reprojected.gpkg" ),
pathjoin( "modified_scheme", "reprojected2.gpkg" ),
6
);
ASSERT_TRUE( ret );
}

int main( int argc, char **argv )
Expand Down
Binary file modified geodiff/tests/testdata/base.gpkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.2.6'
__version__ = '0.3.0'
__author__ = 'Peter Petrik'
__author_email__ = 'zilolv@gmail.com'
__maintainer__ = 'Peter Petrik'
Expand Down
6 changes: 3 additions & 3 deletions pygeodiff/tests/test_concurrent_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def test_2_inserts(self):

print("create changeset base to A")
self.geodiff.create_changeset(base, modifiedA, changesetbaseA)
check_nchanges(self.geodiff, changesetbaseA, 1)
check_nchanges(self.geodiff, changesetbaseA, 2)

print("create changeset A to B")
self.geodiff.create_rebased_changeset(base, modifiedB, changesetbaseA, changesetAB)
check_nchanges(self.geodiff, changesetAB, 1)
check_nchanges(self.geodiff, changesetAB, 2)

print("apply changeset to A to get AB")
self.geodiff.apply_changeset(modifiedA, patchedAB, changesetAB)

print("check that then new data has both features\n")
self.geodiff.create_changeset(base, patchedAB, changesetBbase)
check_nchanges(self.geodiff, changesetBbase, 2)
check_nchanges(self.geodiff, changesetBbase, 3)
2 changes: 1 addition & 1 deletion pygeodiff/tests/test_single_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def test_geopackage(self):
"1_geopackage",
"base.gpkg",
"modified_1_geom.gpkg",
1)
2)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja"]
requires = ["setuptools", "wheel", "scikit-build", "cmake"]
8 changes: 8 additions & 0 deletions scripts/update_version.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
VER=$1

python3 $DIR/update_version.py --version $VER



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.2.6'
VERSION = '0.3.0'

setup(
name="pygeodiff",
Expand Down

0 comments on commit 22e069b

Please sign in to comment.