Skip to content

Commit

Permalink
Fixes packaging bug with multiple exp that have the same report type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vulder authored Sep 23, 2023
1 parent af451e3 commit 4b0e29b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/data/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ def test_get_uuid(self):
self.assertEqual(self.report_filename.uuid, self.correct_UUID)
self.assertRaises(ValueError, lambda: self.broken_report_filename.uuid)

def test_experiment_shorthand_parsing_with_path_in_name(self) -> None:
"""Checks that we correctly parse the experiment shorthand also in cases
where we have a path as part of the filename."""
prefixed = ReportFilename(
"/tmp/foobar/" + self.report_filename.filename
)
self.assertEqual(prefixed.experiment_shorthand, "CRE")


class TestConfigReportFilename(unittest.TestCase):
"""Test configuration specific ReportFilename functionality."""
Expand Down
54 changes: 52 additions & 2 deletions tests/paper_mgmt/test_case_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def test_get_newest_result_files_for_case_study_with_empty_res_dir(
UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES
)
def test_get_newest_result_files_for_case_study_with_config(self) -> None:
"""Check that when we have two files, the newes one get's selected."""
"""Check that when we have two files that differ in their config id,
both get selected."""
vara_cfg()['paper_config']['current_config'] = "test_config_ids"
load_paper_config()

Expand Down Expand Up @@ -273,7 +274,56 @@ def test_get_newest_result_files_for_case_study_with_config(self) -> None:

self.assertEqual(newest_res_filenames[0].config_id, 0)
self.assertEqual(newest_res_filenames[1].config_id, 1)
self.assertEqual(len(newest_res_filenames), 2)
self.assertEqual(newest_res_filenames[2].config_id, 0)
self.assertEqual(newest_res_filenames[3].config_id, 1)
self.assertEqual(len(newest_res_filenames), 4)

@run_in_test_environment(
UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES
)
def test_get_newest_result_files_for_case_study_with_diff_exp(self) -> None:
"""Check that when we have two files that differ in their experiment
shorthand, both get selected."""
vara_cfg()['paper_config']['current_config'] = "test_config_ids"
load_paper_config()

config_0_file = ReportFilename(
"BBBase-CR-SynthSAContextSensitivity-ContextSense-06eac0edb6/"
"b24ee2c1-fc85-47ba-abbd-90c98e88a37c_config-0_success.zip"
)
config_1_file = ReportFilename(
"BBBaseO-CR-SynthSAContextSensitivity-ContextSense-06eac0edb6/"
"b24ee2c1-fc85-47ba-abbd-90c98e88a37c_config-0_success.zip"
)

now = datetime.now().timestamp()
file_path_0 = Path(
str(vara_cfg()['result_dir'])
) / 'SynthSAContextSensitivity' / config_0_file.filename
os.utime(file_path_0, (now, now))

file_path_1 = Path(
str(vara_cfg()['result_dir'])
) / 'SynthSAContextSensitivity' / config_1_file.filename
os.utime(file_path_1, (now, now))

newest_res_files = MCS.get_newest_result_files_for_case_study(
get_paper_config().get_case_studies('SynthSAContextSensitivity')[0],
Path(vara_cfg()['result_dir'].value), CR
)

newest_res_files.sort(reverse=True)
newest_res_filenames = [ReportFilename(x) for x in newest_res_files]

self.assertEqual(
newest_res_filenames[0].experiment_shorthand, "BBBaseO"
)
self.assertEqual(
newest_res_filenames[1].experiment_shorthand, "BBBaseO"
)
self.assertEqual(newest_res_filenames[2].experiment_shorthand, "BBBase")
self.assertEqual(newest_res_filenames[3].experiment_shorthand, "BBBase")
self.assertEqual(len(newest_res_filenames), 4)

def test_get_case_study_file_name_filter_empty(self) -> None:
"""Check that we correctly handle case study filter generation even if
Expand Down
2 changes: 1 addition & 1 deletion varats-core/varats/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def experiment_shorthand(self) -> str:
the experiment shorthand from a result file
"""
if (match := ReportFilename.__RESULT_FILE_REGEX.search(self.filename)):
return match.group("experiment_shorthand")
return match.group("experiment_shorthand").split('/')[-1]

raise ValueError(f'File {self.filename} name was wrongly formatted.')

Expand Down
17 changes: 12 additions & 5 deletions varats/varats/paper_mgmt/case_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_newest_result_files_for_case_study(
Returns:
list of result file paths
"""
files_to_store: tp.Dict[tp.Tuple[ShortCommitHash, tp.Optional[int]],
files_to_store: tp.Dict[tp.Tuple[ShortCommitHash, str, tp.Optional[int]],
Path] = {}

result_dir /= case_study.project_name
Expand All @@ -319,16 +319,23 @@ def get_newest_result_files_for_case_study(
)

if case_study.has_revision(commit_hash) and config_id_matches:
current_file = files_to_store.get((commit_hash, config_id),
None)
current_file = files_to_store.get(
(commit_hash, report_file.experiment_shorthand, config_id),
None
)
if current_file is None:
files_to_store[(commit_hash, config_id)] = opt_res_file
files_to_store[(
commit_hash, report_file.experiment_shorthand, config_id
)] = opt_res_file
else:
if (
current_file.stat().st_mtime <
opt_res_file.stat().st_mtime
):
files_to_store[(commit_hash, config_id)] = opt_res_file
files_to_store[(
commit_hash, report_file.experiment_shorthand,
config_id
)] = opt_res_file

return list(files_to_store.values())

Expand Down

0 comments on commit 4b0e29b

Please sign in to comment.