File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import logging
2+ import os
23from pathlib import Path
34from 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
173176def 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
Original file line number Diff line number Diff line change 55
66import pytest
77from lxml import objectify
8+ from typer .testing import CliRunner
89
910from 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
1627def 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+
2248def test_write_json_map (json_map_generator ):
2349 test_map = JsonMap (
2450 str (Path (__file__ ).parent .joinpath ("test_files/test_bob.bob" )), None
You can’t perform that action at this time.
0 commit comments