diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..2b0d6bd --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import pytest + + +def pytest_addoption(parser): + parser.addoption( + "--manual", action="store_true", help="Run tests that need a human for verification.") + + +def pytest_collection_modifyitems(config, items): + if config.getoption('--manual'): + skip_normal = pytest.mark.skip(reason=f"Only manual tests get run when --manual is set.") + + for item in items: + if not "manual" in item.keywords: + item.add_marker(skip_normal) + + else: + skip_manual = pytest.mark.skip(reason=f"Only normal tests get run when --manual is not set.") + + for item in items: + if "manual" in item.keywords: + item.add_marker(skip_manual) \ No newline at end of file diff --git a/tests/text/test_format.py b/tests/text/test_format.py index 769339b..dffa08c 100644 --- a/tests/text/test_format.py +++ b/tests/text/test_format.py @@ -1,15 +1,25 @@ #!/usr/bin/python3 +import sys +import pytest + from wobbl_tools.text.format import format_string from wobbl_tools.text import format +sys.path.append("..") +from utils import is_right # noqa -print("\n==== wobbl_tools.text.format =====") -formats = list(format.color_ansi.keys()) -formats.remove("rs") -formats.remove("reset") +@pytest.mark.manual +def test_formatting(): + print("\n==== wobbl_tools.text.format =====") -print("Is this shit looking right?\n") + formats = list(format.color_ansi.keys()) + formats.remove("rs") + formats.remove("reset") -for format_name in formats: - print(f"{format_name.title().replace("_", " ")} text: {format_string(f"§{format_name}Text")}") + print("Is this shit looking right?\n") + + for format_name in formats: + print(f"{format_name.title().replace('_', ' ')} text: {format_string(f'§{format_name}Text')}") + + assert is_right() diff --git a/tests/text/test_log.py b/tests/text/test_log.py index 7d37852..1ad86e9 100644 --- a/tests/text/test_log.py +++ b/tests/text/test_log.py @@ -1,22 +1,33 @@ #!/usr/bin/python3 +import sys import pytest -from wobbl_tools.text.log import Log -print("\n==== wobbl_tools.text.log =====") +from wobbl_tools.text import Log +sys.path.append("..") +from utils import is_right # noqa -test_log = Log("test_log.txt") -test_log.clear() -test_log.write("Testing the log module...") -test_log.write("This should be fine...", "ok") -test_log.write("Something happened...", "warning") -test_log.write("Oh shit!", "error") +@pytest.mark.manual +def test_writing(): + print("\n==== wobbl_tools.text.log =====") -print("Logfile contents:") -print(test_log.read()) + log = Log("test_log.txt") + log.clear() -without_file = Log() + log.write("Testing the log module...") + log.write("This should be fine...", "ok") + log.write("Something happened...", "warning") + log.write("Oh shit!", "error") -with pytest.raises(FileNotFoundError, match="You didn't specify a log path at the log instance definition."): - without_file.read() + print("Logfile contents:") + print(log.read()) + + assert is_right() + + +def test_exception_without_file_on_read(): + log = Log() + + with pytest.raises(FileNotFoundError, match="You didn't specify a log path at the log instance definition."): + log.read() diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..9c7cc91 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 + + +def is_right() -> bool: + """ + Ask the developer if the output of the test is right. + """ + + yn = input("\nIs this right? (y/n): ") + + print("\n") + + return yn.lower() == "y"