Skip to content

Commit

Permalink
added SQLBackend commit/close methods and a TestBackendPersistence me…
Browse files Browse the repository at this point in the history
…thod (#51)

Co-authored-by: collinsag <collinsag@egr-u-ec-ce-05.rams.adp.vcu.edu>
  • Loading branch information
acthecoder23 and collinsag committed May 13, 2024
1 parent cb67563 commit 52f6db8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions grand/backends/_sqlbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,9 @@ def ingest_from_edgelist_dataframe(
"edge_count": len(edgelist),
"edge_duration": edge_toc,
}

def commit(self):
self._connection.commit()

def close(self):
self._connection.close()
23 changes: 23 additions & 0 deletions grand/backends/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@
),
)

# @pytest.mark.parametrize("backend", backend_test_params)
class TestBackendPersistence:
def test_sqlite_persistence(self):
if not _CAN_IMPORT_SQL:
return

dbpath = "grand_peristence_test_temp.db"
url = "sqlite:///"+dbpath

#arrange
backend = SQLBackend(db_url=url, directed=True)
node0 = backend.add_node("A",{"foo":"bar"})
backend.commit()
backend.close()
#act
backend = SQLBackend(db_url=url, directed=True)
nodes = list(backend.all_nodes_as_iterable())
#assert
assert node0 in nodes
#cleanup
os.remove(dbpath)



@pytest.mark.parametrize("backend", backend_test_params)
class TestBackend:
Expand Down

0 comments on commit 52f6db8

Please sign in to comment.