First (way too late) commit
Dumping my fever dream coding session into source control finally.
This commit is contained in:
18
tests/test_cli.py
Normal file
18
tests/test_cli.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
from typer.testing import CliRunner
|
||||
|
||||
TestModuleBase = Path(__file__).parent.parent.stem.replace("-", "_")
|
||||
|
||||
|
||||
def test_example_version():
|
||||
app = import_module(f"{TestModuleBase}.cli").app
|
||||
base = import_module(f"{TestModuleBase}")
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
result = runner.invoke(app, ["--version"])
|
||||
assert result.exit_code == 0
|
||||
assert base.PROJECT_VERSION in result.stdout.strip()
|
||||
assert base.PROJECT_NAME in result.stdout.strip()
|
||||
assert len(result.stdout.splitlines()) == 1
|
||||
35
tests/test_configuration.py
Normal file
35
tests/test_configuration.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import SecretStr
|
||||
import configuration as config
|
||||
|
||||
def test_settings_object():
|
||||
|
||||
setting_obj = config.Settings()
|
||||
assert setting_obj.example_string == "Example Default"
|
||||
|
||||
|
||||
def test_settings_load_missing():
|
||||
setting_obj = config.Settings().load("non_existent_config_file.toml")
|
||||
assert setting_obj.example_string == "Example Default"
|
||||
assert setting_obj.example_float is None
|
||||
|
||||
def test_settings_save_and_load(tmp_path: Path):
|
||||
test_config_file = tmp_path / "test_config.toml"
|
||||
|
||||
# Create a settings object and modify some values
|
||||
setting_obj = config.Settings()
|
||||
setting_obj.example_string = "Modified String"
|
||||
setting_obj.example_int = 42
|
||||
setting_obj.example_section.example_key = "Modified Section Key"
|
||||
|
||||
# Save the settings to the test config file
|
||||
setting_obj.save(custom_file=test_config_file)
|
||||
|
||||
# Load the settings from the test config file
|
||||
loaded_settings = config.Settings.load(custom_file=test_config_file)
|
||||
|
||||
# Verify that the loaded settings match the saved settings
|
||||
assert loaded_settings.example_string == "Modified String"
|
||||
assert loaded_settings.example_int == 42
|
||||
assert loaded_settings.example_section.example_key == "Modified Section Key"
|
||||
Reference in New Issue
Block a user