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

BUG: handle setup_cache correctly in asv check #787

Merged
merged 1 commit into from
May 13, 2019
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
26 changes: 17 additions & 9 deletions asv/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ def _get_sourceline_info(obj, basedir):
return ""


def check_num_args(root, benchmark_name, func, num_args):
def check_num_args(root, benchmark_name, func, min_num_args, max_num_args=None):
if max_num_args is None:
max_num_args = min_num_args

try:
if sys.version_info[0] >= 3:
info = inspect.getfullargspec(func)
Expand All @@ -382,15 +385,19 @@ def check_num_args(root, benchmark_name, func, num_args):
if info.varargs is not None:
max_args = float('inf')

ok = min_args <= num_args <= max_args
ok = (min_args <= max_num_args) and (min_num_args <= max_args)
if not ok:
if min_args == max_args:
args_str = min_args
else:
args_str = "{}-{}".format(min_args, max_args)
if min_num_args == max_num_args:
num_args_str = min_num_args
else:
num_args_str = "{}-{}".format(min_num_args, max_num_args)
print("{!s}: wrong number of arguments (for {!r}{!s}): expected {}, has {}".format(
benchmark_name, func, _get_sourceline_info(func, root),
num_args, args_str))
num_args_str, args_str))

return ok

Expand Down Expand Up @@ -481,23 +488,24 @@ def check(self, root):
if self._params:
self.set_param_idx(0)

min_num_args = len(self._current_params)
max_num_args = min_num_args

if self.setup_cache_key is not None:
self.insert_param(None)
ok = ok and check_num_args(root, self.name + ": setup_cache",
self._setup_cache, 0)

num_args = len(self._current_params)
max_num_args += 1

for setup in self._setups:
ok = ok and check_num_args(root, self.name + ": setup",
setup, num_args)
setup, min_num_args, max_num_args)

ok = ok and check_num_args(root, self.name + ": call",
self.func, num_args)
self.func, min_num_args, max_num_args)

for teardown in self._teardowns:
ok = ok and check_num_args(root, self.name + ": teardown",
teardown, num_args)
teardown, min_num_args, max_num_args)

return ok

Expand Down
1 change: 0 additions & 1 deletion test/benchmark/cache_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ def time_fail_second_run(data):
time_fail_second_run.repeat = 1
time_fail_second_run.warmup_time = 0
time_fail_second_run.processes = 2

6 changes: 6 additions & 0 deletions test/benchmark/params_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ def track_bytes():
return 1000000

track_bytes.unit = "bytes"


def track_wrong_number_of_args(a, b):
return 0

track_wrong_number_of_args.params = [[1, 2]]
4 changes: 2 additions & 2 deletions test/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_discover_benchmarks(benchmarks_fixture):
b = benchmarks.Benchmarks.discover(conf, repo, envs, [commit_hash],
regex='example')
conf.branches = old_branches
assert len(b) == 29
assert len(b) == 30

b = benchmarks.Benchmarks.discover(conf, repo, envs, [commit_hash],
regex='time_example_benchmark_1')
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_discover_benchmarks(benchmarks_fixture):
assert b._benchmark_selection['params_examples.track_param_selection'] == [0, 1, 2, 3]

b = benchmarks.Benchmarks.discover(conf, repo, envs, [commit_hash])
assert len(b) == 40
assert len(b) == 41

assert 'named.OtherSuite.track_some_func' in b

Expand Down
3 changes: 2 additions & 1 deletion test/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ def test_check(capsys, basic_conf):

text, err = capsys.readouterr()

assert re.search(r"cache_examples\.[A-Za-z]+\.track_[a-z]+: call: wrong number of arguments", text)
assert re.search(r"params_examples\.track_wrong_number_of_args: call: "
r"wrong number of arguments.*: expected 1, has 2", text)
assert text.count("wrong number of arguments") == 1