rendercv/tests/test_cli.py

73 lines
1.8 KiB
Python
Raw Normal View History

2024-02-11 13:37:10 +00:00
import rendercv.cli as cli
2024-02-09 19:32:58 +00:00
import pydantic
import ruamel.yaml
import pytest
2024-02-11 13:37:10 +00:00
import typer.testing
runner = typer.testing.CliRunner()
2024-02-09 19:32:58 +00:00
def test_welcome():
2024-02-11 13:37:10 +00:00
cli.welcome()
2024-02-09 19:32:58 +00:00
def test_warning():
2024-02-11 13:37:10 +00:00
cli.warning("This is a warning message.")
2024-02-09 19:32:58 +00:00
def test_error():
2024-02-11 13:37:10 +00:00
cli.error("This is an error message.")
2024-02-09 19:32:58 +00:00
def test_information():
2024-02-11 13:37:10 +00:00
cli.information("This is an information message.")
2024-02-09 19:32:58 +00:00
def test_get_error_message_and_location_and_value_from_a_custom_error():
error_string = "('error message', 'location', 'value')"
2024-02-11 13:37:10 +00:00
result = cli.get_error_message_and_location_and_value_from_a_custom_error(
2024-02-09 19:32:58 +00:00
error_string
)
assert result == ("error message", "location", "value")
error_string = "error message"
2024-02-11 13:37:10 +00:00
result = cli.get_error_message_and_location_and_value_from_a_custom_error(
2024-02-09 19:32:58 +00:00
error_string
)
assert result is None
def test_handle_validation_error(invalid_entries):
for entry_type, entries in invalid_entries.items():
for entry in entries:
try:
entry_type(**entry)
except pydantic.ValidationError as e:
2024-02-11 13:37:10 +00:00
cli.handle_validation_error(e)
2024-02-09 19:32:58 +00:00
@pytest.mark.parametrize(
"exception",
[ruamel.yaml.YAMLError, RuntimeError],
)
def test_handle_exceptions(exception):
2024-02-11 13:37:10 +00:00
@cli.handle_exceptions
2024-02-09 19:32:58 +00:00
def function_that_raises_exception():
raise exception("This is an exception!")
function_that_raises_exception()
def test_live_progress_reporter_class():
2024-02-11 13:37:10 +00:00
with cli.LiveProgressReporter(number_of_steps=3) as progress:
2024-02-09 19:32:58 +00:00
progress.start_a_step("Test step 1")
progress.finish_the_current_step()
progress.start_a_step("Test step 2")
progress.finish_the_current_step()
progress.start_a_step("Test step 3")
progress.finish_the_current_step()