Skip to content

Commit

Permalink
PR changes update
Browse files Browse the repository at this point in the history
  • Loading branch information
raksharuia committed Oct 18, 2024
1 parent 29ff426 commit 3a451ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
11 changes: 5 additions & 6 deletions perceval/runtime/job_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def _job_group_exists(name: str) -> bool:
"""
Returns True if a JobGroup with an identical name is already saved on disk
"""
saved_job_groups = JobGroup.list_existing()
return any([jg_name == name for jg_name in saved_job_groups])
return JobGroup._JGRP_PERSISTENT_DATA.has_file(os.path.join(JobGroup._JGRP_DIR_PATH, name + '.' + FILE_EXT_JGRP))

def add(self, job_to_add: RemoteJob, **kwargs):
"""
Expand Down Expand Up @@ -247,17 +246,17 @@ def delete_all_job_groups():
jgrp_dir_path = JobGroup._JGRP_DIR_PATH
list_groups = JobGroup.list_existing()
for each_file in list_groups:
JobGroup._JGRP_PERSISTENT_DATA.delete_file(os.path.join(jgrp_dir_path, each_file))
JobGroup._JGRP_PERSISTENT_DATA.delete_file(os.path.join(jgrp_dir_path, each_file + '.' + FILE_EXT_JGRP))

@staticmethod
def delete_job_group(filename: str):
def delete_job_group(group_name: str):
"""
Delete a single JobGroup file by its name
:param filename: a JobGroup name to delete
:param group_name: a JobGroup name to delete
"""
jgrp_dir_path = JobGroup._JGRP_DIR_PATH

JobGroup._JGRP_PERSISTENT_DATA.delete_file(os.path.join(jgrp_dir_path, filename + FILE_EXT_JGRP))
JobGroup._JGRP_PERSISTENT_DATA.delete_file(os.path.join(jgrp_dir_path, group_name + '.' + FILE_EXT_JGRP))

@staticmethod
def delete_job_groups_date(del_before_date: datetime):
Expand Down
8 changes: 2 additions & 6 deletions tests/test_job_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@

TEST_JG_NAME = 'UnitTest_Job_Group'

@patch.object(JobGroup, 'list_existing')
@patch.object(JobGroup, '_write_job_group_to_disk')
def test_job_group_creation(mock_write_file, mock_list):
def test_job_group_creation(mock_write_file):
jgroup = JobGroup(TEST_JG_NAME)
assert jgroup.name == TEST_JG_NAME
assert len(jgroup.list_remote_jobs) == 0 # empty job group
Expand All @@ -48,11 +47,9 @@ def test_job_group_creation(mock_write_file, mock_list):

# assert mock methods called
mock_write_file.assert_called_once()
mock_list.assert_called_once()

@patch.object(JobGroup, 'list_existing')
@patch.object(JobGroup, '_write_job_group_to_disk')
def test_reject_non_remote_job(mock_write_file, mock_list):
def test_reject_non_remote_job(mock_write_file):
# creating a local job - sampling
p = catalog["postprocessed cnot"].build_processor()
p.with_input(BasicState([0, 1, 0, 1]))
Expand All @@ -65,7 +62,6 @@ def test_reject_non_remote_job(mock_write_file, mock_list):

# assert mock methods called
mock_write_file.assert_called_once()
mock_list.assert_called_once()

@patch.object(JobGroup, 'list_existing')
@patch.object(JobGroup, '_read_job_group_from_disk')
Expand Down

0 comments on commit 3a451ed

Please sign in to comment.