1
|
|
|
import distutils.spawn |
2
|
|
|
import subprocess |
3
|
|
|
import argparse |
4
|
|
|
|
5
|
|
|
import pytest |
6
|
|
|
from pytest import mark |
7
|
|
|
|
8
|
|
|
from pytest_benchmark.utils import clonefunc |
9
|
|
|
from pytest_benchmark.utils import get_commit_info |
10
|
|
|
from pytest_benchmark.utils import parse_warmup |
11
|
|
|
from pytest_benchmark.utils import parse_columns |
12
|
|
|
|
13
|
|
|
pytest_plugins = 'pytester', |
14
|
|
|
|
15
|
|
|
f1 = lambda a: a |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
def f2(a): |
19
|
|
|
return a |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
@mark.parametrize('f', [f1, f2]) |
23
|
|
|
def test_clonefunc(f): |
24
|
|
|
assert clonefunc(f)(1) == f(1) |
25
|
|
|
assert clonefunc(f)(1) == f(1) |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
def test_clonefunc_not_function(): |
29
|
|
|
assert clonefunc(1) == 1 |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
@mark.parametrize('scm', ['git', 'hg']) |
33
|
|
|
def test_get_commit_info(scm, testdir): |
34
|
|
|
if not distutils.spawn.find_executable(scm): |
35
|
|
|
pytest.skip("%r not availabe on $PATH") |
36
|
|
|
subprocess.check_call([scm, 'init', '.']) |
37
|
|
|
if scm == 'git': |
38
|
|
|
subprocess.check_call('git config user.email [email protected]'.split()) |
39
|
|
|
subprocess.check_call('git config user.name you'.split()) |
40
|
|
|
else: |
41
|
|
|
testdir.tmpdir.join('.hg', 'hgrc').write(""" |
42
|
|
|
[ui] |
43
|
|
|
username = you <[email protected]> |
44
|
|
|
""") |
45
|
|
|
|
46
|
|
|
testdir.makepyfile('asdf') |
47
|
|
|
subprocess.check_call([scm, 'add', 'test_get_commit_info.py']) |
48
|
|
|
subprocess.check_call([scm, 'commit', '-m', 'asdf']) |
49
|
|
|
out = get_commit_info() |
50
|
|
|
|
51
|
|
|
assert out.get('dirty') == False |
52
|
|
|
assert 'id' in out |
53
|
|
|
|
54
|
|
|
testdir.makepyfile('sadf') |
55
|
|
|
out = get_commit_info() |
56
|
|
|
|
57
|
|
|
assert out.get('dirty') == True |
58
|
|
|
assert 'id' in out |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
def test_parse_warmup(): |
62
|
|
|
assert parse_warmup('yes') == True |
63
|
|
|
assert parse_warmup('on') == True |
64
|
|
|
assert parse_warmup('true') == True |
65
|
|
|
assert parse_warmup('off') == False |
66
|
|
|
assert parse_warmup('off') == False |
67
|
|
|
assert parse_warmup('no') == False |
68
|
|
|
assert parse_warmup('') == True |
69
|
|
|
assert parse_warmup('auto') in [True, False] |
70
|
|
|
|
71
|
|
|
def test_parse_columns(): |
72
|
|
|
assert parse_columns('min,max') == ['min', 'max'] |
73
|
|
|
assert parse_columns('MIN, max ') == ['min', 'max'] |
74
|
|
|
with pytest.raises(argparse.ArgumentTypeError): |
75
|
|
|
parse_columns('min,max,x') |
76
|
|
|
|