diff --git a/.gitignore b/.gitignore index 9bdd69e..901668c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .idea .cache /.pypirc +/.tox/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0740785 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +tox-pyenv +pytest +tox \ No newline at end of file diff --git a/test/test_terraform.py b/test/test_terraform.py index d5a9c83..a1d0cfb 100644 --- a/test/test_terraform.py +++ b/test/test_terraform.py @@ -5,7 +5,7 @@ import logging import re logging.basicConfig(level=logging.WARN) - +current_path = os.path.dirname(os.path.realpath(__file__)) STRING_CASES = [ [ @@ -61,28 +61,40 @@ class TestTerraform: @pytest.mark.parametrize(*CMD_CASES) def test_cmd(self, method, expected_output): - tf = Terraform() + tf = Terraform(working_dir=current_path) ret, out, err = method(tf) assert expected_output in out assert ret == 0 def test_state_data(self): - tf = Terraform(working_dir='test_tfstate_file', state='tfstate.test') + cwd = os.path.join(current_path, 'test_tfstate_file') + tf = Terraform(working_dir=cwd, state='tfstate.test') tf.read_state_file() assert tf.tfstate.modules[0]['path'] == ['root'] def test_apply(self): - tf = Terraform(working_dir='apply_tf', variables={'test_var': 'test'}) + cwd = os.path.join(current_path, 'apply_tf') + tf = Terraform(working_dir=cwd, variables={'test_var': 'test'}) ret, out, err = tf.apply(var={'test_var': 'test2'}) assert ret == 0 + def test_override_no_color(self): + cwd = os.path.join(current_path, 'apply_tf') + tf = Terraform(working_dir=cwd, variables={'test_var': 'test'}) + ret, out, err = tf.apply(var={'test_var': 'test2'}, + no_color=IsNotFlagged) + out = out.replace('\n', '') + assert '\x1b[0m\x1b[1m\x1b[32mApply' in out + def test_get_output(self): - tf = Terraform(working_dir='apply_tf', variables={'test_var': 'test'}) + cwd = os.path.join(current_path, 'apply_tf') + tf = Terraform(working_dir=cwd, variables={'test_var': 'test'}) tf.apply() assert tf.output('test_output') == 'test' def test_destroy(self): - tf = Terraform(working_dir='apply_tf', variables={'test_var': 'test'}) + cwd = os.path.join(current_path, 'apply_tf') + tf = Terraform(working_dir=cwd, variables={'test_var': 'test'}) ret, out, err = tf.destroy() assert ret == 0 assert 'Destroy complete! Resources: 0 destroyed.' in out diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..bdd1854 --- /dev/null +++ b/tox.ini @@ -0,0 +1,6 @@ +# content of: tox.ini , put in same dir as setup.py +[tox] +envlist = py27, py3 +[testenv] +deps=pytest +commands=py.test test \ No newline at end of file