From d0196012981c63b460813c2d518a6f3e98033a6a Mon Sep 17 00:00:00 2001 From: Paco Hope Date: Sat, 13 Aug 2022 16:03:43 -0400 Subject: [PATCH] added invalid tests --- tests/invalid_action.yaml | 6 ++++++ tests/invalid_keybind.yaml | 6 ++++++ tests/test_cli.py | 8 ++++---- tests/test_valid_yaml.py | 27 ++++++++++++++++++++++++--- 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tests/invalid_action.yaml create mode 100644 tests/invalid_keybind.yaml diff --git a/tests/invalid_action.yaml b/tests/invalid_action.yaml new file mode 100644 index 0000000..3b2d4e9 --- /dev/null +++ b/tests/invalid_action.yaml @@ -0,0 +1,6 @@ +# comment +heavy: + mouse2: + snort: attack + 'e': + giggle: attack diff --git a/tests/invalid_keybind.yaml b/tests/invalid_keybind.yaml new file mode 100644 index 0000000..d127332 --- /dev/null +++ b/tests/invalid_keybind.yaml @@ -0,0 +1,6 @@ +# comment +heavy: + mouse8: + hold: attack + blarg: + toggle: attack diff --git a/tests/test_cli.py b/tests/test_cli.py index 3f68015..19f187a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 == '.' diff --git a/tests/test_valid_yaml.py b/tests/test_valid_yaml.py index b187722..bcb21e9 100644 --- a/tests/test_valid_yaml.py +++ b/tests/test_valid_yaml.py @@ -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")