@@ -328,12 +328,63 @@ def test_load_data_load_recs_module1(parse):
328328
329329@pytest .mark .test_sensor_app_load_data_return_module1
330330def test_sensor_app_load_data_return_module1 (parse ):
331+ # First, let's verify the user did not accidentally deleted
332+ # the two lines provided for them.
333+
334+ # data = [] # list to store data read from files
335+ # print("Sensor Data App")
336+
337+ sensor = parse ("sensor_app" )
338+ assert sensor .success , sensor .message
339+
340+ original_data = (
341+ sensor .assign_ ().match (
342+ {
343+ "0_type" : "Assign" ,
344+ "0_targets_0_type" : "Name" ,
345+ "0_targets_0_id" : "data" ,
346+ "0_value_type" : "List" ,
347+ }
348+ )
349+ .exists ()
350+ )
351+ assert (
352+ original_data
353+ ), """Do you have a `data` variable set to an empty list on top of the file?
354+ You need to have these two lines of code before you being testing Module1
355+ data = []
356+ print("Sensor Data App")
357+ """
358+
359+ print_app = (
360+ sensor .calls ().match (
361+ {
362+ "type" : "Expr" ,
363+ "value_type" : "Call" ,
364+ "value_func_type" : "Name" ,
365+ "value_func_id" : "print" ,
366+ "value_args_0_type" : "Constant" ,
367+ "value_args_0_value" : "Sensor Data App"
368+ }
369+ )
370+ .exists ()
371+ )
372+ assert (
373+ print_app
374+ ), """Do you have a `print("Sensor Data App")` statement?
375+ You need to have these two lines of code before you being testing Module1
376+ data = []
377+ print("Sensor Data App")"""
378+
379+
380+ ######################################################
381+ # Now we can test the actual module
382+ ######################################################
383+
331384 # from load_data import load_sensor_data
332385 # data = load_sensor_data()
333386 # print("Loaded records {}".format(len(data)))
334387
335- sensor = parse ("sensor_app" )
336- assert sensor .success , sensor .message
337388
338389 load_sensor_data_import = sensor .from_imports (
339390 "load_data" , "load_sensor_data" )
@@ -348,7 +399,7 @@ def test_sensor_app_load_data_return_module1(parse):
348399 {
349400 "1_type" : "Assign" ,
350401 "1_targets_0_type" : "Name" ,
351- "1_targets_0_id" : "recs " ,
402+ "1_targets_0_id" : "data " ,
352403 "1_value_type" : "Call" ,
353404 "1_value_func_type" : "Name" ,
354405 "1_value_func_id" : "load_sensor_data" ,
@@ -370,13 +421,13 @@ def test_sensor_app_load_data_return_module1(parse):
370421 "value_args_0_type" : "Call" ,
371422 "value_args_0_func_type" : "Attribute" ,
372423 "value_args_0_func_value_type" : "Constant" ,
373- "value_args_0_func_value_value" : "Loaded records: [{}] " ,
424+ "value_args_0_func_value_value" : "Loaded records: {} " ,
374425 "value_args_0_func_attr" : "format" ,
375426 "value_args_0_args_0_type" : "Call" ,
376427 "value_args_0_args_0_func_type" : "Name" ,
377428 "value_args_0_args_0_func_id" : "len" ,
378429 "value_args_0_args_0_args_0_type" : "Name" ,
379- "value_args_0_args_0_args_0_id" : "recs "
430+ "value_args_0_args_0_args_0_id" : "data "
380431 }
381432 )
382433 .exists ()
0 commit comments