diff --git a/sensor/house_info.py b/sensor/house_info.py index e69de29b..7c516635 100644 --- a/sensor/house_info.py +++ b/sensor/house_info.py @@ -0,0 +1,22 @@ +from datetime import date + +class HouseInfo(object): + def __init__(self, data): + self.data = data + + def get_data_by_area(self, field, rec_area=0): + field_data = [] + for record in self.data: + if rec_area == 0: + field_data.append(record[field]) + elif rec_area == int(record['area']): + field_data.append(record[field]) + return field_data + + def get_data_by_date(self, field, rec_date=date.today()): + field_data = [] + + for record in self.data: + if rec_date.strftime("%m/%d/%y") == record['date']: + field_data.append(record[field]) + return field_data \ No newline at end of file diff --git a/sensor/load_data.py b/sensor/load_data.py index e69de29b..aa02f61e 100644 --- a/sensor/load_data.py +++ b/sensor/load_data.py @@ -0,0 +1,20 @@ +import os +import glob +import csv + +def load_sensor_data(): + sensor_data = [] + + sensor_files = glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv')) + + # Loop over list of files + for sensor_file in sensor_files: + with open(sensor_file ) as data_file: + # Create a csv.DictReader + data_reader = csv.DictReader(data_file, delimiter=',') + # Loop over each row dictionary + for row in data_reader: + # Create a list of dictionaries + sensor_data.append(row) + + return sensor_data \ No newline at end of file diff --git a/sensor/sensor_app.py b/sensor/sensor_app.py index e3fdb5ce..c683edb3 100644 --- a/sensor/sensor_app.py +++ b/sensor/sensor_app.py @@ -1,6 +1,7 @@ # Runner script for all modules - - +from load_data import load_sensor_data +from house_info import HouseInfo +from datetime import datetime, date ############################## # Do not remove these two lines # They are needed to validate your unittest @@ -8,12 +9,21 @@ print("Sensor Data App") ############################## +# Module 1 code here: +data = load_sensor_data() +print("Loaded records: {}".format(len(data))) # Module 2 code here: +house_info = HouseInfo(data) +test_area = 1 +recs = house_info.get_data_by_area("id", rec_area=test_area) +print("\nHouse sensor records for area {} = {}".format(test_area, len(recs))) + +test_date = datetime.strptime("5/9/20", "%m/%d/%y") +recs = house_info.get_data_by_date("id", rec_date=test_date) +print("House sensor records for date {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) # Module 3 code here: # Module 4 code here: -# Module 5 code here: - -# Module 6 code here: \ No newline at end of file +# Module 5 code here: \ No newline at end of file diff --git a/tests/test_module1.py b/tests/test_module1.py index 3c51e0af..003e98c4 100644 --- a/tests/test_module1.py +++ b/tests/test_module1.py @@ -328,32 +328,70 @@ 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): - # from load_data import load_sensor_data + # First, let's verify the user did not accidentally deleted + # the two lines provided for them. + # data = [] # list to store data read from files # print("Sensor Data App") - # - # data = load_sensor_data() - # print("Loaded records {}".format(len(data))) + + 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") + """ - test_file = "sensor_app" - test_class = "HouseInfo" - test_method = "__init__" + 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")""" - my_file = parse(test_file) - assert my_file.success, my_file.message + + ###################################################### + # Now we can test the actual module + ###################################################### + # from load_data import load_sensor_data + # data = load_sensor_data() + # print("Loaded records {}".format(len(data))) - my_file_import = my_file.from_imports( + load_sensor_data_import = sensor.from_imports( "load_data", "load_sensor_data") - assert my_file_import, "Are you importing `load_sensor_data` from `load_data`?" + assert load_sensor_data_import, "Are you importing `load_sensor_data` from load_data?" data = ( - my_file.assign_().match( + sensor.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", @@ -366,8 +404,4 @@ def test_sensor_app_load_data_return_module1(parse): ) assert ( data - ), """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 + ), "Are you creating a variable called `data` set equal to `load_sensor_data()` function?" \ No newline at end of file diff --git a/tests/test_module2.py b/tests/test_module2.py index cb0f3cda..ca27940c 100644 --- a/tests/test_module2.py +++ b/tests/test_module2.py @@ -443,8 +443,9 @@ def test_sensor_app_house_info_by_area_module2(parse): # from house_info import HouseInfo # ... # house_info = HouseInfo(data) - # recs = house_info.get_data_by_area("id", rec_area=1) - # print("House sensor records for area 1 = {}".format(len(recs))) # NOT TEST IT + # test_area = 1 + # recs = house_info.get_data_by_area("id", rec_area=test_area) + # print("\nHouse sensor records for area {} = {}".format(test_area, len(recs))) test_file = "sensor_app" @@ -481,29 +482,35 @@ def test_sensor_app_house_info_by_area_module2(parse): test_code = ( my_file.assign_().match( { - "3_type": "Assign", - "3_targets_0_type": "Name", - "3_targets_0_id": "recs", - "3_value_type": "Call", - "3_value_func_type": "Attribute", - "3_value_func_value_type": "Name", - "3_value_func_value_id": "house_info", - "3_value_func_attr": "get_data_by_area", - "3_value_args_0_type": "Constant", - "3_value_args_0_value": "id", - "3_value_keywords_0_type": "keyword", - "3_value_keywords_0_arg": "rec_area", - "3_value_keywords_0_value_type": "Constant", - "3_value_keywords_0_value_value": 1, + "3_type": "Assign", + "3_targets_0_type": "Name", + "3_targets_0_id": "test_area", + "3_value_type": "Constant", + "3_value_value": 1, + "4_type": "Assign", + "4_targets_0_type": "Name", + "4_targets_0_id": "recs", + "4_value_type": "Call", + "4_value_func_type": "Attribute", + "4_value_func_value_type": "Name", + "4_value_func_value_id": "house_info", + "4_value_func_attr": "get_data_by_area", + "4_value_args_0_type": "Constant", + "4_value_args_0_value": "id", + "4_value_keywords_0_type": "keyword", + "4_value_keywords_0_arg": "rec_area", + "4_value_keywords_0_value_type": "Name", + "4_value_keywords_0_value_id": "test_area", } ) .exists() ) assert ( test_code - ), """Are you creating a variable `recs` and setting it to `house_info.get_data_by_area()`? + ), """Are you creating a variable called `test_area` and setting it to 1? + Are you creating a variable `recs` and setting it to `house_info.get_data_by_area()`? Are you passing `"id"` as the first argument to the method? - Are you passing `rec_area=1` as the second argument to the method?""" + Are you passing `rec_area=test_area` as the second argument to the method?""" @pytest.mark.test_sensor_app_house_info_by_date_module2 @@ -526,24 +533,25 @@ 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 `date` from `datetime` module?" + # debug_test_case(my_file) test_code = ( my_file.assign_().match( { - "4_type": "Assign", - "4_targets_0_type": "Name", - "4_targets_0_id": "test_date", - "4_value_type": "Call", - "4_value_func_type": "Attribute", - "4_value_func_value_type": "Name", - "4_value_func_value_id": "datetime", - "4_value_func_attr": "strptime", - "4_value_args_0_type": "Constant", - "4_value_args_0_value": "5/9/20", - "4_value_args_1_type": "Constant", - "4_value_args_1_value": "%m/%d/%y", + "5_type": "Assign", + "5_targets_0_type": "Name", + "5_targets_0_id": "test_date", + "5_value_type": "Call", + "5_value_func_type": "Attribute", + "5_value_func_value_type": "Name", + "5_value_func_value_id": "datetime", + "5_value_func_attr": "strptime", + "5_value_args_0_type": "Constant", + "5_value_args_0_value": "5/9/20", + "5_value_args_1_type": "Constant", + "5_value_args_1_value": "%m/%d/%y", } ) .exists() @@ -551,26 +559,26 @@ def test_sensor_app_house_info_by_date_module2(parse): assert ( test_code ), """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 = ( my_file.assign_().match( { - "5_type": "Assign", - "5_targets_0_type": "Name", - "5_targets_0_id": "recs", - "5_value_type": "Call", - "5_value_func_type": "Attribute", - "5_value_func_value_type": "Name", - "5_value_func_value_id": "house_info", - "5_value_func_attr": "get_data_by_date", - "5_value_args_0_type": "Constant", - "5_value_args_0_value": "id", - "5_value_keywords_0_type": "keyword", - "5_value_keywords_0_arg": "rec_date", - "5_value_keywords_0_value_type": "Name", - "5_value_keywords_0_value_id": "test_date" - + "6_type": "Assign", + "6_targets_0_type": "Name", + "6_targets_0_id": "recs", + "6_value_type": "Call", + "6_value_func_type": "Attribute", + "6_value_func_value_type": "Name", + "6_value_func_value_id": "house_info", + "6_value_func_attr": "get_data_by_date", + "6_value_args_0_type": "Constant", + "6_value_args_0_value": "id", + "6_value_keywords_0_type": "keyword", + "6_value_keywords_0_arg": "rec_date", + "6_value_keywords_0_value_type": "Name", + "6_value_keywords_0_value_id": "test_date", } ) .exists() diff --git a/tests/test_module3.py b/tests/test_module3.py index 700470ab..5d7371b9 100644 --- a/tests/test_module3.py +++ b/tests/test_module3.py @@ -86,7 +86,7 @@ def test_temperature_create_class_module3(parse): def test_temperature_convert_loop_module3(parse): # for rec in data: # # Convert string of integers into actual integers based 10 - # recs.append(int(rec, 10)) + # recs.append(int(rec, base=10)) # return recs test_file = "temperature_info" @@ -140,15 +140,17 @@ def test_temperature_convert_loop_module3(parse): "0_value_args_0_func_id": "int", "0_value_args_0_args_0_type": "Name", "0_value_args_0_args_0_id": "rec", - "0_value_args_0_args_1_type": "Constant", - "0_value_args_0_args_1_value": 10 + "0_value_args_0_keywords_0_type": "keyword", + "0_value_args_0_keywords_0_arg": "base", + "0_value_args_0_keywords_0_value_type": "Constant", + "0_value_args_0_keywords_0_value_value": 10 } ) .exists() ) assert ( test_code - ), """Inside your loop, are you converting `rec` value to integer based ten + ), """Inside your loop, are you converting `rec` value to integer `base=10` Are you appending it to `recs` list?""" test_code= ( @@ -383,6 +385,7 @@ def test_temperature_by_date_method_module3(parse): 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): # ... @@ -438,9 +441,8 @@ def test_sensor_app_temp_info_by_area_module3(parse): # from temperature_info import TemperatureData # ... # temperature_data = TemperatureData(data) - # recs = temperature_data.get_data_by_area(rec_area=1) - # NOTE: print statements are not validated - # print("House Temperature sensor records for area 1 = {}".format(len(recs))) + # recs = temperature_data.get_data_by_area(rec_area=test_area) + # print("\nHouse Temperature sensor records for area {} = {}".format(test_area, len(recs))) # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} temperatures".format( max(recs), min(recs))) test_file = "sensor_app" @@ -453,19 +455,20 @@ def test_sensor_app_temp_info_by_area_module3(parse): "temperature_info", "TemperatureData") assert my_file_import, "Are you importing `{0}` from `temperature_info` in `{}`".format(test_file) + # debug_test_case(my_file) test_code = ( my_file.assign_().match( { - "6_type": "Assign", - "6_targets_0_type": "Name", - "6_targets_0_id": "temperature_data", - "6_value_type": "Call", - "6_value_func_type": "Name", - "6_value_func_id": "TemperatureData", - "6_value_args_0_type": "Name", - "6_value_args_0_id": "data", + "7_type": "Assign", + "7_targets_0_type": "Name", + "7_targets_0_id": "temperature_data", + "7_value_type": "Call", + "7_value_func_type": "Name", + "7_value_func_id": "TemperatureData", + "7_value_args_0_type": "Name", + "7_value_args_0_id": "data", } ) .exists() @@ -474,23 +477,24 @@ def test_sensor_app_temp_info_by_area_module3(parse): test_code ), """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 = ( my_file.assign_().match( { - "7_type": "Assign", - "7_targets_0_type": "Name", - "7_targets_0_id": "recs", - "7_value_type": "Call", - "7_value_func_type": "Attribute", - "7_value_func_value_type": "Name", - "7_value_func_value_id": "temperature_data", - "7_value_func_attr": "get_data_by_area", - "7_value_keywords_0_type": "keyword", - "7_value_keywords_0_arg": "rec_area", - "7_value_keywords_0_value_type": "Constant", - "7_value_keywords_0_value_value": 1, + "8_type": "Assign", + "8_targets_0_type": "Name", + "8_targets_0_id": "recs", + "8_value_type": "Call", + "8_value_func_type": "Attribute", + "8_value_func_value_type": "Name", + "8_value_func_value_id": "temperature_data", + "8_value_func_attr": "get_data_by_area", + "8_value_keywords_0_type": "keyword", + "8_value_keywords_0_arg": "rec_area", + "8_value_keywords_0_value_type": "Name", + "8_value_keywords_0_value_id": "test_area", } ) .exists() @@ -498,7 +502,7 @@ def test_sensor_app_temp_info_by_area_module3(parse): assert ( test_code ), """Are you setting `recs` to the method call `get_data_by_area` from the `temperature_data` object? - Are you passing `"rec_area=1"` as the only argument to the method? + Are you passing `rec_area=test_area` as the only argument to the method? """ @@ -521,18 +525,18 @@ def test_sensor_app_temp_info_by_date_module3(parse): test_code = ( my_file.assign_().match( { - "8_type": "Assign", - "8_targets_0_type": "Name", - "8_targets_0_id": "recs", - "8_value_type": "Call", - "8_value_func_type": "Attribute", - "8_value_func_value_type": "Name", - "8_value_func_value_id": "temperature_data", - "8_value_func_attr": "get_data_by_date", - "8_value_keywords_0_type": "keyword", - "8_value_keywords_0_arg": "rec_date", - "8_value_keywords_0_value_type": "Name", - "8_value_keywords_0_value_id": "test_date" + "9_type": "Assign", + "9_targets_0_type": "Name", + "9_targets_0_id": "recs", + "9_value_type": "Call", + "9_value_func_type": "Attribute", + "9_value_func_value_type": "Name", + "9_value_func_value_id": "temperature_data", + "9_value_func_attr": "get_data_by_date", + "9_value_keywords_0_type": "keyword", + "9_value_keywords_0_arg": "rec_date", + "9_value_keywords_0_value_type": "Name", + "9_value_keywords_0_value_id": "test_date", } ) .exists() diff --git a/tests/test_module4.py b/tests/test_module4.py index a9f45b1c..00777bf3 100644 --- a/tests/test_module4.py +++ b/tests/test_module4.py @@ -142,6 +142,7 @@ def test_humidity_convert_loop_module4(parse): assert ( test_code ), """Inside your loop, are you converting `rec` value to `float()` and multiplying it by `100`? + Are you appending it to `recs` list?""" test_code= ( @@ -160,7 +161,7 @@ def test_humidity_convert_loop_module4(parse): @pytest.mark.test_humidity_by_area_method_module4 -def test_humidity_by_area_and_method_module4(parse): +def test_humidity_by_area_method_module4(parse): # def get_data_by_area(self, rec_area=0): # data = super().get_data_by_area("humidity", rec_area) # return self._convert_data(recs) @@ -379,9 +380,8 @@ def test_sensor_app_temp_info_by_area_module4(parse): # from statistics import mean # ... # humidity_data = HumidityData(data) - # recs = humidity_data.get_data_by_area(rec_area=1) - # NOTE: print statements are not validated - # print("\nHouse Humidity sensor records for area 1 = {}".format(len(recs))) + # recs = particle_data.get_data_by_area(rec_area=test_area) + # print("\nHouse Particle sensor records for area {} = {}".format(test_area, len(recs))) # print("\tAverage: {} humidity".format(mean(recs))) test_file = "sensor_app" @@ -393,21 +393,20 @@ def test_sensor_app_temp_info_by_area_module4(parse): my_file_import = my_file.from_imports( "humidity_info", "HumidityData") assert my_file_import, "Are you importing `HumidityData` from `humidity_info` in `{}`".format(test_file) - # debug_test_case(my_file) test_code = ( my_file.assign_().match( { - "9_type": "Assign", - "9_targets_0_type": "Name", - "9_targets_0_id": "humidity_data", - "9_value_type": "Call", - "9_value_func_type": "Name", - "9_value_func_id": "HumidityData", - "9_value_args_0_type": "Name", - "9_value_args_0_id": "data", + "10_type": "Assign", + "10_targets_0_type": "Name", + "10_targets_0_id": "humidity_data", + "10_value_type": "Call", + "10_value_func_type": "Name", + "10_value_func_id": "HumidityData", + "10_value_args_0_type": "Name", + "10_value_args_0_id": "data", } ) .exists() @@ -421,18 +420,18 @@ def test_sensor_app_temp_info_by_area_module4(parse): test_code = ( my_file.assign_().match( { - "10_type": "Assign", - "10_targets_0_type": "Name", - "10_targets_0_id": "recs", - "10_value_type": "Call", - "10_value_func_type": "Attribute", - "10_value_func_value_type": "Name", - "10_value_func_value_id": "humidity_data", - "10_value_func_attr": "get_data_by_area", - "10_value_keywords_0_type": "keyword", - "10_value_keywords_0_arg": "rec_area", - "10_value_keywords_0_value_type": "Constant", - "10_value_keywords_0_value_value": 1, + "11_type": "Assign", + "11_targets_0_type": "Name", + "11_targets_0_id": "recs", + "11_value_type": "Call", + "11_value_func_type": "Attribute", + "11_value_func_value_type": "Name", + "11_value_func_value_id": "humidity_data", + "11_value_func_attr": "get_data_by_area", + "11_value_keywords_0_type": "keyword", + "11_value_keywords_0_arg": "rec_area", + "11_value_keywords_0_value_type": "Name", + "11_value_keywords_0_value_id": "test_area", } ) .exists() @@ -440,7 +439,7 @@ def test_sensor_app_temp_info_by_area_module4(parse): assert ( test_code ), """Are you setting `recs` to the method call `get_data_by_area` from the `humidity_data` object? - Are you passing `"rec_area=1"` as the only argument to the method? + Are you passing `rec_area=test_area` as the only argument to the method? """ my_file_import = my_file.from_imports( @@ -466,18 +465,18 @@ def test_sensor_app_temp_info_by_date_module4(parse): test_code = ( my_file.assign_().match( { - "11_type": "Assign", - "11_targets_0_type": "Name", - "11_targets_0_id": "recs", - "11_value_type": "Call", - "11_value_func_type": "Attribute", - "11_value_func_value_type": "Name", - "11_value_func_value_id": "humidity_data", - "11_value_func_attr": "get_data_by_date", - "11_value_keywords_0_type": "keyword", - "11_value_keywords_0_arg": "rec_date", - "11_value_keywords_0_value_type": "Name", - "11_value_keywords_0_value_id": "test_date" + "12_type": "Assign", + "12_targets_0_type": "Name", + "12_targets_0_id": "recs", + "12_value_type": "Call", + "12_value_func_type": "Attribute", + "12_value_func_value_type": "Name", + "12_value_func_value_id": "humidity_data", + "12_value_func_attr": "get_data_by_date", + "12_value_keywords_0_type": "keyword", + "12_value_keywords_0_arg": "rec_date", + "12_value_keywords_0_value_type": "Name", + "12_value_keywords_0_value_id": "test_date", } ) .exists() @@ -931,7 +930,7 @@ def test_particle_get_concentration_for_module4(parse): # # Select particulate concentration # if rec <= 50.0: # particulate["good"] += 1 - # elif rec > 50.0 and rec < 100: + # elif rec > 50.0 and rec <= 100: # particulate["moderate"] += 1 # else: # particulate["bad"] += 1 @@ -996,8 +995,8 @@ def test_sensor_app_particle_info_by_area_module4(parse): # from particle_count_info import ParticleData # module 4 # ... # particle_data = ParticleData(data) - # recs = particle_data.get_data_by_area(rec_area=1) - # print("\nHouse Particle sensor records for area 1 = {}".format(len(recs))) + # recs = particle_data.get_data_by_area(rec_area=test_area) + # print("\nHouse Particle sensor records for area {} = {}".format(test_area, len(recs))) # concentrations = particle_data.get_data_concentrations(data=recs) # print("\tGood Air Quality Recs: {}".format(concentrations["good"])) # print("\tModerate Air Quality Recs: {}".format(concentrations["moderate"])) @@ -1018,14 +1017,14 @@ def test_sensor_app_particle_info_by_area_module4(parse): test_code = ( my_file.assign_().match( { - "12_type": "Assign", - "12_targets_0_type": "Name", - "12_targets_0_id": "particle_data", - "12_value_type": "Call", - "12_value_func_type": "Name", - "12_value_func_id": "ParticleData", - "12_value_args_0_type": "Name", - "12_value_args_0_id": "data", + "13_type": "Assign", + "13_targets_0_type": "Name", + "13_targets_0_id": "particle_data", + "13_value_type": "Call", + "13_value_func_type": "Name", + "13_value_func_id": "ParticleData", + "13_value_args_0_type": "Name", + "13_value_args_0_id": "data", } ) .exists() @@ -1039,18 +1038,18 @@ def test_sensor_app_particle_info_by_area_module4(parse): test_code = ( my_file.assign_().match( { - "13_type": "Assign", - "13_targets_0_type": "Name", - "13_targets_0_id": "recs", - "13_value_type": "Call", - "13_value_func_type": "Attribute", - "13_value_func_value_type": "Name", - "13_value_func_value_id": "particle_data", - "13_value_func_attr": "get_data_by_area", - "13_value_keywords_0_type": "keyword", - "13_value_keywords_0_arg": "rec_area", - "13_value_keywords_0_value_type": "Constant", - "13_value_keywords_0_value_value": 1, + "14_type": "Assign", + "14_targets_0_type": "Name", + "14_targets_0_id": "recs", + "14_value_type": "Call", + "14_value_func_type": "Attribute", + "14_value_func_value_type": "Name", + "14_value_func_value_id": "particle_data", + "14_value_func_attr": "get_data_by_area", + "14_value_keywords_0_type": "keyword", + "14_value_keywords_0_arg": "rec_area", + "14_value_keywords_0_value_type": "Name", + "14_value_keywords_0_value_id": "test_area", } ) .exists() @@ -1058,24 +1057,24 @@ def test_sensor_app_particle_info_by_area_module4(parse): assert ( test_code ), """Are you setting `recs` to the method call `get_data_by_area` from the `particle_data` object? - Are you passing `"rec_area=1"` as the only argument to the method? + Are you passing `rec_area=test_area` as the only argument to the method? """ test_code = ( my_file.assign_().match( { - "14_type": "Assign", - "14_targets_0_type": "Name", - "14_targets_0_id": "concentrations", - "14_value_type": "Call", - "14_value_func_type": "Attribute", - "14_value_func_value_type": "Name", - "14_value_func_value_id": "particle_data", - "14_value_func_attr": "get_data_concentrations", - "14_value_keywords_0_type": "keyword", - "14_value_keywords_0_arg": "data", - "14_value_keywords_0_value_type": "Name", - "14_value_keywords_0_value_id": "recs", + "15_type": "Assign", + "15_targets_0_type": "Name", + "15_targets_0_id": "concentrations", + "15_value_type": "Call", + "15_value_func_type": "Attribute", + "15_value_func_value_type": "Name", + "15_value_func_value_id": "particle_data", + "15_value_func_attr": "get_data_concentrations", + "15_value_keywords_0_type": "keyword", + "15_value_keywords_0_arg": "data", + "15_value_keywords_0_value_type": "Name", + "15_value_keywords_0_value_id": "recs", } ) .exists() @@ -1109,18 +1108,18 @@ def test_sensor_app_particle_info_by_date_module4(parse): test_code = ( my_file.assign_().match( { - "15_type": "Assign", - "15_targets_0_type": "Name", - "15_targets_0_id": "recs", - "15_value_type": "Call", - "15_value_func_type": "Attribute", - "15_value_func_value_type": "Name", - "15_value_func_value_id": "particle_data", - "15_value_func_attr": "get_data_by_date", - "15_value_keywords_0_type": "keyword", - "15_value_keywords_0_arg": "rec_date", - "15_value_keywords_0_value_type": "Name", - "15_value_keywords_0_value_id": "test_date", + "16_type": "Assign", + "16_targets_0_type": "Name", + "16_targets_0_id": "recs", + "16_value_type": "Call", + "16_value_func_type": "Attribute", + "16_value_func_value_type": "Name", + "16_value_func_value_id": "particle_data", + "16_value_func_attr": "get_data_by_date", + "16_value_keywords_0_type": "keyword", + "16_value_keywords_0_arg": "rec_date", + "16_value_keywords_0_value_type": "Name", + "16_value_keywords_0_value_id": "test_date", } ) .exists() @@ -1134,18 +1133,18 @@ def test_sensor_app_particle_info_by_date_module4(parse): test_code = ( my_file.assign_().match( { - "16_type": "Assign", - "16_targets_0_type": "Name", - "16_targets_0_id": "concentrations", - "16_value_type": "Call", - "16_value_func_type": "Attribute", - "16_value_func_value_type": "Name", - "16_value_func_value_id": "particle_data", - "16_value_func_attr": "get_data_concentrations", - "16_value_keywords_0_type": "keyword", - "16_value_keywords_0_arg": "data", - "16_value_keywords_0_value_type": "Name", - "16_value_keywords_0_value_id": "recs", + "17_type": "Assign", + "17_targets_0_type": "Name", + "17_targets_0_id": "concentrations", + "17_value_type": "Call", + "17_value_func_type": "Attribute", + "17_value_func_value_type": "Name", + "17_value_func_value_id": "particle_data", + "17_value_func_attr": "get_data_concentrations", + "17_value_keywords_0_type": "keyword", + "17_value_keywords_0_arg": "data", + "17_value_keywords_0_value_type": "Name", + "17_value_keywords_0_value_id": "recs", } ) .exists() diff --git a/tests/test_module5.py b/tests/test_module5.py index 9766e4bf..232b0d3b 100644 --- a/tests/test_module5.py +++ b/tests/test_module5.py @@ -27,7 +27,8 @@ def test_energy_create_class_module5(parse): ), """Have you created a class called `{0}`? 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,7 +38,7 @@ def test_energy_create_class_module5(parse): "0_targets_0_id": "ENERGY_PER_BULB", "0_value_type": "Constant", "0_value_value": "#", - + "1_type": "Assign", "1_targets_0_type": "Name", "1_targets_0_id": "ENERGY_BITS", @@ -53,15 +54,16 @@ def test_energy_create_class_module5(parse): 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): # def _get_energy(self, rec): - # rec = int(rec, 16) - # rec = rec & ENERGY_BITS # mask ENERGY bits - # rec = rec >> 4 # shift right - # return rec + # energy = int(rec, base=16) + # energy = energy & self.ENERGY_BITS # mask ENERGY bits + # energy = energy >> 4 # shift right + # return energy + test_file = "energy_info" parent_class = "HouseInfo" test_class = "EnergyData" @@ -114,31 +116,34 @@ def test_energy_get_energy_method_module5(parse): { "0_type": "Assign", "0_targets_0_type": "Name", - "0_targets_0_id": "rec", + "0_targets_0_id": "energy", "0_value_type": "Call", "0_value_func_type": "Name", "0_value_func_id": "int", "0_value_args_0_type": "Name", "0_value_args_0_id": "rec", - "0_value_args_1_type": "Constant", - "0_value_args_1_value": 16, + "0_value_keywords_0_type": "keyword", + "0_value_keywords_0_arg": "base", + "0_value_keywords_0_value_type": "Constant", + "0_value_keywords_0_value_value": 16, } ) .exists() ) assert ( test_code - ), "Are you converting `rec` by casting it as an `int()` with base `16`?" + ), """Are you converting `rec` as an `int()` with `base=16`? + Are you assigning the result to a variable called `energy`?""" test_code = ( my_method.assign_().match( { "1_type": "Assign", "1_targets_0_type": "Name", - "1_targets_0_id": "rec", + "1_targets_0_id": "energy", "1_value_type": "BinOp", "1_value_left_type": "Name", - "1_value_left_id": "rec", + "1_value_left_id": "energy", "1_value_op_type": "BitAnd", "1_value_right_type": "Attribute", "1_value_right_value_type": "Name", @@ -150,17 +155,17 @@ def test_energy_get_energy_method_module5(parse): ) assert ( test_code - ), """Are you converting `rec` by "anding it" with `self.ENERGY_BITS`?""" + ), """Are you converting `energy` by "anding it" with `self.ENERGY_BITS`?""" test_code = ( my_method.assign_().match( { "2_type": "Assign", "2_targets_0_type": "Name", - "2_targets_0_id": "rec", + "2_targets_0_id": "energy", "2_value_type": "BinOp", "2_value_left_type": "Name", - "2_value_left_id": "rec", + "2_value_left_id": "energy", "2_value_op_type": "RShift", "2_value_right_type": "Constant", "2_value_right_value": 4 @@ -170,21 +175,21 @@ def test_energy_get_energy_method_module5(parse): ) assert ( test_code - ), """Are you converting `rec` by shifting the bits to the right 4 positions?""" + ), """Are you converting `energy` by shifting the bits to the right 4 positions?""" test_code = ( my_method.returns_call().match( { "type": "Return", "value_type": "Name", - "value_id": "rec" + "value_id": "energy" } ) .exists() ) assert ( test_code - ), """Are you returning `recs` from the `{}` method?""".format(test_method) + ), """Are you returning `energy` from the `{}` method?""".format(test_method) @pytest.mark.test_energy_convert_method_module5 @@ -627,8 +632,8 @@ def test_sensor_app_energy_info_by_area_module5(parse): # from energy_info import EnergyData # module 4 # ... # energy_data = EnergyData(data) - # recs = energy_data.get_data_by_area(rec_area=1) - # print("\nHouse Energy sensor records for area 1 = {}".format(len(recs))) + # recs = energy_data.get_data_by_area(rec_area=test_area) + # print("\nHouse Energy sensor records for area {} = {}".format(test_area, len(recs))) # total_energy = energy_data.calculate_energy_usage(data=recs) # print("\tEnergy Usage: {:2.2} Watts".format(total_energy)) @@ -647,14 +652,14 @@ def test_sensor_app_energy_info_by_area_module5(parse): test_code = ( my_file.assign_().match( { - "17_type": "Assign", - "17_targets_0_type": "Name", - "17_targets_0_id": "energy_data", - "17_value_type": "Call", - "17_value_func_type": "Name", - "17_value_func_id": "EnergyData", - "17_value_args_0_type": "Name", - "17_value_args_0_id": "data", + "18_type": "Assign", + "18_targets_0_type": "Name", + "18_targets_0_id": "energy_data", + "18_value_type": "Call", + "18_value_func_type": "Name", + "18_value_func_id": "EnergyData", + "18_value_args_0_type": "Name", + "18_value_args_0_id": "data", } ) .exists() @@ -668,18 +673,18 @@ def test_sensor_app_energy_info_by_area_module5(parse): test_code = ( my_file.assign_().match( { - "18_type": "Assign", - "18_targets_0_type": "Name", - "18_targets_0_id": "recs", - "18_value_type": "Call", - "18_value_func_type": "Attribute", - "18_value_func_value_type": "Name", - "18_value_func_value_id": "energy_data", - "18_value_func_attr": "get_data_by_area", - "18_value_keywords_0_type": "keyword", - "18_value_keywords_0_arg": "rec_area", - "18_value_keywords_0_value_type": "Constant", - "18_value_keywords_0_value_value": 1 + "19_type": "Assign", + "19_targets_0_type": "Name", + "19_targets_0_id": "recs", + "19_value_type": "Call", + "19_value_func_type": "Attribute", + "19_value_func_value_type": "Name", + "19_value_func_value_id": "energy_data", + "19_value_func_attr": "get_data_by_area", + "19_value_keywords_0_type": "keyword", + "19_value_keywords_0_arg": "rec_area", + "19_value_keywords_0_value_type": "Name", + "19_value_keywords_0_value_id": "test_area", } ) .exists() @@ -687,24 +692,24 @@ def test_sensor_app_energy_info_by_area_module5(parse): assert ( test_code ), """Are you setting `recs` to the method call `get_data_by_area` from the `energy_data` object? - Are you passing `"rec_area=1"` as the only argument to the method? + Are you passing `rec_area=test_area` as the only argument to the method? """ test_code = ( my_file.assign_().match( { - "19_type": "Assign", - "19_targets_0_type": "Name", - "19_targets_0_id": "total_energy", - "19_value_type": "Call", - "19_value_func_type": "Attribute", - "19_value_func_value_type": "Name", - "19_value_func_value_id": "energy_data", - "19_value_func_attr": "calculate_energy_usage", - "19_value_keywords_0_type": "keyword", - "19_value_keywords_0_arg": "data", - "19_value_keywords_0_value_type": "Name", - "19_value_keywords_0_value_id": "recs", + "20_type": "Assign", + "20_targets_0_type": "Name", + "20_targets_0_id": "total_energy", + "20_value_type": "Call", + "20_value_func_type": "Attribute", + "20_value_func_value_type": "Name", + "20_value_func_value_id": "energy_data", + "20_value_func_attr": "calculate_energy_usage", + "20_value_keywords_0_type": "keyword", + "20_value_keywords_0_arg": "data", + "20_value_keywords_0_value_type": "Name", + "20_value_keywords_0_value_id": "recs", } ) .exists() @@ -736,18 +741,18 @@ def test_sensor_app_energy_info_by_date_module5(parse): test_code = ( my_file.assign_().match( { - "20_type": "Assign", - "20_targets_0_type": "Name", - "20_targets_0_id": "recs", - "20_value_type": "Call", - "20_value_func_type": "Attribute", - "20_value_func_value_type": "Name", - "20_value_func_value_id": "energy_data", - "20_value_func_attr": "get_data_by_date", - "20_value_keywords_0_type": "keyword", - "20_value_keywords_0_arg": "rec_date", - "20_value_keywords_0_value_type": "Name", - "20_value_keywords_0_value_id": "test_date", + "21_type": "Assign", + "21_targets_0_type": "Name", + "21_targets_0_id": "recs", + "21_value_type": "Call", + "21_value_func_type": "Attribute", + "21_value_func_value_type": "Name", + "21_value_func_value_id": "energy_data", + "21_value_func_attr": "get_data_by_date", + "21_value_keywords_0_type": "keyword", + "21_value_keywords_0_arg": "rec_date", + "21_value_keywords_0_value_type": "Name", + "21_value_keywords_0_value_id": "test_date", } ) .exists() @@ -761,18 +766,18 @@ def test_sensor_app_energy_info_by_date_module5(parse): test_code = ( my_file.assign_().match( { - "21_type": "Assign", - "21_targets_0_type": "Name", - "21_targets_0_id": "total_energy", - "21_value_type": "Call", - "21_value_func_type": "Attribute", - "21_value_func_value_type": "Name", - "21_value_func_value_id": "energy_data", - "21_value_func_attr": "calculate_energy_usage", - "21_value_keywords_0_type": "keyword", - "21_value_keywords_0_arg": "data", - "21_value_keywords_0_value_type": "Name", - "21_value_keywords_0_value_id": "recs" + "22_type": "Assign", + "22_targets_0_type": "Name", + "22_targets_0_id": "total_energy", + "22_value_type": "Call", + "22_value_func_type": "Attribute", + "22_value_func_value_type": "Name", + "22_value_func_value_id": "energy_data", + "22_value_func_attr": "calculate_energy_usage", + "22_value_keywords_0_type": "keyword", + "22_value_keywords_0_arg": "data", + "22_value_keywords_0_value_type": "Name", + "22_value_keywords_0_value_id": "recs" } ) .exists()