Skip to content

Commit

Permalink
Merge "Fix chrome difftests" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Timin authored and Gerrit Code Review committed Jan 20, 2025
2 parents 8072e96 + 8b5949c commit 8e323bd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion python/generators/diff_tests/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ def validate(self, name_filter: str):
return bool(query_metric_pattern.match(os.path.basename(self.name)))


# str.removeprefix is available in Python 3.9+, but the Perfetto CI runs on
# older versions.
def removeprefix(s: str, prefix: str):
if s.startswith(prefix):
return s[len(prefix):]
return s

# Virtual class responsible for fetching diff tests.
# All functions with name starting with `test_` have to return
# DiffTestBlueprint and function name is a test name. All DiffTestModules have
Expand All @@ -259,7 +266,11 @@ def __init__(
test_data_dir: str = os.path.abspath(
os.path.join(__file__, '../../../../test/data'))
) -> None:
self.dir_name = '/'.join(self.__class__.__module__.split('.')[1:-1])
# The last path in the module is the module name itself, which is not a part
# of the directory. The first part is "diff_tests.", but it is not present
# when running difftests from Chrome, so we strip it conditionally.
self.dir_name = '/'.join(
removeprefix(self.__class__.__module__, 'diff_tests.').split('.')[:-1])
self.index_dir = os.path.join(include_index_dir, self.dir_name)
self.class_name = self.__class__.__name__
self.test_data_dir = test_data_dir
Expand Down

0 comments on commit 8e323bd

Please sign in to comment.