diff --git a/CHANGELOG.md b/CHANGELOG.md index b93738e..22bfba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [0.11.1](https://github.com/brsynth/neo4jsbml/tree/0.11.1) (2023-09-22) + +[Full Changelog](https://github.com/brsynth/neo4jsbml/compare/0.11.0...0.11.1) + +**Merged pull requests:** + +- Add `dry-run` argument [\#10](https://github.com/brsynth/neo4jsbml/pull/10) ([guillaume-gricourt](https://github.com/guillaume-gricourt)) +- chore\(deps\): bump actions/checkout from 3 to 4 [\#9](https://github.com/brsynth/neo4jsbml/pull/9) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore\(deps\): bump github/super-linter from 4 to 5 [\#8](https://github.com/brsynth/neo4jsbml/pull/8) ([dependabot[bot]](https://github.com/apps/dependabot)) + ## [0.11.0](https://github.com/brsynth/neo4jsbml/tree/0.11.0) (2023-03-28) [Full Changelog](https://github.com/brsynth/neo4jsbml/compare/0.10.1...0.11.0) diff --git a/docs/CHANGELOG.data.rst b/docs/CHANGELOG.data.rst index f462390..3d1ed3e 100644 --- a/docs/CHANGELOG.data.rst +++ b/docs/CHANGELOG.data.rst @@ -1,6 +1,26 @@ Changelog ========= +`0.11.1 `__ (2023-09-22) +-------------------------------------------------------------------------- + +`Full +Changelog `__ + +**Merged pull requests:** + +- Add ``dry-run`` argument + `#10 `__ + (`guillaume-gricourt `__) +- chore(deps): bump actions/checkout from 3 to 4 + `#9 `__ + (`dependabot[bot] `__) +- chore(deps): bump github/super-linter from 4 to 5 + `#8 `__ + (`dependabot[bot] `__) + +.. _section-1: + `0.11.0 `__ (2023-03-28) -------------------------------------------------------------------------- @@ -13,7 +33,7 @@ Changelog `__ `#7 `__ (`guillaume-gricourt `__) -.. _section-1: +.. _section-2: `0.10.1 `__ (2023-03-17) -------------------------------------------------------------------------- @@ -21,7 +41,7 @@ Changelog `__ `Full Changelog `__ -.. _section-2: +.. _section-3: `0.10.0 `__ (2023-03-17) -------------------------------------------------------------------------- @@ -37,7 +57,7 @@ Changelog `__ - Read the docs `#5 `__ (`guillaume-gricourt `__) -.. _section-3: +.. _section-4: `0.9.2 `__ (2023-02-23) ------------------------------------------------------------------------ @@ -45,7 +65,7 @@ Changelog `__ `Full Changelog `__ -.. _section-4: +.. _section-5: `0.9.1 `__ (2023-02-21) ------------------------------------------------------------------------ @@ -53,7 +73,7 @@ Changelog `__ `Full Changelog `__ -.. _section-5: +.. _section-6: `0.9.0 `__ (2023-01-27) ------------------------------------------------------------------------ @@ -67,7 +87,7 @@ Changelog `__ `#4 `__ (`dependabot[bot] `__) -.. _section-6: +.. _section-7: `0.8.3 `__ (2023-01-16) ------------------------------------------------------------------------ @@ -75,7 +95,7 @@ Changelog `__ `Full Changelog `__ -.. _section-7: +.. _section-8: `0.8.0 `__ (2023-01-16) ------------------------------------------------------------------------ diff --git a/src/neo4jsbml/__main__.py b/src/neo4jsbml/__main__.py index 88396c2..b5a569d 100644 --- a/src/neo4jsbml/__main__.py +++ b/src/neo4jsbml/__main__.py @@ -110,9 +110,19 @@ def main(): logging.info("Connection to database") con = None if args.input_config_file: + if not os.path.isfile(args.input_config_file): + logging.error( + "File provided does not exist: %s" % (args.input_config_file,) + ) + parser.exit(1) logging.warning("Configuration file is provided, ignore indiviual arguments") con = connect.Connect.from_config(path=args.input_config_file) elif args.input_auradb_file: + if not os.path.isfile(args.input_auradb_file): + logging.error( + "File provided does not exist: %s" % (args.input_auradb_file,) + ) + parser.exit(1) logging.warning( "Configuration file AuraDB is provided, ignore indiviual arguments" ) diff --git a/src/neo4jsbml/_version.py b/src/neo4jsbml/_version.py index 70b2059..9ba7dc1 100644 --- a/src/neo4jsbml/_version.py +++ b/src/neo4jsbml/_version.py @@ -1,2 +1,2 @@ __app_name__ = "neo4jsbml" -__version__ = "0.11.1" +__version__ = "0.11.2" diff --git a/src/neo4jsbml/connect.py b/src/neo4jsbml/connect.py index 38f43ee..358dc82 100644 --- a/src/neo4jsbml/connect.py +++ b/src/neo4jsbml/connect.py @@ -261,3 +261,27 @@ def from_auradb(cls, path: str) -> "Connect": elif var == "AURA_INSTANCENAME": data["database"] = value return Connect(**data) + + def __repr__(self): + msg = [] + msg.append("Url: %s" % (self.url,)) + msg.append("Protocol: %s" % (self.protocol,)) + msg.append("Database: %s" % (self.database,)) + user = "" + if self.user: + user = self.user + msg.append("User: %s" % (user,)) + port = "" + if self.port: + port = self.port + msg.append("Port: %s" % (port,)) + password = "" + if self.password: + password = "initialized" + msg.append("Password: " + password) + msg.append("Uri: " + self.uri) + is_connected = "false" + if self.is_connected(): + is_connected = "true" + msg.append("Connected: " + is_connected) + return "\n".join(msg) diff --git a/src/neo4jsbml/entity.py b/src/neo4jsbml/entity.py index 9f10683..d089613 100644 --- a/src/neo4jsbml/entity.py +++ b/src/neo4jsbml/entity.py @@ -43,17 +43,24 @@ def __init__(self, id: str, properties: Dict[str, str], *args, **kwargs) -> None def clean_properties(self): """Remove empty values. + Sanitize string: + - remove return line + - append a backslash in front of double quotes Return ------ None """ keys = [] - for k, v in self.properties.items(): - if v is None or v == "": - keys.append(k) - for k in keys: - del self.properties[k] + for key, value in self.properties.items(): + if value is None or value == "": + keys.append(key) + elif isinstance(value, str): + value = value.replace('"', '\\"') + value = value.replace("\n", "") + self.properties[key] = value + for key in keys: + del self.properties[key] def has_property(self, label: str) -> bool: """Check if a node has a property. diff --git a/tests/conftest.py b/tests/conftest.py index 228b5b6..4e6202f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,7 @@ import os import pytest -from neo4jsbml import connect, sbml +from neo4jsbml import connect, sbml, singleton cur_dir = os.path.abspath(os.path.dirname(__file__)) data_dir = os.path.join(cur_dir, "dataset") @@ -148,6 +148,7 @@ def rel_two_arrow(): @pytest.fixture(scope="function") def init_driver(): + singleton.Singleton.clean() return connect.Connect( protocol="neo4j", url="localhost", diff --git a/tests/dataset/database/localhost.ini b/tests/dataset/database/localhost.ini index 9b7f254..dc23c5b 100644 --- a/tests/dataset/database/localhost.ini +++ b/tests/dataset/database/localhost.ini @@ -1,3 +1,4 @@ [connection] protocol = neo4j url = localhost +port = 7687 diff --git a/tests/test_neo4jsbml.py b/tests/test_neo4jsbml.py index 199d343..026631f 100644 --- a/tests/test_neo4jsbml.py +++ b/tests/test_neo4jsbml.py @@ -46,7 +46,6 @@ def load_iAF1260(init_driver, config_path, pathway_two_path, iaf1260_path): class TestiML1515: def test_nodes(self, init_driver, load_iML1515): query = "CALL db.labels() YIELD label CALL apoc.cypher.run('MATCH (:`'+label+'`) RETURN count(*) as count',{}) YIELD value RETURN label, value.count" - singleton.Singleton.clean() data = init_driver.query(value=query, expect_data=True) assert data == [ @@ -61,7 +60,6 @@ def test_nodes(self, init_driver, load_iML1515): def test_relationships(self, init_driver, load_iML1515): query = "CALL db.relationshipTypes() YIELD relationshipType as type CALL apoc.cypher.run('MATCH ()-[:`'+type+'`]->() RETURN count(*) as count',{}) YIELD value RETURN type, value.count" - singleton.Singleton.clean() data = init_driver.query(value=query, expect_data=True) assert data == [ @@ -80,7 +78,6 @@ def test_relationships(self, init_driver, load_iML1515): class TestiAF1260: def test_nodes(self, init_driver, load_iAF1260): query = "CALL db.labels() YIELD label CALL apoc.cypher.run('MATCH (:`'+label+'`) RETURN count(*) as count',{}) YIELD value RETURN label, value.count" - singleton.Singleton.clean() data = init_driver.query(value=query, expect_data=True) assert data == [ @@ -95,7 +92,6 @@ def test_nodes(self, init_driver, load_iAF1260): def test_relationships(self, init_driver, load_iAF1260): query = "CALL db.relationshipTypes() YIELD relationshipType as type CALL apoc.cypher.run('MATCH ()-[:`'+type+'`]->() RETURN count(*) as count',{}) YIELD value RETURN type, value.count" - singleton.Singleton.clean() data = init_driver.query(value=query, expect_data=True) assert data == [