Skip to content

Commit

Permalink
get_double_task_run_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
wangpatrick57 committed Dec 27, 2024
1 parent 316ca02 commit 7454757
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions util/tests/unittest_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ def get_updated_structure_from_workspace_init(
)
return structure

def get_double_task_run_setup(self) -> tuple[DBGymWorkspace, FilesystemStructure]:
"""
Any tests involving save_file() will involve two task runs so it's convenient to have this helper.
"""
# This first initialization will create a task run.
workspace = DBGymWorkspace(self.workspace_path)
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)
structure = WorkspaceTests.get_updated_structure_from_workspace_init(
structure, workspace
)

return workspace, structure

def test_init_from_nonexistent_workspace(self) -> None:
starting_structure = FilesystemStructure({})
create_structure(self.scratchspace_path, starting_structure)
Expand All @@ -82,19 +101,7 @@ def test_init_from_empty_workspace(self) -> None:
self.assertTrue(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 = WorkspaceTests.get_updated_structure_from_workspace_init(
ending_structure, workspace
)

_, ending_structure = self.get_double_task_run_setup()
self.assertTrue(verify_structure(self.scratchspace_path, ending_structure))


Expand Down

0 comments on commit 7454757

Please sign in to comment.