Merge pull request 'Basic implementation of `pytest`' (#11) from add-tests into main
Reviewed-on: #11main
commit
6c13802d17
|
@ -9,6 +9,7 @@ cfg/*
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
.venv
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
|
@ -2,3 +2,5 @@ pyyaml
|
||||||
argparse
|
argparse
|
||||||
pylint
|
pylint
|
||||||
build
|
build
|
||||||
|
pytest
|
||||||
|
cli_test_helpers
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
"""
|
||||||
|
Tests that we can import and execute the most basic valid test file.
|
||||||
|
Uses: tests/validYAML.yaml
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
import tfscript.cli
|
||||||
|
from cli_test_helpers import ArgvContext, shell
|
||||||
|
|
||||||
|
class TestCLI:
|
||||||
|
|
||||||
|
def test_debug_opt(self):
|
||||||
|
"""Is debug argument available?"""
|
||||||
|
with ArgvContext('tfscript', '-d', 'tests/validYAML.yaml'):
|
||||||
|
parser = tfscript.cli.parseCLI()
|
||||||
|
args = parser.parse_args()
|
||||||
|
assert args.debug == True
|
||||||
|
|
||||||
|
def test_dry_run_opt(self):
|
||||||
|
"""Is dry-run argument available?"""
|
||||||
|
with ArgvContext('tfscript', '-n', 'tests/validYAML.yaml'):
|
||||||
|
parser = tfscript.cli.parseCLI()
|
||||||
|
args = parser.parse_args()
|
||||||
|
assert args.dry_run == True
|
||||||
|
|
||||||
|
def test_directory_opt(self):
|
||||||
|
"""Use . because it's sure to exist on all platforms."""
|
||||||
|
with ArgvContext('tfscript', '--directory', '.', 'tests/validYAML.yaml'):
|
||||||
|
parser = tfscript.cli.parseCLI()
|
||||||
|
args = parser.parse_args()
|
||||||
|
assert args.directory == '.'
|
||||||
|
|
||||||
|
def test_cli(self):
|
||||||
|
"""
|
||||||
|
Does CLI stop execution w/o a filename positional argument?
|
||||||
|
"""
|
||||||
|
with pytest.raises(SystemExit):
|
||||||
|
tfscript.cli.main()
|
||||||
|
pytest.fail("Should abort without positional filename argument")
|
|
@ -0,0 +1,15 @@
|
||||||
|
"""
|
||||||
|
Tests that we can import and execute the most basic valid test file.
|
||||||
|
Uses: tests/validYAML.yaml
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
import tfscript.cli
|
||||||
|
from cli_test_helpers import ArgvContext, shell
|
||||||
|
|
||||||
|
class TestValidYaml:
|
||||||
|
|
||||||
|
def test_parseValidFile(self, tmp_path):
|
||||||
|
"""Parse the basic test file."""
|
||||||
|
with ArgvContext('tfscript', '--directory', str(tmp_path),
|
||||||
|
'-d', 'tests/validYAML.yaml'):
|
||||||
|
tfscript.cli.main()
|
Loading…
Reference in New Issue