Completed
Pull Request — develop (#14)
by Jace
01:56
created

describe_get_version()   A

Complexity

Conditions 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
# -*- coding: utf-8 -*-
2
3
# pylint: disable=unused-variable,unused-argument,expression-not-assigned
4
5
from __future__ import unicode_literals
6
7
import pytest
0 ignored issues
show
Configuration introduced by
The import pytest could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
8
from expecter import expect
0 ignored issues
show
Configuration introduced by
The import expecter could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
9
10
from verchew.script import find_config, parse_config, get_version, _
11
12
13
def describe_find_config():
14
15
    @pytest.fixture
16
    def config(tmpdir):
17
        tmpdir.chdir()
18
        path = tmpdir.join("foo.bar")
19
        path.write("")
20
        return path
21
22
    def when_missing(config):
23
        with expect.raises(RuntimeError):
24
            find_config()
25
26
    def when_found(config):
27
        path = find_config(config_filenames=["foo.bar"])
28
29
        expect(path) == config
30
31
32
def describe_parse_config():
33
34
    @pytest.fixture
35
    def config(tmpdir):
36
        tmpdir.chdir()
37
        path = tmpdir.join("verchew.ini")
38
        path.write("")
39
        return path
40
41
    def with_no_content(config):
42
        config.write("")
43
44
        expect(parse_config(str(config))) == {}
45
46
    def with_an_empty_section(config):
47
        config.write("""
48
        [Foobar]
49
        """.replace(' ' * 8, ''))
50
51
        expect(parse_config(str(config))) == {
52
            'Foobar': {},
53
        }
54
55
    def with_a_filled_section(config):
56
        config.write("""
57
        [Foobar]
58
59
        cli = foobar
60
        version = v1.2.3
61
        """.replace(' ' * 8, ''))
62
63
        expect(parse_config(str(config))) == {
64
            'Foobar': {
65
                'cli': 'foobar',
66
                'version': 'v1.2.3',
67
            },
68
        }
69
70
71
def describe_get_version():
72
73
    def when_missing():
74
        expect(get_version('foobar')) == "sh: command not found: foobar"
75
76
    def when_found():
77
        expect(get_version('python')).contains("Python ")
78
79
80
def describe_format():
81
82
    def when_utf8():
83
        expect(_('~', utf8=True)) == "✔"
84
85
    def when_tty():
86
        expect(_('~', tty=True)) == "\033[92m~\033[0m"
87
88
    def when_utf8_and_tty():
89
        expect(_('~', utf8=True, tty=True)) == "\033[92m✔\033[0m"
90