Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added SQLBackend commit/close methods and a TestBackendPersistence me… #51

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart :)

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
Loading