19
19
from test_lib import capture_stdout , mock_env
20
20
21
21
sys .path .append (os .path .join (os .path .dirname (__file__ ), ".." , "src" ))
22
- from download_vspec import download_file , get_vehicle_model_src , is_uri , main # noqa
22
+ from download_vspec import ( # noqa
23
+ download_file ,
24
+ get_legacy_model_src ,
25
+ is_proper_interface_type ,
26
+ is_uri ,
27
+ main ,
28
+ require_env ,
29
+ )
23
30
24
31
vspec_300_uri = "https://github.com/COVESA/vehicle_signal_specification/releases/download/v3.0/vss_rel_3.0.json" # noqa
25
- app_manifest = {"VehicleModel" : {"src" : "" }}
32
+
33
+
34
+ def get_vspec_file_path_value (capturedOutput : str ) -> str :
35
+ return (
36
+ capturedOutput .split ("vspec_file_path=" )[1 ]
37
+ .split (" >> VELOCITAS_CACHE" )[0 ]
38
+ .replace ("'" , "" )
39
+ )
26
40
27
41
28
42
def test_is_uri ():
@@ -38,48 +52,100 @@ def test_download_file():
38
52
assert os .path .isfile (local_file_path )
39
53
40
54
41
- def test_camel_case_vehicle_model_key ():
55
+ def test_get_legacy_model_src__camel_case_vehicle_model_key ():
42
56
app_manifest_dict = {"vehicleModel" : {"src" : "foo" }}
43
- with mock_env (app_manifest_dict ):
44
- assert get_vehicle_model_src () == "foo"
57
+ assert get_legacy_model_src (app_manifest_dict ) == "foo"
45
58
46
59
47
- def test_pascal_case_vehicle_model_key ():
60
+ def test_get_legacy_model_src__pascal_case_vehicle_model_key ():
48
61
app_manifest_dict = {"VehicleModel" : {"src" : "bar" }}
49
- with mock_env (app_manifest_dict ):
50
- assert get_vehicle_model_src () == "bar"
62
+ assert get_legacy_model_src (app_manifest_dict ) == "bar"
51
63
52
64
53
- def test_invalid_vehicle_model_key ():
65
+ def test_get_legacy_model_src__invalid_vehicle_model_key ():
54
66
app_manifest_dict = {"Vehicle.Model" : {"src" : "baz" }}
55
- with mock_env (app_manifest_dict ):
56
- with pytest .raises (KeyError ):
57
- get_vehicle_model_src ()
67
+ with pytest .raises (KeyError ):
68
+ get_legacy_model_src (app_manifest_dict )
69
+
70
+
71
+ def test_proper_interface_type__wrong_type ():
72
+ assert not is_proper_interface_type ({"type" : "foo" })
73
+
58
74
75
+ def test_proper_interface_type__no_type ():
76
+ assert not is_proper_interface_type ({"notype" : "foo" })
59
77
60
- def test_int_relative_src_converted_to_absolute ():
61
- app_manifest ["VehicleModel" ]["src" ] = "./app/vspec.json"
62
- with capture_stdout () as capture , mock_env (app_manifest ):
63
- main ()
78
+
79
+ def test_proper_interface_type__correct_type ():
80
+ assert is_proper_interface_type ({"type" : "vehicle-signal-interface" })
81
+
82
+
83
+ def test_require_env__var_not_present__raises_error ():
84
+ with pytest .raises (ValueError ):
85
+ require_env ("foo" )
86
+
87
+
88
+ @pytest .mark .parametrize (
89
+ "app_manifest" ,
90
+ [
91
+ {
92
+ "manifestVersion" : "v3" ,
93
+ "interfaces" : [
94
+ {
95
+ "type" : "vehicle-signal-interface" ,
96
+ "config" : {"src" : "./app/vspec.json" },
97
+ }
98
+ ],
99
+ },
100
+ {"VehicleModel" : {"src" : "./app/vspec.json" }},
101
+ ],
102
+ )
103
+ def test_main__relative_src__converted_to_absolute (app_manifest ):
104
+ with capture_stdout () as capture , mock_env ():
105
+ main (app_manifest )
64
106
65
107
vspec_file_path = get_vspec_file_path_value (capture .getvalue ())
66
108
assert os .path .isabs (vspec_file_path )
67
109
assert vspec_file_path == "/workspaces/my_vehicle_app/app/vspec.json"
68
110
69
111
70
- def test_int_uri_src_downloaded_and_stored_in_cache ():
71
- app_manifest ["VehicleModel" ]["src" ] = vspec_300_uri
72
- with capture_stdout () as capture , mock_env (app_manifest ):
73
- main ()
112
+ @pytest .mark .parametrize (
113
+ "app_manifest" ,
114
+ [
115
+ {
116
+ "manifestVersion" : "v3" ,
117
+ "interfaces" : [
118
+ {"type" : "vehicle-signal-interface" , "config" : {"src" : vspec_300_uri }}
119
+ ],
120
+ },
121
+ {"VehicleModel" : {"src" : vspec_300_uri }},
122
+ ],
123
+ )
124
+ def test_main__valid_app_manifest__uri_src_downloaded_and_stored_in_cache (app_manifest ):
125
+ with capture_stdout () as capture , mock_env ():
126
+ main (app_manifest )
74
127
75
128
vspec_file_path = get_vspec_file_path_value (capture .getvalue ())
76
129
assert os .path .isabs (vspec_file_path )
77
130
assert vspec_file_path == "/tmp/velocitas/vspec.json"
78
131
79
132
80
- def get_vspec_file_path_value (capturedOutput : str ) -> str :
81
- return (
82
- capturedOutput .split ("vspec_file_path=" )[1 ]
83
- .split (" >> VELOCITAS_CACHE" )[0 ]
84
- .replace ("'" , "" )
85
- )
133
+ def test_main__duplicate_vehicle_signal_interface__raises_error ():
134
+ app_manifest = {
135
+ "manifestVersion" : "v3" ,
136
+ "interfaces" : [
137
+ {"type" : "vehicle-signal-interface" , "config" : {"src" : vspec_300_uri }},
138
+ {"type" : "vehicle-signal-interface" , "config" : {"src" : vspec_300_uri }},
139
+ ],
140
+ }
141
+ with pytest .raises (KeyError ):
142
+ main (app_manifest )
143
+
144
+
145
+ def test_main__no_vehicle_signal_interface__silently_exists ():
146
+ app_manifest = {
147
+ "manifestVersion" : "v3" ,
148
+ "interfaces" : [{"type" : "pubsub" , "config" : {}}],
149
+ }
150
+ with capture_stdout (), mock_env ():
151
+ main (app_manifest )
0 commit comments