diff --git a/sensor/sensor_app.py b/sensor/sensor_app.py index 08e8059b..e3fdb5ce 100644 --- a/sensor/sensor_app.py +++ b/sensor/sensor_app.py @@ -4,16 +4,16 @@ ############################## # Do not remove these two lines # They are needed to validate your unittest -recs = 0 +data = [] print("Sensor Data App") ############################## -# Module 1 code here: - # Module 2 code here: # Module 3 code here: # Module 4 code here: -# Module 5 code here: \ No newline at end of file +# Module 5 code here: + +# Module 6 code here: \ No newline at end of file diff --git a/tests/test_module1.py b/tests/test_module1.py index 003e98c4..3c51e0af 100644 --- a/tests/test_module1.py +++ b/tests/test_module1.py @@ -328,70 +328,32 @@ def test_load_data_load_recs_module1(parse): @pytest.mark.test_sensor_app_load_data_return_module1 def test_sensor_app_load_data_return_module1(parse): - # First, let's verify the user did not accidentally deleted - # the two lines provided for them. - + # from load_data import load_sensor_data # data = [] # list to store data read from files # print("Sensor Data App") - - sensor = parse("sensor_app") - assert sensor.success, sensor.message - - original_data = ( - sensor.assign_().match( - { - "0_type": "Assign", - "0_targets_0_type": "Name", - "0_targets_0_id": "data", - "0_value_type": "List", - } - ) - .exists() - ) - assert ( - original_data - ), """Do you have a `data` variable set to an empty list on top of the file? - You need to have these two lines of code before you being testing Module1 - data = [] - print("Sensor Data App") - """ + # + # data = load_sensor_data() + # print("Loaded records {}".format(len(data))) - print_app = ( - sensor.calls().match( - { - "type": "Expr", - "value_type": "Call", - "value_func_type": "Name", - "value_func_id": "print", - "value_args_0_type": "Constant", - "value_args_0_value": "Sensor Data App" - } - ) - .exists() - ) - assert ( - print_app - ), """Do you have a `print("Sensor Data App")` statement? - You need to have these two lines of code before you being testing Module1 - data = [] - print("Sensor Data App")""" + test_file = "sensor_app" + test_class = "HouseInfo" + test_method = "__init__" - - ###################################################### - # Now we can test the actual module - ###################################################### + my_file = parse(test_file) + assert my_file.success, my_file.message - # from load_data import load_sensor_data - # data = load_sensor_data() - # print("Loaded records {}".format(len(data))) - load_sensor_data_import = sensor.from_imports( + my_file_import = my_file.from_imports( "load_data", "load_sensor_data") - assert load_sensor_data_import, "Are you importing `load_sensor_data` from load_data?" + assert my_file_import, "Are you importing `load_sensor_data` from `load_data`?" data = ( - sensor.assign_().match( + my_file.assign_().match( { + "0_type": "Assign", + "0_targets_0_type": "Name", + "0_targets_0_id": "data", + "0_value_type": "List", "1_type": "Assign", "1_targets_0_type": "Name", "1_targets_0_id": "data", @@ -404,4 +366,8 @@ def test_sensor_app_load_data_return_module1(parse): ) assert ( data - ), "Are you creating a variable called `data` set equal to `load_sensor_data()` function?" \ No newline at end of file + ), """Do you have a `data` variable set to an empty list on top of the file? + Did you delete the starting code ? + data = [] + print("Sensor Data App") + In a new line, are you setting `data` to `load_sensor_data()` function call?""" \ No newline at end of file diff --git a/tests/test_module2.py b/tests/test_module2.py index 5436ee8d..cb0f3cda 100644 --- a/tests/test_module2.py +++ b/tests/test_module2.py @@ -525,7 +525,7 @@ def test_sensor_app_house_info_by_date_module2(parse): my_file_import = my_file.from_imports( "datetime", "date") - assert my_file_import, "Are you importing `datetime` from `datetime` module?" + assert my_file_import, "Are you importing `date` from `datetime` module?" # debug_test_case(my_file) @@ -550,7 +550,7 @@ def test_sensor_app_house_info_by_date_module2(parse): ) assert ( test_code - ), """Are you creating an instance of the `datetime` class called `record_date` + ), """Are you creating an instance of the `datetime` class called `test_date` which takes `"5/9/20"` and `"%m/%d/%y"` as the two arguments?""" test_code = ( diff --git a/tests/test_module3.py b/tests/test_module3.py index 974b0d82..700470ab 100644 --- a/tests/test_module3.py +++ b/tests/test_module3.py @@ -243,7 +243,8 @@ def test_temperature_by_area_method_module3(parse): test_code ), """Are you creating a variable called `recs` set equal to the `{}` method from the `{}` parent class? - Are you passing "temperature" as the only argument to the method call?""".format(test_method, parent_class) + Are you passing `"temperature"` as the first argument to the method call? + Are you passing `rec_area` as the second argument to the method call?""".format(test_method, parent_class) @pytest.mark.test_temperature_by_area_method_return_module3 def test_temperature_by_area_method_return_module3(parse): @@ -310,7 +311,7 @@ def test_temperature_by_date_method_module3(parse): my_file_import = my_file.from_imports( "datetime", "date") - assert my_file_import, "Are you importing `date` from datetime in `{}`".format(test_file) + assert my_file_import, "Are you importing `date` from `datetime` in `{}`".format(test_file) my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) assert ( @@ -379,7 +380,8 @@ def test_temperature_by_date_method_module3(parse): test_code ), """Are you creating a variable called `recs` set equal to the `{}` method from the `{}` parent class? - Are you passing "temperature" as the only argument to the method call?""".format(test_method, parent_class) + Are you passing `"temperature"` as the first argument to the method call? + Are you passing `rec_date` as the second argument to the method call?""".format(test_method, parent_class) @pytest.mark.test_temperature_by_date_method_return_module3 def test_temperature_by_date_method_return_module3(parse): @@ -449,7 +451,7 @@ def test_sensor_app_temp_info_by_area_module3(parse): my_file_import = my_file.from_imports( "temperature_info", "TemperatureData") - assert my_file_import, "Are you importing `TemperatureData` from `temperature_info` in `{}`".format(test_file) + assert my_file_import, "Are you importing `{0}` from `temperature_info` in `{}`".format(test_file) # debug_test_case(my_file) @@ -470,8 +472,8 @@ def test_sensor_app_temp_info_by_area_module3(parse): ) assert ( test_code - ), """Are you creating an instance of the '{}' class with - `data` list as the initialization argument for the constructor? + ), """Are you creating an instance of the '{}' class called `temperature_data`? + Are you passing `data` list as the initialization argument for the constructor? """.format(test_class) test_code = ( diff --git a/tests/test_module4.py b/tests/test_module4.py index ba5349aa..a9f45b1c 100644 --- a/tests/test_module4.py +++ b/tests/test_module4.py @@ -92,7 +92,7 @@ def test_humidity_convert_loop_module4(parse): assert ( my_class.exists() ), """Have you created a class called `{0}`? - Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class) + Is your class inheriting the properties of the `{1}` class?""".format(test_class, parent_class) my_method = my_file.class_(test_class).method(test_method) assert ( @@ -141,7 +141,7 @@ def test_humidity_convert_loop_module4(parse): ) assert ( test_code - ), """Inside your loop, are you converting `rec` value to `float()` and multipling it by `100` + ), """Inside your loop, are you converting `rec` value to `float()` and multiplying it by `100`? Are you appending it to `recs` list?""" test_code= ( @@ -237,7 +237,8 @@ def test_humidity_by_area_and_method_module4(parse): test_code ), """Are you creating a variable called `recs` set equal to the `{}` method from the `{}` parent class? - Are you passing "humidity" as the only argument to the method call?""".format(test_method, parent_class) + Are you passing `"humidity"` as the first argument to the method call? + Are you passing `rec_area` as the second argument to the method call?""".format(test_method, parent_class) test_code = ( my_method.returns_call().match( @@ -347,7 +348,8 @@ def test_humidity_by_date_method_module4(parse): test_code ), """Are you creating a variable called `recs` set equal to the `{}` method from the `{}` parent class? - Are you passing "humidity" as the only argument to the method call?""".format(test_method, parent_class) + Are you passing `"humidity"` as the first argument to the method call? + Are you passing `rec_date` as the second argument to the method call?""".format(test_method, parent_class) test_code = ( my_method.returns_call().match( @@ -392,9 +394,6 @@ def test_sensor_app_temp_info_by_area_module4(parse): "humidity_info", "HumidityData") assert my_file_import, "Are you importing `HumidityData` from `humidity_info` in `{}`".format(test_file) - my_file_import = my_file.from_imports( - "statistics", "mean") - assert my_file_import, "Are you importing `mean` from `statistics` in `{}`".format(test_file) # debug_test_case(my_file) @@ -415,8 +414,8 @@ def test_sensor_app_temp_info_by_area_module4(parse): ) assert ( test_code - ), """Are you creating an instance of the '{}' class with - `data` list as the initialization argument for the constructor? + ), """Are you creating an instance of the '{}' class called `humidity_data`? + Are you passing `data` as the initialization argument for the constructor? """.format(test_class) test_code = ( @@ -726,7 +725,8 @@ def test_particle_by_area_and_date_methods_module4(parse): test_code ), """Are you creating a variable called `recs` set equal to the `{}` method from the `{}` parent class? - Are you passing "particle" as the only argument to the method call?""".format(test_method, parent_class) + Are you passing `"particulate"` as the first argument to the method call? + Are you passing `rec_area` as the second argument to the method call?""".format(test_method, parent_class) test_code = ( my_method.returns_call().match( @@ -819,7 +819,8 @@ def test_particle_by_area_and_date_methods_module4(parse): test_code ), """Are you creating a variable called `recs` set equal to the `{}` method from the `{}` parent class? - Are you passing "particle" as the only argument to the method call?""".format(test_method, parent_class) + Are you passing `"particulate"` as the first argument to the method call? + Are you passing `rec_date`as the second argument to the method call?""".format(test_method, parent_class) test_code = ( my_method.returns_call().match( @@ -1031,8 +1032,8 @@ def test_sensor_app_particle_info_by_area_module4(parse): ) assert ( test_code - ), """Are you creating an instance of the '{}' class with - `data` list as the initialization argument for the constructor? + ), """Are you creating an instance of the '{}' class called `particle_data`? + Are you passing `data` as the initialization argument for the constructor? """.format(test_class) test_code = ( diff --git a/tests/test_module5.py b/tests/test_module5.py index 8631df25..9766e4bf 100644 --- a/tests/test_module5.py +++ b/tests/test_module5.py @@ -25,9 +25,9 @@ def test_energy_create_class_module5(parse): assert ( my_class.exists() ), """Have you created a class called `{0}`? - Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class) + Is your class inheriting the properties of the `{1}` class?""".format(test_class, parent_class) - # debug_test_case_class(my_class, test_method) + debug_test_case_class(my_class, test_method) test_code = ( my_class.assign_().match( @@ -37,18 +37,7 @@ def test_energy_create_class_module5(parse): "0_targets_0_id": "ENERGY_PER_BULB", "0_value_type": "Constant", "0_value_value": "#", - } - ) - .exists() - ) - assert ( - test_code - ), """Are you declararing a constant `ENERGY_PER_BULB`? - Did you set it to `0.2` float number?""" - - test_code = ( - my_class.assign_().match( - { + "1_type": "Assign", "1_targets_0_type": "Name", "1_targets_0_id": "ENERGY_BITS", @@ -60,8 +49,11 @@ def test_energy_create_class_module5(parse): ) assert ( test_code - ), """Are you declararing a constant `ENERGY_BITS`? + ), """Are you declararing a constant `ENERGY_PER_BULB`? + Did you set it to `0.2` float number? + Are you declararing a constant `ENERGY_BITS`? Did you set it to `0x0F0` hex number?""" + @pytest.mark.test_energy_get_energy_method_module5 def test_energy_get_energy_method_module5(parse): @@ -70,7 +62,6 @@ def test_energy_get_energy_method_module5(parse): # rec = rec & ENERGY_BITS # mask ENERGY bits # rec = rec >> 4 # shift right # return rec - test_file = "energy_info" parent_class = "HouseInfo" test_class = "EnergyData" @@ -670,8 +661,8 @@ def test_sensor_app_energy_info_by_area_module5(parse): ) assert ( test_code - ), """Are you creating an instance of the '{}' class with - `data` list as the initialization argument for the constructor? + ), """Are you creating an instance of the '{}' class called `energy_data` + Are you passing `data` as the initialization argument for the constructor? """.format(test_class) test_code = ( @@ -789,6 +780,5 @@ def test_sensor_app_energy_info_by_date_module5(parse): assert ( test_code ), """Are you setting `total_energy` to the method call `calculate_energy` from the `energy_data` object? - Are you pasing `get_data_by_date` method of the same object as input argument? - Are you passing `rec_date=test_date` as the argument to `get_data_by_date` method? + Are you passing `data=recs` as the only argument to the method? """