Skip to content

Commit cff5579

Browse files
Return new db in empty db initializer (#217)
1 parent 08a5cf2 commit cff5579

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/openlifu/db/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def get_default_path():
10771077
return Path(Database.get_default_user_dir()) / "Documents" / "db"
10781078

10791079
@staticmethod
1080-
def initialize_empty_database(database_filepath : Path | str) -> None:
1080+
def initialize_empty_database(database_filepath : Path | str) -> "Database":
10811081
"""
10821082
Initializes an empty database at the given database_filepath
10831083
"""
@@ -1092,4 +1092,4 @@ def initialize_empty_database(database_filepath : Path | str) -> None:
10921092
new_db.write_user_ids([])
10931093
new_db.write_subject_ids([])
10941094
new_db.write_transducer_ids([])
1095-
#new_db.write_system_ids([])
1095+
return new_db

tests/test_database.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def example_transducer(example_database : Database) -> Transducer:
4444
filename = Path(example_database.path)/"transducers/example_transducer/example_transducer.json",
4545
)
4646

47+
def test_new_database(tmp_path:Path):
48+
"""Test that a new empty database can be created that more or less works"""
49+
db1 = Database.initialize_empty_database(tmp_path/"db1")
50+
db2 = Database.initialize_empty_database(str(tmp_path/"db2")) # make sure using string also works
51+
assert len(db1.get_protocol_ids()) == 0
52+
assert len(db1.get_user_ids()) == 0
53+
assert len(db1.get_subject_ids()) == 0
54+
assert len(db1.get_transducer_ids()) == 0
55+
56+
4757
def test_write_protocol(example_database: Database):
4858
protocol = Protocol(name="bleh", id="a_protocol_called_bleh")
4959

0 commit comments

Comments
 (0)