@@ -222,6 +222,96 @@ def test_from_numpy(valid_input_flag: bool, tst_mode, tst_f0, exp_factor_or_erro
222222 scope_object = pss .Scope .from_numpy (period_vector_t_i_invalid , mode = tst_mode , f0 = tst_f0 ,
223223 label = tst_label , unit = tst_unit )
224224
225+
226+ #########################################################################################################
227+ # test of from_geckocircuits
228+ #########################################################################################################
229+
230+ # test frequency
231+ frequency1 = 20e-1
232+ frequency2 = 1
233+
234+ # parameterset for values
235+ @pytest .mark .parametrize ("valid_file_name_flag, tst_datafile_name, tst_f0, exp_result_or_error, error_flag" , [
236+ # --invalid inputs----
237+ # wrong type for one attribute
238+ (False , "wrong_file_name" , None , ValueError , True ),
239+ (False , 2 , None , TypeError , True ),
240+ (False , None , None , TypeError , True ),
241+ (True , "test_data_gecko" , "Freq" , TypeError , True ),
242+ # --valid inputs----
243+ (True , "test_data_gecko" , None , 0 , False ),
244+ (True , "test_data_gecko" , frequency1 , 1 , False ),
245+ (True , "test_data_gecko" , frequency2 , 2 , False )
246+ ])
247+ # definition of the testfunction
248+ def test_from_geckocircuits (valid_file_name_flag : bool , tst_datafile_name , tst_f0 , exp_result_or_error , error_flag : bool ):
249+ """Test for the method test_from_geckocircuits().
250+
251+ :param valid_file_name_flag: flag to indicate if the file name is valid
252+ :type valid_file_name_flag: bool
253+ :param tst_datafile_name: string, which contains the test file name
254+ :type tst_datafile_name: any
255+ :param tst_f0: test variable for the frequency
256+ :type tst_f0: any
257+ :param exp_result_or_error: result vector index or expected error
258+ :type exp_result_or_error: any
259+ :param error_flag: flag to indicate, if an error or a valid result is expected
260+ :type error_flag: bool
261+ """
262+ # Define value input
263+ res_label_lst = ['u1' , 'u2' ]
264+ res_source = 'GeckoCIRCUITS simulation'
265+ tst_header = "# t " + res_label_lst [0 ] + " " + res_label_lst [1 ] + " "
266+ tst_time = [0.0 , 0.2 , 0.4 , 0.6 , 0.8 , 1.0 , 1.2 , 1.4 , 1.6 , 1.8 , 2 ]
267+ tst_data0 = [- 1 , - 2.1 , - 3.2 , - 4.4 , - 2.2 , - 0.2 , 0 , 2.1 , 4.4 , 2.1 , 0.2 ]
268+ tst_data1 = [1 , 2.1 , 3.2 , 4.4 , 3.2 , 0.2 , 0 , - 2.1 , - 4.4 , - 2.1 , - 0.2 ]
269+
270+ # Check if file name is valid
271+ if valid_file_name_flag is True :
272+ # generate a valid file
273+ with open (tst_datafile_name , "w" ) as file :
274+ # write the header
275+ file .write (tst_header + "\n " )
276+ # write data
277+ for act_time , act_data1 , act_data2 in zip (tst_time , tst_data0 , tst_data1 ):
278+ file .write (f"{ act_time } { act_data1 } { act_data2 } \n " )
279+
280+ # Check if expected test result is no error
281+ if error_flag is False :
282+
283+ # Resultvector definition
284+ if exp_result_or_error == 0 :
285+ resvector = [tst_time , tst_data0 , tst_data1 ]
286+ elif exp_result_or_error == 1 :
287+ resvector = [np .linspace (0 , 1 / tst_f0 , 3 ), tst_data0 [- 3 :], tst_data1 [- 3 :]]
288+ elif exp_result_or_error == 2 :
289+ resvector = [np .linspace (0 , 1 / tst_f0 , 6 ), tst_data0 [- 6 :], tst_data1 [- 6 :]]
290+
291+ # Perform command
292+ scope_object_lst = pss .Scope .from_geckocircuits (tst_datafile_name , f0 = tst_f0 )
293+
294+ # verification of attributes
295+ numpy .testing .assert_equal (scope_object_lst [0 ].label , res_label_lst [0 ])
296+ numpy .testing .assert_equal (scope_object_lst [1 ].label , res_label_lst [1 ])
297+ numpy .testing .assert_equal (scope_object_lst [0 ].source , res_source )
298+ numpy .testing .assert_equal (scope_object_lst [1 ].source , res_source )
299+
300+ # verification of data
301+ np .testing .assert_array_almost_equal (scope_object_lst [0 ].time , np .array (resvector [0 ]))
302+ np .testing .assert_array_almost_equal (scope_object_lst [1 ].time , np .array (resvector [0 ]))
303+ np .testing .assert_array_almost_equal (scope_object_lst [0 ].data , np .array (resvector [1 ]))
304+ np .testing .assert_array_almost_equal (scope_object_lst [1 ].data , np .array (resvector [2 ]))
305+ # delete the file
306+ else : # generate_channel raises an error
307+ with pytest .raises (exp_result_or_error ):
308+ scope_object_lst = pss .Scope .from_geckocircuits (tst_datafile_name , f0 = tst_f0 )
309+
310+ # delete the file if exists
311+ if valid_file_name_flag is True :
312+ if os .path .exists (tst_datafile_name ):
313+ os .remove (tst_datafile_name )
314+
225315#########################################################################################################
226316# test of low_pass_filter
227317#########################################################################################################
@@ -292,8 +382,10 @@ def test_low_pass_filter(tst_vector, tst_order, tst_angular_freq, exp_result_or_
292382# channel values
293383test_vec1 = pss .Scope .generate_channel ([0 , 1 , 2 , 3 , 4 , 5 , 6 ], [1 , 4 , 2 , 3 , 7 , 3 , 2 ])
294384
385+ # Remark: findiff v0.12.0 works with "test_res1 = [6, 1, 0, 2, 0, -2, 0]".
386+ # Bugfix in v0.12.1 leads to update of the result vector test_res1
295387# result values
296- test_res1 = [6 , 1 , 0 , 2 , 0 , - 2 , 0 ]
388+ test_res1 = [5.5 , 0.5 , - 0.5 , 2.5 , 0.0 , - 2.5 , 0.5 ]
297389
298390# parameterset for values
299391@pytest .mark .parametrize ("tst_vector, tst_order, exp_result_or_error, error_flag" , [
0 commit comments