added invalid tests

main
Paco Hope 2022-08-13 16:03:43 -04:00
parent 3d528f85cb
commit d019601298
4 changed files with 40 additions and 7 deletions

View File

@ -0,0 +1,6 @@
# comment
heavy:
mouse2:
snort: attack
'e':
giggle: attack

View File

@ -0,0 +1,6 @@
# comment
heavy:
mouse8:
hold: attack
blarg:
toggle: attack

View File

@ -1,6 +1,6 @@
"""
Tests that we can import and execute the most basic valid test file.
Uses: tests/validYAML.yaml
Uses: tests/basic_test.yaml
"""
import pytest
import tfscript.cli
@ -10,21 +10,21 @@ class TestCLI:
def test_debug_opt(self):
"""Is debug argument available?"""
with ArgvContext('tfscript', '-d', 'tests/validYAML.yaml'):
with ArgvContext('tfscript', '-d', 'tests/basic_test.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'):
with ArgvContext('tfscript', '-n', 'tests/basic_test.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'):
with ArgvContext('tfscript', '--directory', '.', 'tests/basic_test.yaml'):
parser = tfscript.cli.parseCLI()
args = parser.parse_args()
assert args.directory == '.'

View File

@ -1,15 +1,36 @@
"""
Tests that we can import and execute the most basic valid test file.
Uses: tests/validYAML.yaml
Uses: tests/basic_test.yaml
tests/mega.yaml
"""
import pytest
import tfscript.cli
import os
from cli_test_helpers import ArgvContext, shell
class TestValidYaml:
def test_parseValidFile(self, tmp_path):
def test_parseValidFile(self, tmp_path, capsys):
"""Parse the basic test file."""
with capsys.disabled():
print(os.linesep + "Basic test output in {}".format(str(tmp_path)))
with ArgvContext('tfscript', '--directory', str(tmp_path),
'-d', 'tests/validYAML.yaml'):
'-d', 'tests/basic_test.yaml'):
tfscript.cli.main()
def test_megabyteYamlFile(self, tmp_path, capsys):
"""Parse the test file that produces multi-megabyte output."""
with capsys.disabled():
print(os.linesep + "Multi-megabyte test output in {}".format(str(tmp_path)))
with ArgvContext('tfscript', '--directory', str(tmp_path),
'-d', 'tests/basic_test.yaml'):
tfscript.cli.main()
def test_invalidKeyBind(self):
"""Test handling of invalid YAML exception. Doesn't capture output."""
with ArgvContext('tfscript', 'tests/invalid_keybind.yaml'):
with pytest.raises(SystemExit):
tfscript.cli.main()
pytest.fail("Should abort without positional filename argument")