benchmarks root must be subdir of tests root

This commit is contained in:
Alvin Ryanputra 2025-04-01 10:53:14 -07:00
parent 0937329d38
commit ed8f5efcad
3 changed files with 55 additions and 44 deletions

View file

@ -1,18 +1,18 @@
# import unittest
#
# from code_to_optimize.bubble_sort import sorter
#
#
# class TestPigLatin(unittest.TestCase):
# def test_sort(self):
# input = [5, 4, 3, 2, 1, 0]
# output = sorter(input)
# self.assertEqual(output, [0, 1, 2, 3, 4, 5])
#
# input = [5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
# output = sorter(input)
# self.assertEqual(output, [0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
#
# input = list(reversed(range(5000)))
# output = sorter(input)
# self.assertEqual(output, list(range(5000)))
import unittest
from code_to_optimize.bubble_sort import sorter
class TestPigLatin(unittest.TestCase):
def test_sort(self):
input = [5, 4, 3, 2, 1, 0]
output = sorter(input)
self.assertEqual(output, [0, 1, 2, 3, 4, 5])
input = [5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
output = sorter(input)
self.assertEqual(output, [0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
input = list(reversed(range(5000)))
output = sorter(input)
self.assertEqual(output, list(range(5000)))

View file

@ -1,18 +1,18 @@
# import unittest
#
# from parameterized import parameterized
#
# from code_to_optimize.bubble_sort import sorter
#
#
# class TestPigLatin(unittest.TestCase):
# @parameterized.expand(
# [
# ([5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5]),
# ([5.0, 4.0, 3.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]),
# (list(reversed(range(50))), list(range(50))),
# ]
# )
# def test_sort(self, input, expected_output):
# output = sorter(input)
# self.assertEqual(output, expected_output)
import unittest
from parameterized import parameterized
from code_to_optimize.bubble_sort import sorter
class TestPigLatin(unittest.TestCase):
@parameterized.expand(
[
([5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5]),
([5.0, 4.0, 3.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]),
(list(reversed(range(50))), list(range(50))),
]
)
def test_sort(self, input, expected_output):
output = sorter(input)
self.assertEqual(output, expected_output)

View file

@ -135,14 +135,25 @@ def process_pyproject_config(args: Namespace) -> Namespace:
if args.benchmark:
assert args.benchmarks_root is not None, "--benchmarks-root must be specified when running with --benchmark"
assert Path(args.benchmarks_root).is_dir(), f"--benchmarks-root {args.benchmarks_root} must be a valid directory"
assert not (env_utils.get_pr_number() is not None and not env_utils.ensure_codeflash_api_key()), (
"Codeflash API key not found. When running in a Github Actions Context, provide the "
"'CODEFLASH_API_KEY' environment variable as a secret.\n"
"You can add a secret by going to your repository's settings page, then clicking 'Secrets' in the left sidebar.\n"
"Then, click 'New repository secret' and add your api key with the variable name CODEFLASH_API_KEY.\n"
f"Here's a direct link: {get_github_secrets_page_url()}\n"
"Exiting..."
)
assert Path(args.benchmarks_root).is_relative_to(Path(args.tests_root)), (
f"--benchmarks-root {args.benchmarks_root} must be a subdirectory of --tests-root {args.tests_root}"
)
if env_utils.get_pr_number() is not None:
assert env_utils.ensure_codeflash_api_key(), (
"Codeflash API key not found. When running in a Github Actions Context, provide the "
"'CODEFLASH_API_KEY' environment variable as a secret.\n"
"You can add a secret by going to your repository's settings page, then clicking 'Secrets' in the left sidebar.\n"
"Then, click 'New repository secret' and add your api key with the variable name CODEFLASH_API_KEY.\n"
f"Here's a direct link: {get_github_secrets_page_url()}\n"
"Exiting..."
)
repo = git.Repo(search_parent_directories=True)
owner, repo_name = get_repo_owner_and_name(repo)
require_github_app_or_exit(owner, repo_name)
if hasattr(args, "ignore_paths") and args.ignore_paths is not None:
normalized_ignore_paths = []
for path in args.ignore_paths: