Skip to content

Commit

Permalink
Merge pull request #325 from pv/fix-find
Browse files Browse the repository at this point in the history
Fix argument parsing in Find + ensure such bugs don't arise again
  • Loading branch information
mdboom committed Sep 27, 2015
2 parents db5abe3 + 77339dc commit bd4539b
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 67 deletions.
5 changes: 3 additions & 2 deletions asv/commands/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ def setup_arguments(cls, subparsers):
return parser

@classmethod
def run_from_conf_args(cls, conf, args):
def run_from_conf_args(cls, conf, args, **kwargs):
return cls.run(
conf=conf, branch=args.branch, base=args.base, factor=args.factor,
show_stderr=args.show_stderr, bench=args.bench, machine=args.machine
show_stderr=args.show_stderr, bench=args.bench, machine=args.machine,
**kwargs
)

@classmethod
Expand Down
5 changes: 3 additions & 2 deletions asv/commands/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def setup_arguments(cls, subparsers):
return parser

@classmethod
def run_from_conf_args(cls, conf, args):
return cls.run(conf, bench=args.bench, machine=args.machine, python=args.python)
def run_from_conf_args(cls, conf, args, **kwargs):
return cls.run(conf, bench=args.bench, machine=args.machine, python=args.python,
**kwargs)

@classmethod
def run(cls, conf, bench=None, python="same", machine=None, _machine_file=None):
Expand Down
6 changes: 3 additions & 3 deletions asv/commands/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def setup_arguments(cls, subparsers):
return parser

@classmethod
def run_from_conf_args(cls, conf, args):
def run_from_conf_args(cls, conf, args, **kwargs):
return cls.run(
conf, args.range[0], args.bench[0],
conf, args.range, args.bench,
invert=args.invert, show_stderr=args.show_stderr,
machine=args.machine
machine=args.machine, **kwargs
)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions asv/commands/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def find_guis(cls):
cls.guis[x.name] = x

@classmethod
def run_from_conf_args(cls, conf, args):
def run_from_conf_args(cls, conf, args, **kwargs):
return cls.run(
conf=conf, benchmark=args.benchmark, revision=args.revision,
gui=args.gui, output=args.output, force=args.force,
environment=args.environment, python=args.python)
environment=args.environment, python=args.python, **kwargs)

