@@ -14,6 +14,7 @@ class TestUtilityFunctions:
1414
1515 def test_replace_none_with_empty (self ):
1616 """Test the _replace_none_with_empty utility function."""
17+ # Import here to ensure license is set up
1718 from flexo_syside_lib .core import _replace_none_with_empty
1819
1920 data = {"a" : None , "b" : [1 , None , {"c" : None }]}
@@ -33,26 +34,13 @@ def test_wrap_elements_as_payload(self):
3334 from flexo_syside_lib .core import _wrap_elements_as_payload
3435
3536 elements = [
36- {"@id" : "ID1" , "name" : None },
37+ {"@id" : "ID1" , "@uri" : "ignore" , " name" : None },
3738 {"name" : "X" , "props" : [None , 1 ]},
3839 ]
3940 wrapped = _wrap_elements_as_payload (elements )
40- # check wrapper structure
41- assert isinstance (wrapped , list )
42- assert all ("payload" in e for e in wrapped )
43-
44- # identity should now be inside payload
45- assert wrapped [0 ]["payload" ]["identity" ] == {"@id" : "ID1" }
46-
47- # @uri should be removed
48- assert "@uri" not in wrapped [0 ]["payload" ]
49-
50- # None should become "" in name
41+ assert wrapped [0 ]["identity" ] == {"@id" : "ID1" }
5142 assert wrapped [0 ]["payload" ]["name" ] == ""
52-
53- # props should remain list with None preserved
5443 assert wrapped [1 ]["payload" ]["props" ][0 ] is None
55- assert wrapped [1 ]["payload" ]["props" ][1 ] == 1
5644
5745 def test_make_root_namespace_first (self ):
5846 """Test the _make_root_namespace_first utility function."""
@@ -105,6 +93,7 @@ def test_convert_sysml_string_to_json(self, mock_syside):
10593 """Test converting SysML string to JSON with mocked SysIDE."""
10694 from flexo_syside_lib .core import convert_sysml_string_textual_to_json
10795
96+ # Sample SysML content
10897 sample_sysml = '''
10998 package TestPackage {
11099 part def Component {
@@ -113,16 +102,19 @@ def test_convert_sysml_string_to_json(self, mock_syside):
113102 }
114103 '''
115104
105+ # Sample JSON data
116106 sample_json = [
117107 {"@id" : "ns1" , "@type" : "Namespace" , "qualifiedName" : "2020-01-01T00:00:00Z" },
118108 {"@id" : "comp1" , "@type" : "Component" , "name" : "TestComponent" },
119109 ]
120110
111+ # Mock SysIDE components
121112 mock_model = Mock ()
122113 mock_diagnostics = Mock ()
123114 mock_diagnostics .contains_errors .return_value = False
124115 mock_syside .load_model .return_value = (mock_model , mock_diagnostics )
125116
117+ # Mock the model serialization
126118 mock_model .user_docs = [Mock ()]
127119 mock_locked = Mock ()
128120 mock_locked .root_node = Mock ()
@@ -131,8 +123,11 @@ def test_convert_sysml_string_to_json(self, mock_syside):
131123 mock_context_manager .__exit__ = Mock (return_value = None )
132124 mock_model .user_docs [0 ].lock .return_value = mock_context_manager
133125
126+ # Mock JSON writer
134127 mock_writer = Mock ()
135128 mock_writer .result = json .dumps (sample_json )
129+
130+ # Mock serialization options
136131 mock_options = Mock ()
137132
138133 with patch ('flexo_syside_lib.core._create_json_writer' , return_value = mock_writer ), \
@@ -141,16 +136,18 @@ def test_convert_sysml_string_to_json(self, mock_syside):
141136
142137 payload , json_string = convert_sysml_string_textual_to_json (sample_sysml )
143138
139+ # Verify we get a payload structure
144140 assert isinstance (payload , list )
145141 assert len (payload ) > 0
146142
147- # Verify payload structure (updated)
143+ # Verify payload structure
148144 for item in payload :
149145 assert "payload" in item
150- assert "identity" in item [ "payload" ]
146+ assert "identity" in item
151147 assert isinstance (item ["payload" ], dict )
152- assert isinstance (item ["payload" ][ " identity" ], dict )
148+ assert isinstance (item ["identity" ], dict )
153149
150+ # Verify JSON string is valid
154151 parsed_json = json .loads (json_string )
155152 assert isinstance (parsed_json , list )
156153 assert len (parsed_json ) > 0
@@ -160,6 +157,7 @@ def test_convert_sysml_file_to_json(self, mock_syside):
160157 """Test converting SysML file to JSON with mocked SysIDE."""
161158 from flexo_syside_lib .core import convert_sysml_file_textual_to_json
162159
160+ # Sample SysML content
163161 sample_sysml = '''
164162 package TestPackage {
165163 part def Component {
@@ -168,16 +166,19 @@ def test_convert_sysml_file_to_json(self, mock_syside):
168166 }
169167 '''
170168
169+ # Sample JSON data
171170 sample_json = [
172171 {"@id" : "ns1" , "@type" : "Namespace" , "qualifiedName" : "2020-01-01T00:00:00Z" },
173172 {"@id" : "comp1" , "@type" : "Component" , "name" : "TestComponent" },
174173 ]
175174
175+ # Mock SysIDE components
176176 mock_model = Mock ()
177177 mock_diagnostics = Mock ()
178178 mock_diagnostics .contains_errors .return_value = False
179179 mock_syside .try_load_model .return_value = (mock_model , mock_diagnostics )
180180
181+ # Mock the model serialization
181182 mock_model .user_docs = [Mock ()]
182183 mock_locked = Mock ()
183184 mock_locked .root_node = Mock ()
@@ -186,8 +187,11 @@ def test_convert_sysml_file_to_json(self, mock_syside):
186187 mock_context_manager .__exit__ = Mock (return_value = None )
187188 mock_model .user_docs [0 ].lock .return_value = mock_context_manager
188189
190+ # Mock JSON writer
189191 mock_writer = Mock ()
190192 mock_writer .result = json .dumps (sample_json )
193+
194+ # Mock serialization options
191195 mock_options = Mock ()
192196
193197 with patch ('flexo_syside_lib.core._create_json_writer' , return_value = mock_writer ), \
@@ -201,16 +205,18 @@ def test_convert_sysml_file_to_json(self, mock_syside):
201205 try :
202206 payload , json_string = convert_sysml_file_textual_to_json (temp_file )
203207
208+ # Verify we get a payload structure
204209 assert isinstance (payload , list )
205210 assert len (payload ) > 0
206211
207- # Verify payload structure (updated)
212+ # Verify payload structure
208213 for item in payload :
209214 assert "payload" in item
210- assert "identity" in item [ "payload" ]
215+ assert "identity" in item
211216 assert isinstance (item ["payload" ], dict )
212- assert isinstance (item ["payload" ][ " identity" ], dict )
217+ assert isinstance (item ["identity" ], dict )
213218
219+ # Verify JSON string is valid
214220 parsed_json = json .loads (json_string )
215221 assert isinstance (parsed_json , list )
216222 assert len (parsed_json ) > 0
@@ -223,7 +229,7 @@ def test_convert_json_to_sysml_textual_invalid_input(self):
223229 from flexo_syside_lib .core import convert_json_to_sysml_textual
224230
225231 with pytest .raises (TypeError , match = "json_flexo must be dict/list/str" ):
226- convert_json_to_sysml_textual (123 )
232+ convert_json_to_sysml_textual (123 ) # Invalid type
227233
228234 @patch ('flexo_syside_lib.core.syside' )
229235 def test_create_json_writer (self , mock_syside ):
@@ -260,10 +266,15 @@ class TestLicenseHandling:
260266
261267 def test_import_without_license_graceful_failure (self ):
262268 """Test that import fails gracefully when no license is available."""
269+ # This test verifies that the import behavior is predictable
270+ # In CI, we'll mock syside to avoid license issues
263271 pass
264272
265273 def test_utility_functions_work_without_syside (self ):
266274 """Test that utility functions work even if SysIDE is mocked."""
275+ # This test ensures our utility functions are truly independent
267276 from flexo_syside_lib .core import _replace_none_with_empty
277+
278+ # Test that the function works regardless of SysIDE state
268279 result = _replace_none_with_empty ({"test" : None })
269280 assert result == {"test" : "" }
0 commit comments