Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds config support for revision look ups #855

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added tests/revision/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/revision/test_revisions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Test revision helper functions."""

import unittest

from tests.helper_utils import run_in_test_environment, UnitTestFixtures
from varats.paper.paper_config import load_paper_config
from varats.revision.revisions import get_processed_revisions_files
from varats.utils.settings import vara_cfg


class TestGetProcessedRevisionsFiles(unittest.TestCase):
"""Test if the revision look up works correctly."""

@run_in_test_environment(
UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES
)
def test_config_specific_lookup(self) -> None:
"""Check whether the config specific file loading works."""
vara_cfg()['paper_config']['current_config'] = "test_config_ids"
load_paper_config()

processed_rev_files_cid_1 = get_processed_revisions_files(
"SynthSAContextSensitivity", config_id=1
)
self.assertEqual(len(processed_rev_files_cid_1), 1)
self.assertEqual(
processed_rev_files_cid_1[0].report_filename.config_id, 1
)

processed_rev_files_cid_2 = get_processed_revisions_files(
"SynthSAContextSensitivity", config_id=2
)
# there should not be a report for config id 2
self.assertEqual(len(processed_rev_files_cid_2), 0)
50 changes: 39 additions & 11 deletions varats-core/varats/revision/revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def __get_files_with_status(
experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None,
report_type: tp.Optional[tp.Type[BaseReport]] = None,
file_name_filter: tp.Callable[[str], bool] = lambda x: False,
only_newest: bool = True
only_newest: bool = True,
config_id: tp.Optional[int] = None
) -> tp.List[ReportFilepath]:
"""
Find all file paths to result files with given file statuses.
Expand All @@ -148,7 +149,15 @@ def __get_files_with_status(
result_files = __get_result_files_dict(
project_name, experiment_type, report_type
)

for value in result_files.values():
if config_id is not None:
value = [
x for x in value if x.report_filename.config_id == config_id
]
if not value:
continue

sorted_res_files = sorted(
value, key=lambda x: x.stat().st_mtime, reverse=True
)
Expand All @@ -168,7 +177,8 @@ def get_all_revisions_files(
experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None,
report_type: tp.Optional[tp.Type[BaseReport]] = None,
file_name_filter: tp.Callable[[str], bool] = lambda x: False,
only_newest: bool = True
only_newest: bool = True,
config_id: tp.Optional[int] = None
) -> tp.List[ReportFilepath]:
"""
Find all file paths to revision files.
Expand All @@ -188,8 +198,13 @@ def get_all_revisions_files(
a list of file paths to correctly processed revision files
"""
return __get_files_with_status(
project_name, list(FileStatusExtension.get_physical_file_statuses()),
experiment_type, report_type, file_name_filter, only_newest
project_name=project_name,
file_statuses=list(FileStatusExtension.get_physical_file_statuses()),
experiment_type=experiment_type,
report_type=report_type,
file_name_filter=file_name_filter,
only_newest=only_newest,
config_id=config_id
)


Expand All @@ -198,7 +213,8 @@ def get_processed_revisions_files(
experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None,
report_type: tp.Optional[tp.Type[BaseReport]] = None,
file_name_filter: tp.Callable[[str], bool] = lambda x: False,
only_newest: bool = True
only_newest: bool = True,
config_id: tp.Optional[int] = None
) -> tp.List[ReportFilepath]:
"""
Find all file paths to correctly processed revision files.
Expand All @@ -218,8 +234,13 @@ def get_processed_revisions_files(
a list of file paths to correctly processed revision files
"""
return __get_files_with_status(
project_name, [FileStatusExtension.SUCCESS], experiment_type,
report_type, file_name_filter, only_newest
project_name=project_name,
file_statuses=[FileStatusExtension.SUCCESS],
experiment_type=experiment_type,
report_type=report_type,
file_name_filter=file_name_filter,
only_newest=only_newest,
config_id=config_id
)


Expand All @@ -228,7 +249,8 @@ def get_failed_revisions_files(
experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None,
report_type: tp.Optional[tp.Type[BaseReport]] = None,
file_name_filter: tp.Callable[[str], bool] = lambda x: False,
only_newest: bool = True
only_newest: bool = True,
config_id: tp.Optional[int] = None
) -> tp.List[ReportFilepath]:
"""
Find all file paths to failed revision files.
Expand All @@ -248,9 +270,15 @@ def get_failed_revisions_files(
a list of file paths to failed revision files
"""
return __get_files_with_status(
project_name,
[FileStatusExtension.FAILED, FileStatusExtension.COMPILE_ERROR],
experiment_type, report_type, file_name_filter, only_newest
project_name=project_name,
file_statuses=[
FileStatusExtension.FAILED, FileStatusExtension.COMPILE_ERROR
],
experiment_type=experiment_type,
report_type=report_type,
file_name_filter=file_name_filter,
only_newest=only_newest,
config_id=config_id
)


Expand Down
Loading