aboutsummaryrefslogtreecommitdiff
path: root/tests/test_utils.py
blob: 2ced6bba289fc5f36c965abd5b6258afb7dc4003 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import pytest
from delivery_merge import utils


KEYPAIRS = """FOO=FOO
FEED=FEED
FACE=FACE

moo=moo
meow=meow

"""


class TestUtils:
    def setup_class(self):
        pass

    def teardown_class(self):
        pass

    def test_sh(self):
        result = utils.sh('echo', 'testing').stdout.decode().strip()
        assert result == 'testing'

    def test_sh_variadic(self):
        result = utils.sh('echo',
                          'testing', '1', '2', '3').stdout.decode().strip()
        assert result == 'testing 1 2 3'

    def test_git_alive(self):
        assert utils.git('--version').stdout.decode().strip()

    def test_getenv(self):
        result = utils.getenv(KEYPAIRS)
        assert isinstance(result, dict)
        for k, v in result.items():
            assert k == v

    def test_getenv_multi_equal(self):
        result = utils.getenv("INFINITE_FUN=LINE=10")
        assert result.get('INFINITE_FUN') == 'LINE=10'

    def test_pushd(self):
        orig_path = os.path.abspath('.')
        d = os.path.join(orig_path, 'pushd_test')

        if not os.path.exists(d):
            os.mkdir(d)

        with utils.pushd(d):
           new_path = os.path.abspath('.')
           assert new_path == os.path.join(orig_path, d)

        assert os.path.abspath('.') == orig_path