@classmethod
def run(cls, conf, benchmark, revision=None, gui=None, output=None,
Expand Down
5 changes: 3 additions & 2 deletions asv/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def setup_arguments(cls, subparsers):
return parser

@classmethod
def run_from_conf_args(cls, conf, args):
def run_from_conf_args(cls, conf, args, **kwargs):
return cls.run(
conf=conf, range_spec=args.range, steps=args.steps,
bench=args.bench, parallel=args.parallel,
Expand All @@ -119,7 +119,8 @@ def run_from_conf_args(cls, conf, args):
dry_run=args.dry_run, machine=args.machine,
skip_successful=args.skip_existing_successful or args.skip_existing,
skip_failed=args.skip_existing_failed or args.skip_existing,
skip_existing_commits=args.skip_existing_commits
skip_existing_commits=args.skip_existing_commits,
**kwargs
)

@classmethod
Expand Down
6 changes: 4 additions & 2 deletions asv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,10 @@ def write_json(path, data, api_version=None):
Writes JSON to the given path, including indentation and sorting.
"""
path = os.path.abspath(path)
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))

dirname = long_path(os.path.dirname(path))
if not os.path.exists(dirname):
os.makedirs(dirname)

if api_version is not None:
data['version'] = api_version
Expand Down
5 changes: 2 additions & 3 deletions test/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ def test_compare(capsys, tmpdir):
'repo': tools.generate_test_repo(tmpdir).path,
'project': 'asv'})

mock_args = Namespace(revision1='22b920c6', revision2='fcf8c079', machine='cheetah',
factor=2, split=False)
Compare.run_from_conf_args(conf, mock_args)
tools.run_asv_with_conf(conf, 'compare', '22b920c6', 'fcf8c079', '--machine=cheetah',
'--factor=2')

text, err = capsys.readouterr()
assert text.strip() == REFERENCE.strip()
Expand Down
12 changes: 4 additions & 8 deletions test/test_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import six

from asv import config
from asv.commands.dev import Dev
from asv.commands.profiling import Profile
from asv.commands.run import Run
from asv.commands import make_argparser

from . import tools
Expand Down Expand Up @@ -56,7 +53,7 @@ def test_dev(capsys, basic_conf):
tmpdir, local, conf = basic_conf

# Test Dev runs
Dev.run(conf, _machine_file=join(tmpdir, 'asv-machine.json'))
tools.run_asv_with_conf(conf, 'dev', _machine_file=join(tmpdir, 'asv-machine.json'))
text, err = capsys.readouterr()

# time_with_warnings failure case
Expand All @@ -72,7 +69,7 @@ def test_run_python_same(capsys, basic_conf):
tmpdir, local, conf = basic_conf

# Test Run runs with python=same
Run.run(conf, _machine_file=join(tmpdir, 'asv-machine.json'), python="same")
tools.run_asv_with_conf(conf, 'run', '--python=same', _machine_file=join(tmpdir, 'asv-machine.json'))
text, err = capsys.readouterr()

assert re.search("time_exception.*failed", text, re.S)
Expand All @@ -87,9 +84,8 @@ def test_profile_python_same(capsys, basic_conf):
tmpdir, local, conf = basic_conf

# Test Profile can run with python=same
Profile.run(conf, "time_secondary.track_value",
_machine_file=join(tmpdir, 'asv-machine.json'),
python="same")
tools.run_asv_with_conf(conf, 'profile', '--python=same', "time_secondary.track_value",
_machine_file=join(tmpdir, 'asv-machine.json'))
text, err = capsys.readouterr()

# time_with_warnings failure case
Expand Down
4 changes: 2 additions & 2 deletions test/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_publish(tmpdir):
'repo': dvcs.path,
'project': 'asv'})

Publish.run(conf)
tools.run_asv_with_conf(conf, 'publish')

# Check output
assert isfile(join(tmpdir, 'html', 'index.html'))
Expand Down Expand Up @@ -98,7 +98,7 @@ def check_file(branch):

# Publish with branches set in the config
conf.branches = ['master', 'some-branch']
Publish.run(conf)
tools.run_asv_with_conf(conf, 'publish')

# Check output
check_file("master")
Expand Down
5 changes: 3 additions & 2 deletions test/test_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

from os.path import isfile, join

import os
import six

from asv.commands.quickstart import Quickstart
from . import tools


def test_quickstart(tmpdir):
tmpdir = six.text_type(tmpdir)

Quickstart.run(tmpdir)
tools.run_asv('quickstart', '--dest', tmpdir)

assert isfile(join(tmpdir, 'asv.conf.json'))
assert isfile(join(tmpdir, 'benchmarks', 'benchmarks.py'))
7 changes: 4 additions & 3 deletions test/test_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from asv import config
from asv import results
from asv.commands.rm import Rm

from . import tools


def test_rm(tmpdir):
Expand All @@ -26,14 +27,14 @@ def test_rm(tmpdir):
'repo': "### IGNORED, BUT REQUIRED ###"
})

Rm.run(conf, ['benchmark=time_quantity*'])
tools.run_asv_with_conf(conf, 'rm', '-y', 'benchmark=time_quantity*')

results_a = list(results.iter_results(tmpdir))
for result in results_a:
for key in six.iterkeys(result.results):
assert not key.startswith('time_quantity')

Rm.run(conf, ['commit_hash=05d283b9'])
tools.run_asv_with_conf(conf, 'rm', '-y', 'commit_hash=05d283b9')

results_b = list(results.iter_results(tmpdir))
assert len(results_b) == len(results_a) - 1
16 changes: 7 additions & 9 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
import pytest

from asv import config
from asv.commands.run import Run
from asv.commands.publish import Publish

from . import tools
from .tools import browser, get_with_retry
from .test_workflow import basic_conf


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -55,9 +52,9 @@ def basic_html(request):
}
})

Run.run(conf, range_spec="master~5..master", steps=3,
_machine_file=machine_file, quick=True)
Publish.run(conf)
tools.run_asv_with_conf(conf, 'run', "master~5..master", '--steps=3',
'--quick', _machine_file=machine_file)
tools.run_asv_with_conf(conf, 'publish')
finally:
os.chdir(cwd)

Expand Down Expand Up @@ -131,9 +128,10 @@ def test_web_regressions(browser, tmpdir):
},
})

Run.run(conf, range_spec="ALL", bench='params_examples.track_find_test',
_machine_file=machine_file, show_stderr=True, quick=True)
Publish.run(conf)
tools.run_asv_with_conf(conf, 'run', 'ALL', '--bench=params_examples.track_find_test',
'--show-stderr', '--quick',
_machine_file=machine_file)
tools.run_asv_with_conf(conf, 'publish')
finally:
os.chdir(cwd)

Expand Down
50 changes: 25 additions & 25 deletions test/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
import pytest

from asv import config
from asv.commands.run import Run
from asv.commands.publish import Publish
from asv.commands.find import Find
from asv.commands.continuous import Continuous
from asv.util import check_output, which

from . import tools
Expand Down Expand Up @@ -80,15 +76,16 @@ def test_run_publish(capfd, basic_conf):
tmpdir, local, conf, machine_file = basic_conf

# Tests a typical complete run/publish workflow
Run.run(conf, range_spec="master~5..master", steps=2,
_machine_file=machine_file, quick=True, show_stderr=True)
tools.run_asv_with_conf(conf, 'run', "master~5..master", '--steps=2',
'--quick', '--show-stderr',
_machine_file=machine_file)
text, err = capfd.readouterr()

assert len(os.listdir(join(tmpdir, 'results_workflow', 'orangutan'))) == 5
assert len(os.listdir(join(tmpdir, 'results_workflow'))) == 2
assert 'asv: benchmark timed out (timeout 0.1s)' in text

Publish.run(conf)
tools.run_asv_with_conf(conf, 'publish')

assert isfile(join(tmpdir, 'html', 'index.html'))
assert isfile(join(tmpdir, 'html', 'index.json'))
Expand All @@ -112,32 +109,34 @@ def test_run_publish(capfd, basic_conf):

# Check that the skip options work
capfd.readouterr()
Run.run(conf, range_spec="master~5..master", steps=2,
_machine_file=join(tmpdir, 'asv-machine.json'), quick=True,
skip_successful=True, skip_failed=True)
Run.run(conf, range_spec="master~5..master", steps=2,
_machine_file=join(tmpdir, 'asv-machine.json'), quick=True,
skip_existing_commits=True)
tools.run_asv_with_conf(conf, 'run', "master~5..master", '--steps=2',
'--quick', '--skip-existing-successful',
'--skip-existing-failed',
_machine_file=join(tmpdir, 'asv-machine.json'))
tools.run_asv_with_conf(conf, 'run', "master~5..master", '--steps=2',
'--quick', '--skip-existing-commits',
_machine_file=join(tmpdir, 'asv-machine.json'))
text, err = capfd.readouterr()
assert 'Running benchmarks.' not in text

# Check EXISTING works
Run.run(conf, range_spec="EXISTING",
_machine_file=machine_file, quick=True)
tools.run_asv_with_conf(conf, 'run', "EXISTING", '--quick',
_machine_file=machine_file)

# Remove the benchmarks.json file to make sure publish can
# regenerate it

os.remove(join(tmpdir, "results_workflow", "benchmarks.json"))

Publish.run(conf)
tools.run_asv_with_conf(conf, 'publish')


def test_continuous(capfd, basic_conf):
tmpdir, local, conf, machine_file = basic_conf

# Check that asv continuous runs
Continuous.run(conf, branch="master^", _machine_file=machine_file, show_stderr=True)
tools.run_asv_with_conf(conf, 'continuous', "master^", '--show-stderr',
_machine_file=machine_file)

text, err = capfd.readouterr()
assert "SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY" in text
Expand All @@ -155,8 +154,8 @@ def test_find(capfd, basic_conf):
"from py.test runner.")

# Test find at least runs
Find.run(conf, "master~5..master", "params_examples.track_find_test",
_machine_file=machine_file)
tools.run_asv_with_conf(conf, 'find', "master~5..master", "params_examples.track_find_test",
_machine_file=machine_file)

# Check it found the first commit after the initially tested one
output, err = capfd.readouterr()
Expand All @@ -175,8 +174,8 @@ def _test_run_branches(tmpdir, dvcs, conf, machine_file, range_spec,
commits.append(dvcs.get_hash(branch))

# Run tests
Run.run(conf, range_spec=range_spec,
_machine_file=machine_file, quick=True)
tools.run_asv_with_conf(conf, 'run', range_spec, '--quick',
_machine_file=machine_file)

# Check that files for all commits expected were generated
expected = set(['machine.json'])
Expand Down Expand Up @@ -211,10 +210,11 @@ def init_results():
results_dir = os.path.join(tmpdir, 'results_workflow')
if os.path.isdir(results_dir):
shutil.rmtree(results_dir)
Run.run(conf, range_spec=initial_commit+"^!",
bench=["time_secondary.track_value"],
_machine_file=join(tmpdir, 'asv-machine.json'), quick=True,
skip_successful=True, skip_failed=True)
tools.run_asv_with_conf(conf, 'run', initial_commit+"^!",
'--bench=time_secondary.track_value',
'--quick', '--skip-existing-successful',
'--skip-existing-failed',
_machine_file=join(tmpdir, 'asv-machine.json'))

# Without branches in config, should just use master
init_results()
Expand Down
Loading

0 comments on commit bd4539b

Please sign in to comment.