Skip to content

Commit 1343d80

Browse files
Adding tests
1 parent cd040cd commit 1343d80

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

tests/test_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
from pathlib import Path
34
from unittest.mock import MagicMock, Mock, patch
45

@@ -166,11 +167,12 @@ def test_main_json_map_generation(caplog):
166167
"tests/t01-services/synoptic/index.bob",
167168
],
168169
)
170+
if Path.exists(Path("tests/t01-services/synoptic/JsonMap.json")):
171+
os.remove("tests/t01-services/synoptic/JsonMap.json")
169172
for log_output in caplog.records:
170173
assert "Json map generated for (from" in log_output.message
171174

172175

173176
def test_main_without_techui_yaml(caplog):
174177
result = runner.invoke(app)
175-
print(result.output)
176178
assert "Techui.yaml file must be provided as an argument." in result.output

tests/test_generate_jsonmap.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,46 @@
55

66
import pytest
77
from lxml import objectify
8+
from typer.testing import CliRunner
89

910
from techui_builder.generate_jsonmap import (
1011
JsonMap,
1112
_get_action_group,
1213
_serialise_json_map,
14+
app,
15+
log_level,
1316
)
1417

18+
runner = CliRunner()
19+
20+
21+
@patch("techui_builder.generate_jsonmap.Logger")
22+
def test_log_level(mock_logger):
23+
log_level("INFO")
24+
mock_logger.assert_called_once()
25+
1526

1627
def test_write_json_map_no_synoptic(json_map_generator):
1728
with pytest.raises(FileNotFoundError):
1829
json_map_generator.bob_path = Path("Synoptic")
1930
json_map_generator.write_json_map()
2031

2132

33+
def test_app():
34+
result = runner.invoke(app, ["tests/t01-services/synoptic/techui.yaml"])
35+
if Path.exists(Path("tests/t01-services/synoptic/JsonMap.json")):
36+
os.remove("tests/t01-services/synoptic/JsonMap.json")
37+
assert result.exit_code == 0
38+
39+
40+
@patch("techui_builder.generate_jsonmap.yaml.safe_load")
41+
def test_json_map_generator_techui_exception(mock_safe_load, json_map_generator):
42+
mock_safe_load.side_effect = Exception("YAML load error")
43+
with pytest.raises(Exception) as excinfo:
44+
json_map_generator.__init__(bob_path=Path("tests/test_files/test_bob.bob"))
45+
assert "No such file or directory" in str(excinfo.value)
46+
47+
2248
def test_write_json_map(json_map_generator):
2349
test_map = JsonMap(
2450
str(Path(__file__).parent.joinpath("test_files/test_bob.bob")), None

0 commit comments

Comments
 (0)