Skip to content

Commit

Permalink
added more workspace init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wangpatrick57 committed Dec 27, 2024
1 parent dc1bfba commit c0772aa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manage/tests/unittest_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_nonexistent_workspace(self) -> None:
# This just ensures that it doesn't raise an exception.
clean_workspace(MockDBGymWorkspace(self.workspace_path))

def test_no_symlinks_dir_and_no_task_runs_dir(self) -> None:
def test_empty_workspace(self) -> None:
starting_structure = FilesystemStructure({"dbgym_workspace": {}})
ending_structure = FilesystemStructure({"dbgym_workspace": {}})
CleanTests.create_structure(self.scratchspace_path, starting_structure)
Expand Down
43 changes: 43 additions & 0 deletions util/tests/unittest_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def setUp(self) -> None:
if self.scratchspace_path.exists():
shutil.rmtree(self.scratchspace_path)

# Reset this to avoid the error of it being created twice.
# The assertion checking that it's only been been created once is meant to avoid creating multiple
# objects for the same workspace. However, it's fine to create it multiple times in this case because
# we're deleting the scratchspace before each test.
DBGymWorkspace.num_times_created_this_run = 0

def tearDown(self) -> None:
if self.scratchspace_path.exists():
shutil.rmtree(self.scratchspace_path)
Expand Down Expand Up @@ -51,3 +57,40 @@ def test_init_from_nonexistent_workspace(self) -> None:
self.assertTrue(
CleanTests.verify_structure(self.scratchspace_path, ending_structure)
)

def test_init_from_empty_workspace(self) -> None:
starting_structure = FilesystemStructure({"dbgym_workspace": {}})
CleanTests.create_structure(self.scratchspace_path, starting_structure)

workspace = DBGymWorkspace(self.workspace_path)
ending_structure = WorkspaceTests.get_workspace_init_structure(workspace)

self.assertTrue(
CleanTests.verify_structure(self.scratchspace_path, ending_structure)
)

def test_init_from_already_initialized_workspace(self) -> None:
# This first initialization will create a task run.
workspace = DBGymWorkspace(self.workspace_path)
ending_structure = WorkspaceTests.get_workspace_init_structure(workspace)

# The second initialization will create a second task run.
# Make sure to reset this. In real usage, the second run would be a different Python process
# so DBGymWorkspace.num_times_created_this_run would be 0.
DBGymWorkspace.num_times_created_this_run = 0
workspace = DBGymWorkspace(self.workspace_path)
ending_structure["dbgym_workspace"]["task_runs"][
workspace.dbgym_this_run_path.name
] = {}
ending_structure["dbgym_workspace"]["task_runs"]["latest_run.link"] = (
"symlink",
f"dbgym_workspace/task_runs/{workspace.dbgym_this_run_path.name}",
)

self.assertTrue(
CleanTests.verify_structure(self.scratchspace_path, ending_structure)
)


if __name__ == "__main__":
unittest.main()

0 comments on commit c0772aa

Please sign in to comment.