From f6e8e579818c3e6b9708e4d236bcabc6fa2ee397 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 May 2019 13:48:16 -0400 Subject: Initial commit of utils tests --- tests/test_utils.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/test_utils.py diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..2ced6bb --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,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 -- cgit