Skip to content

tools/tinytest-codegen: Ensure consistent tests order. #12906

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

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 19 additions & 3 deletions tools/tinytest-codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,24 @@ def script_to_map(test_file):
return r


def flatten_iterable(iterable):
flattened = set()
for element in iterable:
if isinstance(element, (list, tuple, set)):
flattened = flattened.union(flatten_iterable(element))
elif isinstance(element, str):
flattened.add(element)
else:
raise TypeError("Invalid type %s for element `%s`" % (type(element), element))
return flattened


def load_profile(profile_file, test_dirs, exclude_tests):
profile_globals = {"test_dirs": test_dirs, "exclude_tests": exclude_tests}
exec(profile_file.read(), profile_globals)
return profile_globals["test_dirs"], profile_globals["exclude_tests"]
return flatten_iterable(profile_globals["test_dirs"]), flatten_iterable(
profile_globals["exclude_tests"]
)


test_function = (
Expand Down Expand Up @@ -127,8 +141,10 @@ def load_profile(profile_file, test_dirs, exclude_tests):
test_dirs, exclude_tests = load_profile(args.profile, test_dirs, exclude_tests)
if args.exclude:
exclude_tests = exclude_tests.union(args.exclude)
for group in test_dirs:
tests += [test for test in glob("{}/*.py".format(group)) if test not in exclude_tests]
for group in sorted(test_dirs):
tests += [
test for test in sorted(glob("{}/*.py".format(group))) if test not in exclude_tests
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be a lot simpler to just do tests.sort() after this for loop? Then there's no need to flatten anything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agatti any thought about using sort() to keep this simple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay, this fell off my radar. The reason for the list flattening was to prevent potential user error, as it was not obvious the tests exclusion list is a set and not an array of sorts.

If that's not a concern I can sort the final list without pre-flattening the input as you suggest.

else:
for l in sys.stdin:
tests.append(l.rstrip())
Expand Down