Completed
Pull Request — master (#34)
by
unknown
01:30
created

tests.test_parse_columns()   A

Complexity

Conditions 4

Size

Total Lines 5

Duplication

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