From c44a5db826395c957d8837d4d74495789e235960 Mon Sep 17 00:00:00 2001 From: Hugo Valle Date: Tue, 19 May 2020 11:08:41 -0600 Subject: [PATCH 1/7] Update test module testing. --- tests/test_module1.py | 36 +- tests/test_module2.py | 328 +++++++----- tests/test_module3.py | 542 +++++++++++++++++++ tests/test_module4.py | 1162 +++++++++++++++++++++++++++++++++++++++++ tests/test_module5.py | 895 +++++++++++++++++++++++++++++++ 5 files changed, 2785 insertions(+), 178 deletions(-) create mode 100644 tests/test_module3.py create mode 100644 tests/test_module4.py create mode 100644 tests/test_module5.py diff --git a/tests/test_module1.py b/tests/test_module1.py index f75f53e3..2f65e70f 100644 --- a/tests/test_module1.py +++ b/tests/test_module1.py @@ -53,7 +53,6 @@ def test_load_data_load_sensor_func_module1(parse): @pytest.mark.test_load_data_sensor_files_module1 def test_load_data_sensor_files_module1(parse): - # def load_sensor_data(): # .... # sensor_files = glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv')) @@ -107,11 +106,9 @@ def test_load_data_sensor_files_module1(parse): ), "Are you creating a variable called `sensor_files` and assigning it glob.glob() and passing os.path.join()? Are you passing 3 values to os.path.join()?" - @pytest.mark.test_load_data_read_files_module1 def test_load_data_read_files_module1(parse): - # def load_sensor_data(): # .... # for sensor_file in sensor_files: # with open(sensor_file) as data_file: @@ -385,15 +382,10 @@ def test_sensor_app_load_data_return_module1(parse): # data = load_sensor_data() # print("Loaded records {}".format(len(data))) - load_sensor_data_import = sensor.from_imports( "load_data", "load_sensor_data") assert load_sensor_data_import, "Are you importing `load_sensor_data` from load_data?" - # print(json.dumps(sensor.assign_().n, indent=2)) - # print(json.dumps(sensor.calls().n, indent=2)) - # assert False - data = ( sensor.assign_().match( { @@ -409,30 +401,4 @@ 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?" - - # print_data = ( - # sensor.calls().match( - # { - # "type": "Expr", - # "value_type": "Call", - # "value_func_type": "Name", - # "value_func_id": "print", - # "value_args_0_type": "Call", - # "value_args_0_func_type": "Attribute", - # "value_args_0_func_value_type": "Constant", - # "value_args_0_func_value_value": "Loaded records: {}", - # "value_args_0_func_attr": "format", - # "value_args_0_args_0_type": "Call", - # "value_args_0_args_0_func_type": "Name", - # "value_args_0_args_0_func_id": "len", - # "value_args_0_args_0_args_0_type": "Name", - # "value_args_0_args_0_args_0_id": "data" - # } - # ) - # .exists() - # ) - # assert ( - # print_data - # ), "Are you calling `print()` and passing in `format()`? Are you passing 1 values to `format()` `len(data)`" - + ), "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 d56cd6a6..50ce185e 100644 --- a/tests/test_module2.py +++ b/tests/test_module2.py @@ -1,6 +1,5 @@ import pytest -import json - +from tests.template import debug_test_case, debug_test_case_class import sensor.load_data import sensor.house_info from datetime import date, datetime @@ -12,21 +11,27 @@ def test_house_info_create_class_module2(parse): # def __init__(self, data): # self.data = data - house_info = parse("house_info") - assert house_info.success, house_info.message + test_file = "house_info" + test_class = "HouseInfo" + test_method = "__init__" - house_info_class = house_info.class_("HouseInfo") + my_file = parse(test_file) + assert my_file.success, my_file.message + + # my_class = house_info.class_(test_class) + my_class = my_file.query("class {}(): ??".format(test_class)) assert ( - house_info_class.exists() - ), "Have you created a class called `HouseInfo` in the `house_info.py` file?" + my_class.exists() + ), "Have you created a class called `{0}` in the `{1}` file?".format(test_class, test_file) - class_init = house_info.class_("HouseInfo").method("__init__") - assert class_init.exists(), "Are you defining a constructor called `__init__`?" + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a constructor called `{}`?".format(test_method) - class_init_q = house_info.query("class HouseInfo(): ??") - test_method = "__init__" - class_init_arguments= ( - class_init_q.def_args_(test_method).match( + + my_class_arguments = ( + my_class.def_args_(test_method).match( { "type": "FunctionDef", "name": "__init__", @@ -42,28 +47,30 @@ def test_house_info_create_class_module2(parse): .exists() ) assert ( - class_init_arguments - ), """Are you defining a constructor for the `HouseInfo` class? - Are you declaring the correct name and number of parameters?""" + my_class_arguments + ), """Are you defining a constructor `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + # debug_test_case(my_method) # Check for assignment - self_data_exists = ( - class_init_q.def_args_(test_method).match( + test_code = ( + my_method.assign_().match( { - "body_0_type": "Assign", - "body_0_targets_0_type": "Attribute", - "body_0_targets_0_value_type": "Name", - "body_0_targets_0_value_id": "self", - "body_0_targets_0_attr": "data", - "body_0_value_type": "Name", - "body_0_value_id": "data", + "type": "Assign", + "targets_0_type": "Attribute", + "targets_0_value_type": "Name", + "targets_0_value_id": "self", + "targets_0_attr": "data", + "value_type": "Name", + "value_id": "data" } ) .exists() ) assert ( - self_data_exists - ), """Are you assigning the correct value to `self.data`?""" + test_code + ), "Are you creating a class attribute `self.data` and setting it equal to `data`?" @pytest.mark.test_house_info_get_data_by_area_module2 @@ -71,20 +78,29 @@ def test_house_info_get_data_by_area_module2(parse): # def get_data_by_area(self, field, rec_area=0): # field_data = [] - house_info = parse("house_info") - assert house_info.success, house_info.message + + test_file = "house_info" + test_class = "HouseInfo" + test_method = "get_data_by_area" - house_info_class = house_info.class_("HouseInfo") + my_file = parse(test_file) + assert my_file.success, my_file.message + + # my_class = house_info.class_(test_class) + my_class = my_file.query("class {}(): ??".format(test_class)) assert ( - house_info_class.exists() - ), "Have you created a class called `HouseInfo` in the `house_info.py` file?" + my_class.exists() + ), "Have you created a class called `{0}` in the `{1}` file?".format(test_class, test_file) - data_by_area = house_info.class_("HouseInfo").method("get_data_by_area") - assert data_by_area.exists(), "Are you defining a method called `get_data_by_area?" + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) - test_method = "get_data_by_area" - data_by_area_arguments= ( - house_info_class.def_args_(test_method).match( + my_class_arguments = ( + my_class.def_args_(test_method).match( { "type": "FunctionDef", "name": test_method, @@ -107,14 +123,13 @@ def test_house_info_get_data_by_area_module2(parse): .exists() ) assert ( - data_by_area_arguments - ), """Are you defining a method `get_data_by_area` - with the correct name and number of parameters? - Are you setting the third parameter's default value to zero?""" + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) - data_list = ( - data_by_area.assign_().match( + test_code = ( + my_method.assign_().match( { "type": "Assign", "targets_0_type": "Name", @@ -125,7 +140,7 @@ def test_house_info_get_data_by_area_module2(parse): .exists() ) assert ( - data_list + test_code ), "Are you creating a variable called `field_data` set equal to an empty list?" @@ -133,26 +148,34 @@ def test_house_info_get_data_by_area_module2(parse): def test_house_info_get_data_by_area_loop_module2(parse): # for record in self.data: - # if rec_area == int(record['area']): # select area + # if rec_area == 0: # field_data.append(record[field]) - # elif rec_area == 0: + # elif rec_area == int(record['area']): # field_data.append(record[field]) # return field_data - house_info = parse("house_info") - assert house_info.success, house_info.message + test_file = "house_info" + test_class = "HouseInfo" + test_method = "get_data_by_area" - house_info_class = house_info.class_("HouseInfo") + my_file = parse(test_file) + assert my_file.success, my_file.message + + # my_class = house_info.class_(test_class) + my_class = my_file.query("class {}(): ??".format(test_class)) assert ( - house_info_class.exists() - ), "Have you created a class called `HouseInfo` in the `house_info.py` file?" + my_class.exists() + ), "Have you created a class called `{0}` in the `{1}` file?".format(test_class, test_file) - data_by_area = house_info.class_("HouseInfo").method("get_data_by_area") - assert data_by_area.exists(), "Are you defining a method called `get_data_by_area?" + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) - test_method = "get_data_by_area" - first_for = ( - data_by_area.for_().match( + test_code = ( + my_method.for_().match( { "target_type": "Name", @@ -166,7 +189,7 @@ def test_house_info_get_data_by_area_loop_module2(parse): .exists() ) assert ( - first_for + test_code ), """Do you have a `for` loop, looping through `self.data`? Is the current loop value called `record`?""" @@ -210,25 +233,33 @@ def test_house_info_get_data_by_date_module2(parse): # def get_data_by_date(self, field, rec_date=date.today()): # field_data = [] - house_info = parse("house_info") - assert house_info.success, house_info.message - - house_info_import = house_info.from_imports( - "datetime", "date") - assert house_info_import, "Are you importing `date` from datetime?" + test_file = "house_info" + test_class = "HouseInfo" + test_method = "get_data_by_date" - house_info_class = house_info.class_("HouseInfo") + my_file = parse(test_file) + assert my_file.success, my_file.message + + # my_class = house_info.class_(test_class) + my_class = my_file.query("class {}(): ??".format(test_class)) assert ( - house_info_class.exists() - ), "Have you created a class called `HouseInfo` in the `house_info.py` file?" + my_class.exists() + ), "Have you created a class called `{0}` in the `{1}` file?".format(test_class, test_file) - data_by_date = house_info.class_("HouseInfo").method("get_data_by_date") - assert data_by_date.exists(), "Are you defining a method called `get_data_by_date?" - - test_method = "get_data_by_date" + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) - data_by_date_arguments= ( - house_info_class.def_args_(test_method).match( + # debug_test_case(my_method) + + house_info_import = my_file.from_imports( + "datetime", "date") + assert house_info_import, "Are you importing `date` from `datetime`?" + + + my_class_arguments = ( + my_class.def_args_(test_method).match( { "type": "FunctionDef", "name": test_method, @@ -254,16 +285,15 @@ def test_house_info_get_data_by_date_module2(parse): .exists() ) assert ( - data_by_date_arguments + my_class_arguments ), """Are you defining a method `get_data_by_date` with the correct name and number of parameters? - Are you setting the third parameter's default value to date.today()?""" + Are you setting the third parameter's default value to `date.today()`?""" - # print("1)", json.dumps(house_info_class.def_args_(test_method).n, indent=4)) # TODO Remove - print("2)", json.dumps(data_by_date.assign_().n, indent=4)) # TODO Remove - # assert False - data_list = ( - data_by_date.assign_().match( + # debug_test_case(my_method) + + test_code = ( + my_method.assign_().match( { "type": "Assign", "targets_0_type": "Name", @@ -274,7 +304,7 @@ def test_house_info_get_data_by_date_module2(parse): .exists() ) assert ( - data_list + test_code ), "Are you creating a variable called `field_data` set equal to an empty list?" @@ -285,22 +315,29 @@ def test_house_info_get_data_by_date_loop_module2(parse): # field_data.append(record[field]) # return field_data - house_info = parse("house_info") - assert house_info.success, house_info.message + test_file = "house_info" + test_class = "HouseInfo" + test_method = "get_data_by_date" - house_info_class = house_info.class_("HouseInfo") + my_file = parse(test_file) + assert my_file.success, my_file.message + + # my_class = house_info.class_(test_class) + my_class = my_file.query("class {}(): ??".format(test_class)) assert ( - house_info_class.exists() - ), "Have you created a class called `HouseInfo` in the `house_info.py` file?" - - test_method = "get_data_by_date" - data_by_date = house_info.class_("HouseInfo").method(test_method) - assert data_by_date.exists(), "Are you defining a method called `{}?".format(test_method) + my_class.exists() + ), "Have you created a class called `{0}` in the `{1}` file?".format(test_class, test_file) - # print(json.dumps(data_by_date.for_().n, indent=2)) # TODO + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + # assert False first_for = ( - data_by_date.for_().match( + my_method.for_().match( { "target_type": "Name", @@ -319,7 +356,7 @@ def test_house_info_get_data_by_date_loop_module2(parse): Is the current loop value called `record`?""" filter_recs = ( - data_by_date.for_().match( + my_method.for_().match( { "0_type": "If", "0_test_type": "Compare", @@ -390,28 +427,28 @@ def test_house_info_get_data_by_date_loop_module2(parse): and the second argument as `datetime` object with the format: "%m/%d/%Y" Check the logic inside your loop""" - # print("1)", json.dumps(house_info_class.def_args_(test_method).n, indent=4)) # TODO Remove - # print("2)", json.dumps(data_by_date.for_().n, indent=4)) # TODO Remove - # assert False - @pytest.mark.test_sensor_app_house_info_by_area_module2 -def test_sensor_app_load_house_info_by_area_module2(parse): +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))) + # print("House sensor records for area 1 = {}".format(len(recs))) # NOT TEST IT - sensor = parse("sensor_app") - assert sensor.success, sensor.message - - house_info_import = sensor.from_imports( + test_file = "sensor_app" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( "house_info", "HouseInfo") - assert house_info_import, "Are you importing `HouseInfo` from house_info?" + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) - house_info = ( - sensor.assign_().match( + # debug_test_case(my_file) + + test_code = ( + my_file.assign_().match( { "2_type": "Assign", "2_targets_0_type": "Name", @@ -426,13 +463,13 @@ def test_sensor_app_load_house_info_by_area_module2(parse): .exists() ) assert ( - house_info - ), """Are you creating an instance of the `class` HouseInfo with + test_code + ), """Are you creating an instance of the class `HouseInfo` with `data` list as the initialization argument for the constructor? """ - house_temp = ( - sensor.assign_().match( + test_code = ( + my_file.assign_().match( { "3_type": "Assign", "3_targets_0_type": "Name", @@ -453,59 +490,61 @@ def test_sensor_app_load_house_info_by_area_module2(parse): .exists() ) assert ( - house_temp - ), """Are you creating a variable `recs` and setting it to the return - value from `house_info.get_data_by_area()`? - Are you passing `area=1 or 2` as the second argument to the `get_data_by_area()` method?""" + test_code + ), """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?""" @pytest.mark.test_sensor_app_house_info_by_date_module2 -def test_sensor_app_load_house_info_by_date_module2(parse): +def test_sensor_app_house_info_by_date_module2(parse): # from datetime import date, datetime # ... - # rec_date = datetime.strptime("5/9/2020", "%m/%d/%Y") - # recs = house_info.get_data_by_date("id", rec_date) - # print("House sensor records for {} = {}".format(rec_date.date(), len(recs))) - - sensor = parse("sensor_app") - assert sensor.success, sensor.message + # 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 {} = {}".format(test_date.date(), len(recs))) # (NOT TEST IT) - datetime_import = sensor.from_imports( + test_file = "sensor_app" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( "datetime", "datetime") - assert datetime_import, "Are you importing `datetime` from datetime?" + assert my_file_import, "Are you importing `datetime` from `datetime` module?" - date_import = sensor.from_imports( + my_file_import = my_file.from_imports( "datetime", "date") - assert date_import, "Are you importing `date` from datetime?" - # print(json.dumps(sensor.assign_().n, indent=2)) - # assert False - - house_date = ( - sensor.assign_().match( + assert my_file_import, "Are you importing `datetime` 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": "rec_date", + "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/2020", + "4_value_args_0_value": "5/9/20", "4_value_args_1_type": "Constant", - "4_value_args_1_value": "%m/%d/%Y", + "4_value_args_1_value": "%m/%d/%y", } ) .exists() ) assert ( - house_date - ), """Are you creating an instance of the datetime class called `record_date` - which takes "5/9/2020" and "%m/%d/%Y" as the two arguments?""" + test_code + ), """Are you creating an instance of the `datetime` class called `record_date` + which takes `"5/9/20"` and `"%m/%d/%y"` as the two arguments?""" - house_temp = ( - sensor.assign_().match( + test_code = ( + my_file.assign_().match( { "5_type": "Assign", "5_targets_0_type": "Name", @@ -517,14 +556,17 @@ def test_sensor_app_load_house_info_by_date_module2(parse): "5_value_func_attr": "get_data_by_date", "5_value_args_0_type": "Constant", "5_value_args_0_value": "id", - "5_value_args_1_type": "Name", - "5_value_args_1_id": "rec_date" + "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" + } ) .exists() ) assert ( - house_temp - ), """Are you creating a variable `recs` and setting it to the return - value from `house_info.get_data_by_date()`? - Are you passing `area=1 or 2` as the second argument to the `get_data_by_area()` method?""" + test_code + ), """Are you creating a variable `recs` and setting it to `house_info.get_data_by_date()`? + Are you passing `"id"` as the first argument to the method? + Are you passing `rec_date=test_date` as the second argument to the method?""" diff --git a/tests/test_module3.py b/tests/test_module3.py new file mode 100644 index 00000000..974b0d82 --- /dev/null +++ b/tests/test_module3.py @@ -0,0 +1,542 @@ +import pytest +from tests.template import debug_test_case, debug_test_case_class + + +@pytest.mark.test_temperature_import_module3 +def test_temperature_import_module3(parse): + # from house_info import HouseInfo + + test_file = "temperature_info" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) + + +@pytest.mark.test_temperature_create_class_module3 +def test_temperature_create_class_module3(parse): + # class TemperatureData(HouseInfo): + # def _convert_data(self, data): + # data = [] + + test_file = "temperature_info" + parent_class = "HouseInfo" + test_class = "TemperatureData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "_convert_data", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "data", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + # Check for assignment + test_code = ( + my_method.assign_().match( + { + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "List" + } + ) + .exists() + ) + assert ( + test_code + ), "Are you creating a variable called `recs` set equal to an empty list?" + + +@pytest.mark.test_temperature_convert_loop_module3 +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)) + # return recs + + test_file = "temperature_info" + parent_class = "HouseInfo" + test_class = "TemperatureData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.for_().match( + { + "target_type": "Name", + "target_id": "rec", + "iter_type": "Name", + "iter_id": "data" + } + ) + .exists() + ) + assert ( + test_code + ), """Do you have a `for` loop, looping through `data`? + Is the current loop value called `rec`?""" + + test_code = ( + my_method.for_().match( + { + "0_type": "Expr", + "0_value_type": "Call", + "0_value_func_type": "Attribute", + "0_value_func_value_type": "Name", + "0_value_func_value_id": "recs", + "0_value_func_attr": "append", + "0_value_args_0_type": "Call", + "0_value_args_0_func_type": "Name", + "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 + } + ) + .exists() + ) + assert ( + test_code + ), """Inside your loop, are you converting `rec` value to integer based ten + Are you appending it to `recs` list?""" + + test_code= ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Name", + "value_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning `recs` list from the `{}` method?""".format(test_method) + + +@pytest.mark.test_temperature_by_area_method_module3 +def test_temperature_by_area_method_module3(parse): + # def get_data_by_area(self, rec_area=0): + # data = super().get_data_by_area("temperature", rec_area) + + test_file = "temperature_info" + parent_class = "HouseInfo" + test_class = "TemperatureData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_area", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_area", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Constant", + "args_defaults_0_value": 0, + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_area", + "value_args_0_type": "Constant", + "value_args_0_value": "temperature", + "value_args_1_type": "Name", + "value_args_1_id": "rec_area" + } + ) + .exists() + ) + assert ( + 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) + +@pytest.mark.test_temperature_by_area_method_return_module3 +def test_temperature_by_area_method_return_module3(parse): + # ... + # return self._convert_data(recs) + + test_file = "temperature_info" + parent_class = "HouseInfo" + test_class = "TemperatureData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + +@pytest.mark.test_temperature_by_date_method_module3 +def test_temperature_by_date_method_module3(parse): + # from datetime import date + # def get_data_by_date(self, rec_date=date.today()): + # recs = super().get_data_by_date("temperature", rec_date) + + test_file = "temperature_info" + parent_class = "HouseInfo" + test_class = "TemperatureData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "datetime", "date") + 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 ( + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_date", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_date", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Call", + "args_defaults_0_func_type": "Attribute", + "args_defaults_0_func_value_type": "Name", + "args_defaults_0_func_value_id": "date", + "args_defaults_0_func_attr": "today", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_date", + "value_args_0_type": "Constant", + "value_args_0_value": "temperature", + "value_args_1_type": "Name", + "value_args_1_id": "rec_date" + } + ) + .exists() + ) + assert ( + 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) + +@pytest.mark.test_temperature_by_date_method_return_module3 +def test_temperature_by_date_method_return_module3(parse): + # ... + # return self._convert_data(recs) + + test_file = "temperature_info" + parent_class = "HouseInfo" + test_class = "TemperatureData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + + +@pytest.mark.test_sensor_app_temp_info_by_area_module3 +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))) + # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} temperatures".format( max(recs), min(recs))) + + test_file = "sensor_app" + test_class = "TemperatureData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + 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) + + # 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", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating an instance of the '{}' class with + `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, + } + ) + .exists() + ) + 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? + """ + + +@pytest.mark.test_sensor_app_temp_info_by_date_module3 +def test_sensor_app_temp_info_by_date_module3(parse): + # ... + # recs = temperature_data.get_data_by_date(test_date) + # NOTE: print statements are not validated + # print("House Temperature sensor records for date: {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) + # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} temperatures".format(max(recs), min(recs), mean(recs))) + + test_file = "sensor_app" + test_class = "TemperatureData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + # debug_test_case(my_file) + + 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" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you setting `recs` to the method call `get_data_by_date` from the `temperature_data` object? + Are you passing `rec_date=test_date` as the only argument to the method? + """ diff --git a/tests/test_module4.py b/tests/test_module4.py new file mode 100644 index 00000000..c7096f05 --- /dev/null +++ b/tests/test_module4.py @@ -0,0 +1,1162 @@ +import pytest +from tests.template import debug_test_case, debug_test_case_class + + +@pytest.mark.test_humidity_import_module4 +def test_humidity_import_module4(parse): + # from house_info import HouseInfo + + test_file = "humidity_info" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) + + +@pytest.mark.test_humidity_create_class_module4 +def test_humidity_create_class_module4(parse): + # class HumidityData(HouseInfo): + # def _convert_data(self, data): + # recs = [] + + test_file = "humidity_info" + parent_class = "HouseInfo" + test_class = "HumidityData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "_convert_data", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "data", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + # Check for assignment + test_code = ( + my_method.assign_().match( + { + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "List" + } + ) + .exists() + ) + assert ( + test_code + ), "Are you creating a variable called `recs` set equal to an empty list?" + + +@pytest.mark.test_humidity_convert_loop_module4 +def test_humidity_convert_loop_module4(parse): + # for rec in data: + # # Convert string of integers into actual integers based 10 + # recs.append(float(rec) * 100) + # return recs + + test_file = "humidity_info" + parent_class = "HouseInfo" + test_class = "HumidityData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.for_().match( + { + "target_type": "Name", + "target_id": "rec", + "iter_type": "Name", + "iter_id": "data" + } + ) + .exists() + ) + assert ( + test_code + ), """Do you have a `for` loop, looping through `data`? + Is the current loop value called `rec`?""" + + test_code = ( + my_method.for_().match( + { + "0_type": "Expr", + "0_value_type": "Call", + "0_value_func_type": "Attribute", + "0_value_func_value_type": "Name", + "0_value_func_value_id": "recs", + "0_value_func_attr": "append", + "0_value_args_0_type": "BinOp", + "0_value_args_0_left_type": "Call", + "0_value_args_0_left_func_type": "Name", + "0_value_args_0_left_func_id": "float", + "0_value_args_0_left_args_0_type": "Name", + "0_value_args_0_left_args_0_id": "rec", + "0_value_args_0_op_type": "Mult", + "0_value_args_0_right_type": "Constant", + "0_value_args_0_right_value": 100 + } + ) + .exists() + ) + assert ( + test_code + ), """Inside your loop, are you converting `rec` value to `float()` and multipling it by `100` + Are you appending it to `recs` list?""" + + test_code= ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Name", + "value_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning `recs` list from the `{}` method?""".format(test_method) + + +@pytest.mark.test_humidity_by_area_method_module4 +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) + + test_file = "humidity_info" + parent_class = "HouseInfo" + test_class = "HumidityData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_area", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_area", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Constant", + "args_defaults_0_value": 0, + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_area", + "value_args_0_type": "Constant", + "value_args_0_value": "humidity", + "value_args_1_type": "Name", + "value_args_1_id": "rec_area" + } + ) + .exists() + ) + assert ( + 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) + + +@pytest.mark.test_humidity_by_area_method_return_module4 +def test_humidity_by_area_method_return_module4(parse): + # ... + # return self._convert_data(recs) + + test_file = "humidity_info" + parent_class = "HouseInfo" + test_class = "HumidityData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + + +@pytest.mark.test_humidity_by_date_method_module4 +def test_humidity_by_date_method_module4(parse): + # from datetime import date + # def get_data_by_date(self, rec_date=date.today()): + # recs = super().get_data_by_date("humidity", rec_date) + + test_file = "humidity_info" + parent_class = "HouseInfo" + test_class = "HumidityData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "datetime", "date") + 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 ( + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_date", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_date", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Call", + "args_defaults_0_func_type": "Attribute", + "args_defaults_0_func_value_type": "Name", + "args_defaults_0_func_value_id": "date", + "args_defaults_0_func_attr": "today", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_date", + "value_args_0_type": "Constant", + "value_args_0_value": "humidity", + "value_args_1_type": "Name", + "value_args_1_id": "rec_date" + } + ) + .exists() + ) + assert ( + 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) + + +@pytest.mark.test_humidity_by_date_method_return_module4 +def test_humidity_by_date_method_return_module4(parse): + # ... + # return self._convert_data(recs) + + test_file = "humidity_info" + parent_class = "HouseInfo" + test_class = "HumidityData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + + +@pytest.mark.test_sensor_app_temp_info_by_area_module4 +def test_sensor_app_temp_info_by_area_module4(parse): + # from humidity_info import HumidityData # module 4 + # 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("House Humidity sensor records for area 1 = {}".format(len(recs))) + # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} temperatures".format( max(recs), min(recs), mean(recs))) + + test_file = "sensor_app" + test_class = "HumidityData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + 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) + + 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) + + 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", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating an instance of the '{}' class with + `data` list as the initialization argument for the constructor? + """.format(test_class) + + 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, + } + ) + .exists() + ) + 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? + """ + + my_file_import = my_file.from_imports( + "statistics", "mean") + assert my_file_import, "Are you importing `mean` from `statistics` in `{}`".format(test_file) + + +@pytest.mark.test_sensor_app_temp_info_by_date_module4 +def test_sensor_app_temp_info_by_date_module4(parse): + # ... + # recs = humidity_data.get_data_by_date(test_date) + # NOTE: print statements are not validated + # print("House Humidity sensor records for date: {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) + # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} humiditys".format(max(recs), min(recs), mean(recs))) + + test_file = "sensor_app" + test_class = "HumidityData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + # debug_test_case(my_file) + + 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" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you setting `recs` to the method call `get_data_by_date` from the `humidity_data` object? + Are you passing `rec_date=test_date` as the only argument to the method? + """ + + +@pytest.mark.test_particle_import_module4 +def test_particle_import_module4(parse): + # from house_info import HouseInfo + + test_file = "particle_count_info" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) + + +@pytest.mark.test_particle_create_class_module4 +def test_particle_create_class_module4(parse): + # class ParticleData(HouseInfo): + # def _convert_data(self, data): + # recs = [] + + test_file = "particle_count_info" + parent_class = "HouseInfo" + test_class = "ParticleData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "_convert_data", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "data", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + # Check for assignment + test_code = ( + my_method.assign_().match( + { + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "List" + } + ) + .exists() + ) + assert ( + test_code + ), "Are you creating a variable called `recs` set equal to an empty list?" + + +@pytest.mark.test_particle_convert_loop_module4 +def test_particle_convert_loop_module4(parse): + # for rec in data: + # # Convert string of integers into actual integers based 10 + # recs.append(float(rec)) + # return recs + + test_file = "particle_count_info" + parent_class = "HouseInfo" + test_class = "ParticleData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.for_().match( + { + "target_type": "Name", + "target_id": "rec", + "iter_type": "Name", + "iter_id": "data" + } + ) + .exists() + ) + assert ( + test_code + ), """Do you have a `for` loop, looping through `data`? + Is the current loop value called `rec`?""" + + test_code = ( + my_method.for_().match( + { + "0_type": "Expr", + "0_value_type": "Call", + "0_value_func_type": "Attribute", + "0_value_func_value_type": "Name", + "0_value_func_value_id": "recs", + "0_value_func_attr": "append", + "0_value_args_0_type": "Call", + "0_value_args_0_func_type": "Name", + "0_value_args_0_func_id": "float", + "0_value_args_0_args_0_type": "Name", + "0_value_args_0_args_0_id": "rec" + } + ) + .exists() + ) + assert ( + test_code + ), """Inside your loop, are you converting `rec` value to `float()` + Are you appending it to `recs` list?""" + + test_code= ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Name", + "value_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning `recs` list from the `{}` method?""".format(test_method) + + +@pytest.mark.test_particle_by_area_method_module4 +def test_particle_by_area_method_module4(parse): + # def get_data_by_area(self, rec_area=0): + # data = super().get_data_by_area("particle", rec_area) + + test_file = "particle_count_info" + parent_class = "HouseInfo" + test_class = "ParticleData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_area", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_area", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Constant", + "args_defaults_0_value": 0, + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_area", + "value_args_0_type": "Constant", + "value_args_0_value": "particulate", + "value_args_1_type": "Name", + "value_args_1_id": "rec_area" + } + ) + .exists() + ) + assert ( + 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) + + +@pytest.mark.test_particle_by_area_method_return_module4 +def test_particle_by_area_method_return_module4(parse): + # ... + # return self._convert_data(recs) + + test_file = "particle_count_info" + parent_class = "HouseInfo" + test_class = "ParticleData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + + +@pytest.mark.test_particle_by_date_method_module4 +def test_particle_by_date_method_module4(parse): + # from datetime import date + # def get_data_by_date(self, rec_date=date.today()): + # recs = super().get_data_by_date("particle", rec_date) + + test_file = "particle_count_info" + parent_class = "HouseInfo" + test_class = "ParticleData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "datetime", "date") + 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 ( + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_date", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_date", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Call", + "args_defaults_0_func_type": "Attribute", + "args_defaults_0_func_value_type": "Name", + "args_defaults_0_func_value_id": "date", + "args_defaults_0_func_attr": "today", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_date", + "value_args_0_type": "Constant", + "value_args_0_value": "particulate", + "value_args_1_type": "Name", + "value_args_1_id": "rec_date" + } + ) + .exists() + ) + assert ( + 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) + + +@pytest.mark.test_particle_by_date_method_return_module4 +def test_particle_by_date_method_return_module4(parse): + # ... + # return self._convert_data(recs) + + test_file = "particle_count_info" + parent_class = "HouseInfo" + test_class = "ParticleData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + + +@pytest.mark.test_sensor_app_temp_info_by_area_module4 +def test_sensor_app_temp_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) + # NOTE: print statements are not validated + # print("House Humidity sensor records for area 1 = {}".format(len(recs))) + # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} temperatures".format( max(recs), min(recs), mean(recs))) + + test_file = "sensor_app" + test_class = "ParticleData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "particle_count_info", "ParticleData") + assert my_file_import, "Are you importing `ParticleData` from `particle_count_info` in `{}`".format(test_file) + + # debug_test_case(my_file) + + 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", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating an instance of the '{}' class with + `data` list as the initialization argument for the constructor? + """.format(test_class) + + 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, + } + ) + .exists() + ) + 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? + """ + + test_code = ( + my_file.assign_().match( + { + "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_concentrations", + "14_value_keywords_0_type": "keyword", + "14_value_keywords_0_arg": "data", + "14_value_keywords_0_value_type": "Call", + "14_value_keywords_0_value_func_type": "Attribute", + "14_value_keywords_0_value_func_value_type": "Name", + "14_value_keywords_0_value_func_value_id": "particle_data", + "14_value_keywords_0_value_func_attr": "get_data_by_area", + "14_value_keywords_0_value_keywords_0_type": "keyword", + "14_value_keywords_0_value_keywords_0_arg": "rec_area", + "14_value_keywords_0_value_keywords_0_value_type": "Constant", + "14_value_keywords_0_value_keywords_0_value_value": 1, + } + ) + .exists() + ) + assert ( + test_code + ), """Are you setting `recs` to the method call `get_data_concentration` from the `particle_data` object? + Are you passing another method call `get_data_by_area` from the same `particle_data` object as the input parameter? + Are you passing `"rec_area=1"` as the only argument to the `get_data_by_area` method? + """ + + +@pytest.mark.test_sensor_app_temp_info_by_date_module4 +def test_sensor_app_temp_info_by_date_module4(parse): + # ... + # recs = particle_data.get_data_by_date(test_date) + # NOTE: print statements are not validated + # print("House Humidity sensor records for date: {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) + # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} particles".format(max(recs), min(recs), mean(recs))) + + test_file = "sensor_app" + test_class = "ParticleData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + # debug_test_case(my_file) + # + 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", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you setting `recs` to the method call `get_data_by_date` from the `particle_data` object? + Are you passing `rec_date=test_date` as the only argument to the method? + """ + + test_code = ( + my_file.assign_().match( + { + "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_concentrations", + "16_value_keywords_0_type": "keyword", + "16_value_keywords_0_arg": "data", + "16_value_keywords_0_value_type": "Call", + "16_value_keywords_0_value_func_type": "Attribute", + "16_value_keywords_0_value_func_value_type": "Name", + "16_value_keywords_0_value_func_value_id": "particle_data", + "16_value_keywords_0_value_func_attr": "get_data_by_date", + "16_value_keywords_0_value_keywords_0_type": "keyword", + "16_value_keywords_0_value_keywords_0_arg": "rec_date", + "16_value_keywords_0_value_keywords_0_value_type": "Name", + "16_value_keywords_0_value_keywords_0_value_id": "test_date" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you setting `recs` to the method call `get_data_by_date` from the `particle_data` object? + Are you passing `rec_date=test_date` as the only argument to the method? + """ diff --git a/tests/test_module5.py b/tests/test_module5.py new file mode 100644 index 00000000..70322d90 --- /dev/null +++ b/tests/test_module5.py @@ -0,0 +1,895 @@ +import pytest +from tests.template import debug_test_case, debug_test_case_class + + +@pytest.mark.test_energy_import_module5 +def test_energy_import_module5(parse): + # from house_info import HouseInfo + + test_file = "energy_info" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) + + +@pytest.mark.test_energy_create_class_module5 +def test_energy_create_class_module5(parse): + # class EnergyData(HouseInfo): + # def _convert_data(self, data): + # recs = [] + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "_convert_data", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "data", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + # Check for assignment + test_code = ( + my_method.assign_().match( + { + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "List" + } + ) + .exists() + ) + assert ( + test_code + ), "Are you creating a variable called `recs` set equal to an empty list?" + + +@pytest.mark.test_energy_convert_loop_module5 +def test_energy_convert_loop_module5(parse): + # for rec in data: + # # Convert string of integers into actual integers based 16 + # recs.append(self._get_energy(rec)) + # return recs + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.for_().match( + { + "target_type": "Name", + "target_id": "rec", + "iter_type": "Name", + "iter_id": "data" + } + ) + .exists() + ) + assert ( + test_code + ), """Do you have a `for` loop, looping through `data`? + Is the current loop value called `rec`?""" + + test_code = ( + my_method.for_().match( + { + "0_type": "Expr", + "0_value_type": "Call", + "0_value_func_type": "Attribute", + "0_value_func_value_type": "Name", + "0_value_func_value_id": "recs", + "0_value_func_attr": "append", + "0_value_args_0_type": "Call", + "0_value_args_0_func_type": "Attribute", + "0_value_args_0_func_value_type": "Name", + "0_value_args_0_func_value_id": "self", + "0_value_args_0_func_attr": "_get_energy", + "0_value_args_0_args_0_type": "Name", + "0_value_args_0_args_0_id": "rec" + } + ) + .exists() + ) + assert ( + test_code + ), """Inside your loop, are you converting `rec` value through `self._rec_energy()` method? + Are you appending it to `recs` list?""" + + test_code= ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Name", + "value_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning `recs` list from the `{}` method?""".format(test_method) + + +@pytest.mark.test_energy_class_variables_module5 +def test_energy_class_variables_module5(parse): + # ENERGY_PER_BULB = 0.2 # in watts + # ENERGY_BITS = 0x0F0 + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "_convert_data" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + # debug_test_case(my_class) + + test_code = ( + my_class.assign_().match( + { + "0_type": "Assign", + "0_targets_0_type": "Name", + "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", + "1_value_type": "Constant", + "1_value_value": 240 + } + ) + .exists() + ) + assert ( + test_code + ), """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 + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "_get_energy" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "_get_energy", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + # Check for assignment + test_code = ( + my_method.assign_().match( + { + "0_type": "Assign", + "0_targets_0_type": "Name", + "0_targets_0_id": "rec", + "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, + } + ) + .exists() + ) + assert ( + test_code + ), "Are you converting `rec` by casting it as an `int()` with base `16`?" + + test_code = ( + my_method.assign_().match( + { + "1_type": "Assign", + "1_targets_0_type": "Name", + "1_targets_0_id": "rec", + "1_value_type": "BinOp", + "1_value_left_type": "Name", + "1_value_left_id": "rec", + "1_value_op_type": "BitAnd", + "1_value_right_type": "Attribute", + "1_value_right_value_type": "Name", + "1_value_right_value_id": "self", + "1_value_right_attr": "ENERGY_BITS", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you converting `rec` 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_value_type": "BinOp", + "2_value_left_type": "Name", + "2_value_left_id": "rec", + "2_value_op_type": "RShift", + "2_value_right_type": "Constant", + "2_value_right_value": 4 + } + ) + .exists() + ) + assert ( + test_code + ), """Are you converting `rec` by shifting the bits to the right 4 positions?""" + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Name", + "value_id": "rec" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning `recs` from the `{}` method?""".format(test_method) + + +@pytest.mark.test_energy_by_area_method_module5 +def test_energy_by_area_method_module5(parse): + # def get_data_by_area(self, rec_area=0): + # data = super().get_data_by_area("energy", rec_area) + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_area", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_area", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Constant", + "args_defaults_0_value": 0, + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_area", + "value_args_0_type": "Constant", + "value_args_0_value": "energy_usage", + "value_args_1_type": "Name", + "value_args_1_id": "rec_area" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating a variable called `recs` set equal to + the `{}` method from the `{}` parent class? + Are you passing "energy" as the only argument to the method call?""".format(test_method, parent_class) + +@pytest.mark.test_energy_by_area_method_return_module5 +def test_energy_by_area_method_return_module5(parse): + # ... + # return self._convert_data(recs) + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "get_data_by_area" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + +@pytest.mark.test_energy_by_date_method_module5 +def test_energy_by_date_method_module5(parse): + # from datetime import date + # def get_data_by_date(self, rec_date=date.today()): + # recs = super().get_data_by_date("energy", rec_date) + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "datetime", "date") + 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 ( + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_date", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_date", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Call", + "args_defaults_0_func_type": "Attribute", + "args_defaults_0_func_value_type": "Name", + "args_defaults_0_func_value_id": "date", + "args_defaults_0_func_attr": "today", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_date", + "value_args_0_type": "Constant", + "value_args_0_value": "energy_usage", + "value_args_1_type": "Name", + "value_args_1_id": "rec_date" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating a variable called `recs` set equal to + the `{}` method from the `{}` parent class? + Are you passing "energy" as the only argument to the method call?""".format(test_method, parent_class) + +@pytest.mark.test_energy_by_date_method_return_module5 +def test_energy_by_date_method_return_module5(parse): + # ... + # return self._convert_data(recs) + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "get_data_by_date" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + + +@pytest.mark.test_energy_calculate_usage_method_module5 +def test_energy_calculate_usage_method_module5(parse): + # def calculate_energy_usage(self, data): + # total_energy = sum([field * self.ENERGY_PER_BULB for field in data]) + # return total_energy + + test_file = "energy_info" + parent_class = "HouseInfo" + test_class = "EnergyData" + test_method = "calculate_energy_usage" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "datetime", "date") + 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 ( + 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) + + # debug_test_case_class(my_class, test_method) + + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "calculate_energy_usage", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "data", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "total_energy", + "value_type": "Call", + "value_func_type": "Name", + "value_func_id": "sum", + "value_args_0_type": "ListComp", + "value_args_0_elt_type": "BinOp", + "value_args_0_elt_left_type": "Name", + "value_args_0_elt_left_id": "field", + "value_args_0_elt_op_type": "Mult", + "value_args_0_elt_right_type": "Attribute", + "value_args_0_elt_right_value_type": "Name", + "value_args_0_elt_right_value_id": "self", + "value_args_0_elt_right_attr": "ENERGY_PER_BULB", + "value_args_0_generators_0_type": "comprehension", + "value_args_0_generators_0_target_type": "Name", + "value_args_0_generators_0_target_id": "field", + "value_args_0_generators_0_iter_type": "Name", + "value_args_0_generators_0_iter_id": "data", + "value_args_0_generators_0_is_async": 0 + } + ) + .exists() + ) + assert ( + test_code + ), """Are you declaring a variable called `total_energy`? + Are you setting it to `sum()` built it function? + Are you passing a `list comprehension` as an argument to `sum()`? + Are you setting `field * self.ENERGY_PER_BULB` as you `list comprehension` expression? + Are you iterating over `data` in your `list comprehension`? + """ + + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Name", + "value_id": "total_energy" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a `total_energy` from the `{}` method?""".format(test_method) + + +@pytest.mark.test_sensor_app_temp_info_by_area_module5 +def test_sensor_app_temp_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) + # NOTE: print statements are not validated + # print("House Humidity sensor records for area 1 = {}".format(len(recs))) + + test_file = "sensor_app" + test_class = "EnergyData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_file_import = my_file.from_imports( + "energy_info", "EnergyData") + assert my_file_import, "Are you importing `EnergyData` from `energy_info` in `{}`".format(test_file) + + # debug_test_case(my_file) + + 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", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating an instance of the '{}' class with + `data` list as the initialization argument for the constructor? + """.format(test_class) + + 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 + } + ) + .exists() + ) + 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? + """ + + 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_args_0_type": "Name", + "19_value_args_0_id": "recs", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you setting `total_energy` to the method call `calculate_energy_usage` from the `energy_data` object? + Are you passing `recs` as the only argument to the method? + """ + + +@pytest.mark.test_sensor_app_temp_info_by_date_module5 +def test_sensor_app_temp_info_by_date_module5(parse): + # ... + # recs = energy_data.get_data_by_date(test_date) + # NOTE: print statements are not validated + # print("House Humidity sensor records for date: {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) + # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} energys".format(max(recs), min(recs), mean(recs))) + + test_file = "sensor_app" + test_class = "EnergyData" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + # debug_test_case(my_file) + + 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", + } + ) + .exists() + ) + assert ( + test_code + ), """Are you setting `recs` to the method call `get_data_by_date` from the `energy_data` object? + Are you passing `rec_date=test_date` as the only argument to the method? + """ + + 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_args_0_type": "Call", + "21_value_args_0_func_type": "Attribute", + "21_value_args_0_func_value_type": "Name", + "21_value_args_0_func_value_id": "energy_data", + "21_value_args_0_func_attr": "get_data_by_date", + "21_value_args_0_keywords_0_type": "keyword", + "21_value_args_0_keywords_0_arg": "rec_date", + "21_value_args_0_keywords_0_value_type": "Name", + "21_value_args_0_keywords_0_value_id": "test_date" + } + ) + .exists() + ) + 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? + """ From 4ae53ba0ff05f1e89935d826bcce78fd8c687a53 Mon Sep 17 00:00:00 2001 From: Hugo Valle Date: Tue, 19 May 2020 11:22:01 -0600 Subject: [PATCH 2/7] Remove tasks details --- tasks.md | 137 ------------------------------------------------------- 1 file changed, 137 deletions(-) delete mode 100644 tasks.md diff --git a/tasks.md b/tasks.md deleted file mode 100644 index 215574ff..00000000 --- a/tasks.md +++ /dev/null @@ -1,137 +0,0 @@ -# Module 1 - The Sensor Class - -- [Module 1 - The Sensor Class](#module-1---the-sensor-class) - - [Status](#status) - - [Module 1: Load Sensor Data From Files](#module-1-load-sensor-data-from-files) - - [M1: Task 1: Import os, glob, and csv](#m1-task-1-import-os-glob-and-csv) - - [M1: Task 2: Create a Function to parse the data](#m1-task-2-create-a-function-to-parse-the-data) - - [M1: Task 3: Sensor Data File Management](#m1-task-3-sensor-data-file-management) - - [M1: Task 4: Read Data Files](#m1-task-4-read-data-files) - - [M1: Task 5: Get Sensor Data with sensor_app](#m1-task-5-get-sensor-data-with-sensorapp) - - [Module 2: Create a Class HomeData](#module-2-create-a-class-homedata) - - [Module 3: Analyze Temperature Data](#module-3-analyze-temperature-data) - - [Module 4: Analyze Humidity Data](#module-4-analyze-humidity-data) - - [Module 5: Analyze Air Quality Data](#module-5-analyze-air-quality-data) - - [Module 6: Analyze Energy Consumption Data](#module-6-analyze-energy-consumption-data) - -## Status - -Draft. - -## Module 1: Load Sensor Data From Files - -### M1: Task 1: Import os, glob, and csv - -[//]:# (@pytest.mark.test_load_data_import_module1) - -The dataset for this project is stored in several CSV files found in the `dataset` folder. It represents the data collected from a device with multiple sensors. The records include measurements of temperature, humidity, energy consumption, and particle count in the air over a given area. The data is collected over a period of 24 hours. - -To start, open the file called `load_data.py` in the `sensor` folder - the rest of the tasks in this module happen in this same file. - -At the top of the file create three import statements for `os`, `glob`, and `csv`. These libraries will allow us to work with a collection of files. - ---- -To test this module locally: - -- Open a terminal at the root of the project -- Run the command `pytest -k module1` - -### M1: Task 2: Create a Function to parse the data - -[//]:# (@pytest.mark.test_load_data_load_sensor_func_module1) - -Create a function called `load_sensor_data` that takes no arguments. -In the body of the `load_sensor_data` function, create variable called `sensor_data` and set it as an empty `list`. - ---- -To test this module locally: - -- Open a terminal at the root of the project -- Run the command `pytest -k module1` - -### M1: Task 3: Sensor Data File Management - -[//]:# (@pytest.mark.test_load_data_sensor_files_module1) - -Next, create a variable called `sensor_files` that is set to a call to the `glob.glob()` function. - -Pass the glob function a single argument, a call to the `os.path.join()` function. - -In turn pass `os.path.join()` three arguments: `os.getcwd()`, `"datasets"`, and `"*.csv"`. - -Your statement should look like this: - -```python - sensor_files = glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv')) -``` - ---- -To test this module locally: - -- Open a terminal at the root of the project -- Run the command `pytest -k module1` - -### M1: Task 4: Read Data Files - -[//]:# (@pytest.mark.test_load_data_read_files_module1) - -The `sensor_files` object contains a list of file names i.e. ['SENSOR_ROOM2', 'SENSOR_ROOM1'] - -To read the sensor data of these files, five steps are required: - -1) Create one `for` loop that loops through `sensor_files` using `sensor_file` as the iterator variable. - -2) In the body of this loop use a `with` statement to `open` the `sensor_file` and set the alias to `data_file`. - -3) In the `with` body, set a variable called `data_reader` equal to `csv.DictReader()`. Pass in the current `data_file` as the first argument, and set the `delimiter=','` as the second argument. The `data_reader` will contain a list of dictionaries with the sensor data. - -4) Create a second `for` loop to `data_file` to get access to each record. Use `row` as your iterator variable. - -5) Inside the body of the second `for` loop, append each `row` record to the `sensor_data` list created on `Task 2` - -Finally, your function should return `sensor_data` list containing a list of dictionaries. - ---- -To test this module locally: - -- Open a terminal at the root of the project -- Run the command `pytest -k module1` - -### M1: Task 5: Get Sensor Data with sensor_app - -[//]:# (@pytest.mark.test_sensor_app_load_data_return_module1) -oLet's set up the command line interface (CLI). Open the `sensor_app.py` file in the `sensor` directory of the project. - -At the top, from the `load_data` module, `import` the `load_sensor_data` function. - -Define variable called `data` and set it equal to `load_sensor_data()`. - -Print the length of the `data` list using `formatted` print. Your output should look like this: - -```bash -Loaded records: [2000] -``` - ---- -To test this task locally: - -- Open a terminal at the root of the project -- Run the command `python sensor/sensor_app.py` - ---- -To test this module locally: - -- Open a terminal at the root of the project -- Run the command `pytest -k module1` - -- - -## Module 2: Create a Class HomeData - -## Module 3: Analyze Temperature Data - -## Module 4: Analyze Humidity Data - -## Module 5: Analyze Air Quality Data - -## Module 6: Analyze Energy Consumption Data From 4ecb5e0b6130fbe395f72cb770a282913cf300d8 Mon Sep 17 00:00:00 2001 From: Hugo Valle Date: Tue, 19 May 2020 12:51:57 -0600 Subject: [PATCH 3/7] Add debug functions --- tests/template.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/template.py b/tests/template.py index 24951cd2..4fd59bf6 100644 --- a/tests/template.py +++ b/tests/template.py @@ -1,6 +1,7 @@ import os.path import warnings import ast +import json from tests.nodes import convert_node @@ -563,3 +564,23 @@ def is_ast_equal(sample, template): return True except TemplateMismatch: return False + + +def debug_test_case(node): + """Print JSON parser nodes + + Arguments: + node {[type]} -- [description] + """ + print(json.dumps(node.assign_().n, indent=4)) + print(json.dumps(node.for_().n, indent=4)) + print(json.dumps(node.returns_call().n, indent=4)) + + +def debug_test_case_class(node, test_method): + """Print JSON parser nodes for class properties + + Arguments: + node {[type]} -- [description] + """ + print(json.dumps(node.def_args_(test_method).n, indent=4)) \ No newline at end of file From 904e8df8cc7190b17f2c0ae86aaacd56bee3639a Mon Sep 17 00:00:00 2001 From: Hugo Valle Date: Tue, 19 May 2020 13:44:42 -0600 Subject: [PATCH 4/7] Update load_sensor_data testing --- tests/test_module1.py | 9 ++++++--- tests/test_module2.py | 14 +++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_module1.py b/tests/test_module1.py index 2f65e70f..ea8e0729 100644 --- a/tests/test_module1.py +++ b/tests/test_module1.py @@ -1,7 +1,11 @@ import pytest import json -from sensor.load_data import load_sensor_data as lsd +try: + from sensor.load_data import load_sensor_data + recs = load_sensor_data() +except ImportError: + recs = 0 @pytest.mark.test_load_data_import_module1 def test_load_data_import_module1(parse): @@ -314,8 +318,7 @@ def test_load_data_load_recs_module1(parse): ), 'Are you returning `sensor_data` from `load_sensor_data` function?' # Test Length of return value - # data_len = load_sensor_data() - data_len = lsd() + # recs = load_sensor_data() # this is defined above assert ( len(data_len) == 2000 ), """The length of your sensor_data list is incorrect. diff --git a/tests/test_module2.py b/tests/test_module2.py index 50ce185e..41b1366f 100644 --- a/tests/test_module2.py +++ b/tests/test_module2.py @@ -1,9 +1,13 @@ import pytest from tests.template import debug_test_case, debug_test_case_class -import sensor.load_data -import sensor.house_info -from datetime import date, datetime +try: + from sensor.load_data import load_sensor_data + recs = load_sensor_data() +except ImportError: + recs = 0 + +from datetime import date, datetime @pytest.mark.test_house_info_create_class_module2 def test_house_info_create_class_module2(parse): @@ -195,7 +199,7 @@ def test_house_info_get_data_by_area_loop_module2(parse): # Test filer options: - recs = sensor.load_data.load_sensor_data() + # recs = sensor.load_data.load_sensor_data() # defined at top of file home_info = sensor.house_info.HouseInfo(recs) home_temp = home_info.get_data_by_area("id") assert ( @@ -400,7 +404,7 @@ def test_house_info_get_data_by_date_loop_module2(parse): # Test filer options: - recs = sensor.load_data.load_sensor_data() + # recs = sensor.load_data.load_sensor_data() # defined at top of file home_info = sensor.house_info.HouseInfo(recs) home_temp = home_info.get_data_by_date("id") assert ( From 57d8b19090a7f9f8dfe1936beafbac6c40350fd4 Mon Sep 17 00:00:00 2001 From: Hugo Valle Date: Tue, 19 May 2020 15:28:33 -0600 Subject: [PATCH 5/7] Remove duplicate test tags --- tests/test_module4.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_module4.py b/tests/test_module4.py index c7096f05..15cb360b 100644 --- a/tests/test_module4.py +++ b/tests/test_module4.py @@ -986,8 +986,8 @@ def test_particle_by_date_method_return_module4(parse): Passing `recs` as the only argument?""".format(test_method) -@pytest.mark.test_sensor_app_temp_info_by_area_module4 -def test_sensor_app_temp_info_by_area_module4(parse): +@pytest.mark.test_sensor_app_particle_info_by_area_module4 +def test_sensor_app_particle_info_by_area_module4(parse): # from particle_count_info import ParticleData # module 4 # ... # particle_data = ParticleData(data) @@ -1088,8 +1088,8 @@ def test_sensor_app_temp_info_by_area_module4(parse): """ -@pytest.mark.test_sensor_app_temp_info_by_date_module4 -def test_sensor_app_temp_info_by_date_module4(parse): +@pytest.mark.test_sensor_app_particle_info_by_date_module4 +def test_sensor_app_particle_info_by_date_module4(parse): # ... # recs = particle_data.get_data_by_date(test_date) # NOTE: print statements are not validated From 4f807d7a8713815c3fd835e3313dcc400d85afa3 Mon Sep 17 00:00:00 2001 From: Hugo Valle Date: Thu, 21 May 2020 10:10:26 -0600 Subject: [PATCH 6/7] fix impor errors --- tests/test_module1.py | 2 +- tests/test_module2.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_module1.py b/tests/test_module1.py index ea8e0729..003e98c4 100644 --- a/tests/test_module1.py +++ b/tests/test_module1.py @@ -320,7 +320,7 @@ def test_load_data_load_recs_module1(parse): # Test Length of return value # recs = load_sensor_data() # this is defined above assert ( - len(data_len) == 2000 + len(recs) == 2000 ), """The length of your sensor_data list is incorrect. Are you scanning both data files?""" diff --git a/tests/test_module2.py b/tests/test_module2.py index 41b1366f..5436ee8d 100644 --- a/tests/test_module2.py +++ b/tests/test_module2.py @@ -7,6 +7,12 @@ except ImportError: recs = 0 +try: + from sensor.house_info import HouseInfo + home_info = HouseInfo(recs) +except ImportError: + home_info = 0 + from datetime import date, datetime @pytest.mark.test_house_info_create_class_module2 @@ -200,7 +206,7 @@ def test_house_info_get_data_by_area_loop_module2(parse): # Test filer options: # recs = sensor.load_data.load_sensor_data() # defined at top of file - home_info = sensor.house_info.HouseInfo(recs) + home_info = HouseInfo(recs) home_temp = home_info.get_data_by_area("id") assert ( len(home_temp) == 2000 @@ -404,8 +410,8 @@ def test_house_info_get_data_by_date_loop_module2(parse): # Test filer options: - # recs = sensor.load_data.load_sensor_data() # defined at top of file - home_info = sensor.house_info.HouseInfo(recs) + # recs = load_sensor_data() # defined at top of file + home_info = HouseInfo(recs) home_temp = home_info.get_data_by_date("id") assert ( len(home_temp) == 0 From 49b5a8f2bf3222e2ac506470db7f552ae5e6f3fb Mon Sep 17 00:00:00 2001 From: Hugo Valle Date: Thu, 21 May 2020 16:49:10 -0600 Subject: [PATCH 7/7] Merger module 4 and 5 changes --- tests/test_module4.py | 382 ++++++++++++++++++------------------- tests/test_module5.py | 435 ++++++++++++++++-------------------------- 2 files changed, 355 insertions(+), 462 deletions(-) diff --git a/tests/test_module4.py b/tests/test_module4.py index 15cb360b..ba5349aa 100644 --- a/tests/test_module4.py +++ b/tests/test_module4.py @@ -2,22 +2,9 @@ from tests.template import debug_test_case, debug_test_case_class -@pytest.mark.test_humidity_import_module4 -def test_humidity_import_module4(parse): - # from house_info import HouseInfo - - test_file = "humidity_info" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_file_import = my_file.from_imports( - "house_info", "HouseInfo") - assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) - - @pytest.mark.test_humidity_create_class_module4 def test_humidity_create_class_module4(parse): + # from house_info import HouseInfo # class HumidityData(HouseInfo): # def _convert_data(self, data): # recs = [] @@ -30,6 +17,10 @@ def test_humidity_create_class_module4(parse): my_file = parse(test_file) assert my_file.success, my_file.message + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) assert ( my_class.exists() @@ -169,9 +160,10 @@ def test_humidity_convert_loop_module4(parse): @pytest.mark.test_humidity_by_area_method_module4 -def test_humidity_by_area_method_module4(parse): +def test_humidity_by_area_and_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) test_file = "humidity_info" parent_class = "HouseInfo" @@ -247,35 +239,6 @@ def test_humidity_by_area_method_module4(parse): the `{}` method from the `{}` parent class? Are you passing "humidity" as the only argument to the method call?""".format(test_method, parent_class) - -@pytest.mark.test_humidity_by_area_method_return_module4 -def test_humidity_by_area_method_return_module4(parse): - # ... - # return self._convert_data(recs) - - test_file = "humidity_info" - parent_class = "HouseInfo" - test_class = "HumidityData" - test_method = "get_data_by_area" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) - 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) - - # debug_test_case_class(my_class, test_method) - - my_method = my_file.class_(test_class).method(test_method) - assert ( - my_method.exists() - ), "Are you defining a method called `{}`?".format(test_method) - - # debug_test_case(my_method) - test_code = ( my_method.returns_call().match( { @@ -303,6 +266,7 @@ def test_humidity_by_date_method_module4(parse): # from datetime import date # def get_data_by_date(self, rec_date=date.today()): # recs = super().get_data_by_date("humidity", rec_date) + # return self._convert_data(recs) test_file = "humidity_info" parent_class = "HouseInfo" @@ -385,35 +349,6 @@ def test_humidity_by_date_method_module4(parse): the `{}` method from the `{}` parent class? Are you passing "humidity" as the only argument to the method call?""".format(test_method, parent_class) - -@pytest.mark.test_humidity_by_date_method_return_module4 -def test_humidity_by_date_method_return_module4(parse): - # ... - # return self._convert_data(recs) - - test_file = "humidity_info" - parent_class = "HouseInfo" - test_class = "HumidityData" - test_method = "get_data_by_date" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) - 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) - - # debug_test_case_class(my_class, test_method) - - my_method = my_file.class_(test_class).method(test_method) - assert ( - my_method.exists() - ), "Are you defining a method called `{}`?".format(test_method) - - # debug_test_case(my_method) - test_code = ( my_method.returns_call().match( { @@ -439,13 +374,13 @@ def test_humidity_by_date_method_return_module4(parse): @pytest.mark.test_sensor_app_temp_info_by_area_module4 def test_sensor_app_temp_info_by_area_module4(parse): # from humidity_info import HumidityData # module 4 - # from statistics import mean . + # 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("House Humidity sensor records for area 1 = {}".format(len(recs))) - # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} temperatures".format( max(recs), min(recs), mean(recs))) + # print("\nHouse Humidity sensor records for area 1 = {}".format(len(recs))) + # print("\tAverage: {} humidity".format(mean(recs))) test_file = "sensor_app" test_class = "HumidityData" @@ -518,9 +453,8 @@ def test_sensor_app_temp_info_by_area_module4(parse): def test_sensor_app_temp_info_by_date_module4(parse): # ... # recs = humidity_data.get_data_by_date(test_date) - # NOTE: print statements are not validated - # print("House Humidity sensor records for date: {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) - # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} humiditys".format(max(recs), min(recs), mean(recs))) + # print("House Humidity sensor records for date: {} = {}".format( test_date.strftime("%m/%d/%y"), len(recs))) + # print("\tAverrage: {} humdity".format(mean(recs))) test_file = "sensor_app" test_class = "HumidityData" @@ -556,22 +490,9 @@ def test_sensor_app_temp_info_by_date_module4(parse): """ -@pytest.mark.test_particle_import_module4 -def test_particle_import_module4(parse): - # from house_info import HouseInfo - - test_file = "particle_count_info" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_file_import = my_file.from_imports( - "house_info", "HouseInfo") - assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) - - @pytest.mark.test_particle_create_class_module4 def test_particle_create_class_module4(parse): + # from house_info import HouseInfo # class ParticleData(HouseInfo): # def _convert_data(self, data): # recs = [] @@ -584,6 +505,10 @@ def test_particle_create_class_module4(parse): my_file = parse(test_file) assert my_file.success, my_file.message + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) assert ( my_class.exists() @@ -718,10 +643,16 @@ def test_particle_convert_loop_module4(parse): ), """Are you returning `recs` list from the `{}` method?""".format(test_method) -@pytest.mark.test_particle_by_area_method_module4 -def test_particle_by_area_method_module4(parse): +@pytest.mark.test_particle_by_area_and_date_methods_module4 +def test_particle_by_area_and_date_methods_module4(parse): + # from datetime import date # def get_data_by_area(self, rec_area=0): # data = super().get_data_by_area("particle", rec_area) + # return self._convert_data(recs) + # + # def get_data_by_date(self, rec_date=date.today()): + # recs = super().get_data_by_date("particle", rec_date) + # return self._convert_data(recs) test_file = "particle_count_info" parent_class = "HouseInfo" @@ -797,35 +728,6 @@ def test_particle_by_area_method_module4(parse): the `{}` method from the `{}` parent class? Are you passing "particle" as the only argument to the method call?""".format(test_method, parent_class) - -@pytest.mark.test_particle_by_area_method_return_module4 -def test_particle_by_area_method_return_module4(parse): - # ... - # return self._convert_data(recs) - - test_file = "particle_count_info" - parent_class = "HouseInfo" - test_class = "ParticleData" - test_method = "get_data_by_area" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) - 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) - - # debug_test_case_class(my_class, test_method) - - my_method = my_file.class_(test_class).method(test_method) - assert ( - my_method.exists() - ), "Are you defining a method called `{}`?".format(test_method) - - # debug_test_case(my_method) - test_code = ( my_method.returns_call().match( { @@ -847,21 +749,9 @@ def test_particle_by_area_method_return_module4(parse): Are you calling the `_convert_data` method? Passing `recs` as the only argument?""".format(test_method) - -@pytest.mark.test_particle_by_date_method_module4 -def test_particle_by_date_method_module4(parse): - # from datetime import date - # def get_data_by_date(self, rec_date=date.today()): - # recs = super().get_data_by_date("particle", rec_date) - - test_file = "particle_count_info" - parent_class = "HouseInfo" - test_class = "ParticleData" + # Now test the get_data_by_date method test_method = "get_data_by_date" - my_file = parse(test_file) - assert my_file.success, my_file.message - my_file_import = my_file.from_imports( "datetime", "date") assert my_file_import, "Are you importing `date` from datetime in `{}`".format(test_file) @@ -872,15 +762,11 @@ def test_particle_by_date_method_module4(parse): ), """Have you created a class called `{0}`? Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class) - # debug_test_case_class(my_class, test_method) - my_method = my_file.class_(test_class).method(test_method) assert ( my_method.exists() ), "Are you defining a method called `{}`?".format(test_method) - # debug_test_case(my_method) - my_class_arguments = ( my_class.def_args_(test_method).match( { @@ -935,17 +821,38 @@ def test_particle_by_date_method_module4(parse): the `{}` method from the `{}` parent class? Are you passing "particle" as the only argument to the method call?""".format(test_method, parent_class) + test_code = ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Name", + "value_func_value_id": "self", + "value_func_attr": "_convert_data", + "value_args_0_type": "Name", + "value_args_0_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning a call from the `{}` method? + Are you calling the `_convert_data` method? + Passing `recs` as the only argument?""".format(test_method) + + +@pytest.mark.test_particle_get_concentration_method_module4 +def test_particle_get_concentration_method_module4(parse): + # def get_data_concentrations(self, data): + # particulate = {"good": 0, "moderate": 0, "bad": 0} -@pytest.mark.test_particle_by_date_method_return_module4 -def test_particle_by_date_method_return_module4(parse): - # ... - # return self._convert_data(recs) - test_file = "particle_count_info" parent_class = "HouseInfo" test_class = "ParticleData" - test_method = "get_data_by_date" - + test_method = "get_data_concentrations" + my_file = parse(test_file) assert my_file.success, my_file.message @@ -955,36 +862,133 @@ def test_particle_by_date_method_return_module4(parse): ), """Have you created a class called `{0}`? Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class) - # debug_test_case_class(my_class, test_method) + my_method = my_file.class_(test_class).method(test_method) + assert ( + my_method.exists() + ), "Are you defining a method called `{}`?".format(test_method) + # debug_test_case_class(my_class, test_method) + # debug_test_case(my_method) + + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_concentrations", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "data", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + # Check for assignment + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "particulate", + "value_type": "Dict", + "value_keys_0_type": "Constant", + "value_keys_0_value": "good", + "value_keys_1_type": "Constant", + "value_keys_1_value": "moderate", + "value_keys_2_type": "Constant", + "value_keys_2_value": "bad", + "value_values_0_type": "Constant", + "value_values_0_value": 0, + "value_values_1_type": "Constant", + "value_values_1_value": 0, + "value_values_2_type": "Constant", + "value_values_2_value": 0 + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating a dictionary called `particulate`? + Are you initializing it with three entries? + "good", "moderate", and "bad", all set equal to zero?""" + + +@pytest.mark.test_particle_get_concentration_for_module4 +def test_particle_get_concentration_for_module4(parse): + # for rec in data: + # # Select particulate concentration + # if rec <= 50.0: + # particulate["good"] += 1 + # elif rec > 50.0 and rec < 100: + # particulate["moderate"] += 1 + # else: + # particulate["bad"] += 1 + + # return particulate + + test_file = "particle_count_info" + parent_class = "HouseInfo" + test_class = "ParticleData" + test_method = "get_data_concentrations" + + my_file = parse(test_file) + assert my_file.success, my_file.message + + my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) + 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) + my_method = my_file.class_(test_class).method(test_method) assert ( my_method.exists() ), "Are you defining a method called `{}`?".format(test_method) - # debug_test_case(my_method) + # debug_test_case(my_method) + + # Check for assignment + test_code = ( + my_method.for_().match( + { + "target_type": "Name", + "target_id": "rec", + "iter_type": "Name", + "iter_id": "data" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating a loop over `data`? + Are you using `rec` as the iterator?""" test_code = ( my_method.returns_call().match( { "type": "Return", - "value_type": "Call", - "value_func_type": "Attribute", - "value_func_value_type": "Name", - "value_func_value_id": "self", - "value_func_attr": "_convert_data", - "value_args_0_type": "Name", - "value_args_0_id": "recs" + "value_type": "Name", + "value_id": "particulate" } ) .exists() ) assert ( test_code - ), """Are you returning a call from the `{}` method? - Are you calling the `_convert_data` method? - Passing `recs` as the only argument?""".format(test_method) - + ), """Are you returning `particulate` from the method?""" + @pytest.mark.test_sensor_app_particle_info_by_area_module4 def test_sensor_app_particle_info_by_area_module4(parse): @@ -992,9 +996,11 @@ def test_sensor_app_particle_info_by_area_module4(parse): # ... # particle_data = ParticleData(data) # recs = particle_data.get_data_by_area(rec_area=1) - # NOTE: print statements are not validated - # print("House Humidity sensor records for area 1 = {}".format(len(recs))) - # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} temperatures".format( max(recs), min(recs), mean(recs))) + # print("\nHouse Particle sensor records for area 1 = {}".format(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"])) + # print("\tBad Air Quality Recs: {}".format(concentrations["bad"])) test_file = "sensor_app" test_class = "ParticleData" @@ -1006,7 +1012,7 @@ def test_sensor_app_particle_info_by_area_module4(parse): "particle_count_info", "ParticleData") assert my_file_import, "Are you importing `ParticleData` from `particle_count_info` in `{}`".format(test_file) - # debug_test_case(my_file) + # debug_test_case(my_file) test_code = ( my_file.assign_().match( @@ -1059,7 +1065,7 @@ def test_sensor_app_particle_info_by_area_module4(parse): { "14_type": "Assign", "14_targets_0_type": "Name", - "14_targets_0_id": "recs", + "14_targets_0_id": "concentrations", "14_value_type": "Call", "14_value_func_type": "Attribute", "14_value_func_value_type": "Name", @@ -1067,34 +1073,29 @@ def test_sensor_app_particle_info_by_area_module4(parse): "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": "Call", - "14_value_keywords_0_value_func_type": "Attribute", - "14_value_keywords_0_value_func_value_type": "Name", - "14_value_keywords_0_value_func_value_id": "particle_data", - "14_value_keywords_0_value_func_attr": "get_data_by_area", - "14_value_keywords_0_value_keywords_0_type": "keyword", - "14_value_keywords_0_value_keywords_0_arg": "rec_area", - "14_value_keywords_0_value_keywords_0_value_type": "Constant", - "14_value_keywords_0_value_keywords_0_value_value": 1, + "14_value_keywords_0_value_type": "Name", + "14_value_keywords_0_value_id": "recs", } ) .exists() ) assert ( test_code - ), """Are you setting `recs` to the method call `get_data_concentration` from the `particle_data` object? - Are you passing another method call `get_data_by_area` from the same `particle_data` object as the input parameter? - Are you passing `"rec_area=1"` as the only argument to the `get_data_by_area` method? + ), """Are you setting `concentrations` to the method call `get_data_concentrations` from the `particle_data` object? + Are you passing `recs` as the only argument to the method? """ @pytest.mark.test_sensor_app_particle_info_by_date_module4 def test_sensor_app_particle_info_by_date_module4(parse): # ... - # recs = particle_data.get_data_by_date(test_date) - # NOTE: print statements are not validated - # print("House Humidity sensor records for date: {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) - # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} particles".format(max(recs), min(recs), mean(recs))) + # recs = particle_data.get_data_by_date(rec_date=test_date) + # print("\nHouse Particle sensor records for date: {} = {}".format( + # test_date.strftime("%m/%d/%y"), 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"])) + # print("\tBad Air Quality Recs: {}".format(concentrations["bad"])) test_file = "sensor_app" test_class = "ParticleData" @@ -1134,7 +1135,7 @@ def test_sensor_app_particle_info_by_date_module4(parse): { "16_type": "Assign", "16_targets_0_type": "Name", - "16_targets_0_id": "recs", + "16_targets_0_id": "concentrations", "16_value_type": "Call", "16_value_func_type": "Attribute", "16_value_func_value_type": "Name", @@ -1142,21 +1143,14 @@ def test_sensor_app_particle_info_by_date_module4(parse): "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": "Call", - "16_value_keywords_0_value_func_type": "Attribute", - "16_value_keywords_0_value_func_value_type": "Name", - "16_value_keywords_0_value_func_value_id": "particle_data", - "16_value_keywords_0_value_func_attr": "get_data_by_date", - "16_value_keywords_0_value_keywords_0_type": "keyword", - "16_value_keywords_0_value_keywords_0_arg": "rec_date", - "16_value_keywords_0_value_keywords_0_value_type": "Name", - "16_value_keywords_0_value_keywords_0_value_id": "test_date" + "16_value_keywords_0_value_type": "Name", + "16_value_keywords_0_value_id": "recs", } ) .exists() ) assert ( test_code - ), """Are you setting `recs` to the method call `get_data_by_date` from the `particle_data` object? - Are you passing `rec_date=test_date` as the only argument to the method? + ), """Are you setting `concentrations` to the method call `get_data_concentrations` from the `particle_data` object? + Are you passing `recs` as the only argument to the method? """ diff --git a/tests/test_module5.py b/tests/test_module5.py index 70322d90..8631df25 100644 --- a/tests/test_module5.py +++ b/tests/test_module5.py @@ -2,25 +2,12 @@ from tests.template import debug_test_case, debug_test_case_class -@pytest.mark.test_energy_import_module5 -def test_energy_import_module5(parse): - # from house_info import HouseInfo - - test_file = "energy_info" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_file_import = my_file.from_imports( - "house_info", "HouseInfo") - assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) - - @pytest.mark.test_energy_create_class_module5 def test_energy_create_class_module5(parse): + # from house_info import HouseInfo # class EnergyData(HouseInfo): - # def _convert_data(self, data): - # recs = [] + # ENERGY_PER_BULB = 0.2 # in watts + # ENERGY_BITS = 0x0F0 test_file = "energy_info" parent_class = "HouseInfo" @@ -30,157 +17,10 @@ def test_energy_create_class_module5(parse): my_file = parse(test_file) assert my_file.success, my_file.message - my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) - 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) - - # debug_test_case_class(my_class, test_method) - - my_method = my_file.class_(test_class).method(test_method) - assert ( - my_method.exists() - ), "Are you defining a method called `{}`?".format(test_method) - - # debug_test_case(my_method) - - my_class_arguments = ( - my_class.def_args_(test_method).match( - { - "type": "FunctionDef", - "name": "_convert_data", - "args_type": "arguments", - "args_args_0_type": "arg", - "args_args_0_arg": "self", - "args_args_0_annotation": "nil", - "args_args_1_type": "arg", - "args_args_1_arg": "data", - "args_args_1_annotation": "nil", - "args_vararg": "nil", - "args_kwarg": "nil", - } - ) - .exists() - ) - assert ( - my_class_arguments - ), """Are you defining a method `{0}` for the `{1}` class? - Are you declaring the correct name and number of parameters?""".format(test_method, test_class) - - # Check for assignment - test_code = ( - my_method.assign_().match( - { - "targets_0_type": "Name", - "targets_0_id": "recs", - "value_type": "List" - } - ) - .exists() - ) - assert ( - test_code - ), "Are you creating a variable called `recs` set equal to an empty list?" - - -@pytest.mark.test_energy_convert_loop_module5 -def test_energy_convert_loop_module5(parse): - # for rec in data: - # # Convert string of integers into actual integers based 16 - # recs.append(self._get_energy(rec)) - # return recs - - test_file = "energy_info" - parent_class = "HouseInfo" - test_class = "EnergyData" - test_method = "_convert_data" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) - 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) - - my_method = my_file.class_(test_class).method(test_method) - assert ( - my_method.exists() - ), "Are you defining a method called `{}`?".format(test_method) - - # debug_test_case(my_method) - - test_code = ( - my_method.for_().match( - { - "target_type": "Name", - "target_id": "rec", - "iter_type": "Name", - "iter_id": "data" - } - ) - .exists() - ) - assert ( - test_code - ), """Do you have a `for` loop, looping through `data`? - Is the current loop value called `rec`?""" - - test_code = ( - my_method.for_().match( - { - "0_type": "Expr", - "0_value_type": "Call", - "0_value_func_type": "Attribute", - "0_value_func_value_type": "Name", - "0_value_func_value_id": "recs", - "0_value_func_attr": "append", - "0_value_args_0_type": "Call", - "0_value_args_0_func_type": "Attribute", - "0_value_args_0_func_value_type": "Name", - "0_value_args_0_func_value_id": "self", - "0_value_args_0_func_attr": "_get_energy", - "0_value_args_0_args_0_type": "Name", - "0_value_args_0_args_0_id": "rec" - } - ) - .exists() - ) - assert ( - test_code - ), """Inside your loop, are you converting `rec` value through `self._rec_energy()` method? - Are you appending it to `recs` list?""" - - test_code= ( - my_method.returns_call().match( - { - "type": "Return", - "value_type": "Name", - "value_id": "recs" - } - ) - .exists() - ) - assert ( - test_code - ), """Are you returning `recs` list from the `{}` method?""".format(test_method) - - -@pytest.mark.test_energy_class_variables_module5 -def test_energy_class_variables_module5(parse): - # ENERGY_PER_BULB = 0.2 # in watts - # ENERGY_BITS = 0x0F0 + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") - test_file = "energy_info" - parent_class = "HouseInfo" - test_class = "EnergyData" - test_method = "_convert_data" - - my_file = parse(test_file) - assert my_file.success, my_file.message - + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) assert ( my_class.exists() @@ -188,7 +28,6 @@ def test_energy_class_variables_module5(parse): Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class) # debug_test_case_class(my_class, test_method) - # debug_test_case(my_class) test_code = ( my_class.assign_().match( @@ -224,7 +63,6 @@ def test_energy_class_variables_module5(parse): ), """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): @@ -358,19 +196,26 @@ def test_energy_get_energy_method_module5(parse): ), """Are you returning `recs` from the `{}` method?""".format(test_method) -@pytest.mark.test_energy_by_area_method_module5 -def test_energy_by_area_method_module5(parse): - # def get_data_by_area(self, rec_area=0): - # data = super().get_data_by_area("energy", rec_area) - +@pytest.mark.test_energy_convert_method_module5 +def test_energy_convert_method_module5(parse): + # def _convert_data(self, data): + # recs = [] + # for rec in data: + # # Convert string of integers into actual integers based 16 + # recs.append(self._get_energy(rec)) + # return recs test_file = "energy_info" parent_class = "HouseInfo" test_class = "EnergyData" - test_method = "get_data_by_area" - + test_method = "_convert_data" + my_file = parse(test_file) assert my_file.success, my_file.message + my_file_import = my_file.from_imports( + "house_info", "HouseInfo") + + assert my_file_import, "Are you importing `HouseInfo` from `house_info` in `{}` file".format(test_file) my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) assert ( my_class.exists() @@ -378,30 +223,28 @@ def test_energy_by_area_method_module5(parse): Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class) # debug_test_case_class(my_class, test_method) - + my_method = my_file.class_(test_class).method(test_method) assert ( my_method.exists() ), "Are you defining a method called `{}`?".format(test_method) # debug_test_case(my_method) - + my_class_arguments = ( my_class.def_args_(test_method).match( { "type": "FunctionDef", - "name": "get_data_by_area", + "name": "_convert_data", "args_type": "arguments", "args_args_0_type": "arg", "args_args_0_arg": "self", "args_args_0_annotation": "nil", "args_args_1_type": "arg", - "args_args_1_arg": "rec_area", + "args_args_1_arg": "data", "args_args_1_annotation": "nil", "args_vararg": "nil", "args_kwarg": "nil", - "args_defaults_0_type": "Constant", - "args_defaults_0_value": 0, } ) .exists() @@ -410,36 +253,87 @@ def test_energy_by_area_method_module5(parse): my_class_arguments ), """Are you defining a method `{0}` for the `{1}` class? Are you declaring the correct name and number of parameters?""".format(test_method, test_class) - + + # Check for assignment test_code = ( my_method.assign_().match( { - "type": "Assign", "targets_0_type": "Name", "targets_0_id": "recs", - "value_type": "Call", - "value_func_type": "Attribute", - "value_func_value_type": "Call", - "value_func_value_func_type": "Name", - "value_func_value_func_id": "super", - "value_func_attr": "get_data_by_area", - "value_args_0_type": "Constant", - "value_args_0_value": "energy_usage", - "value_args_1_type": "Name", - "value_args_1_id": "rec_area" + "value_type": "List" } ) .exists() ) assert ( test_code - ), """Are you creating a variable called `recs` set equal to - the `{}` method from the `{}` parent class? - Are you passing "energy" as the only argument to the method call?""".format(test_method, parent_class) + ), "Are you creating a variable called `recs` set equal to an empty list?" + + test_code = ( + my_method.for_().match( + { + "target_type": "Name", + "target_id": "rec", + "iter_type": "Name", + "iter_id": "data" + } + ) + .exists() + ) + assert ( + test_code + ), """Do you have a `for` loop, looping through `data`? + Is the current loop value called `rec`?""" -@pytest.mark.test_energy_by_area_method_return_module5 -def test_energy_by_area_method_return_module5(parse): - # ... + test_code = ( + my_method.for_().match( + { + "0_type": "Expr", + "0_value_type": "Call", + "0_value_func_type": "Attribute", + "0_value_func_value_type": "Name", + "0_value_func_value_id": "recs", + "0_value_func_attr": "append", + "0_value_args_0_type": "Call", + "0_value_args_0_func_type": "Attribute", + "0_value_args_0_func_value_type": "Name", + "0_value_args_0_func_value_id": "self", + "0_value_args_0_func_attr": "_get_energy", + "0_value_args_0_args_0_type": "Name", + "0_value_args_0_args_0_id": "rec" + } + ) + .exists() + ) + assert ( + test_code + ), """Inside your loop, are you converting `rec` value through `self._rec_energy()` method? + Are you appending it to `recs` list?""" + + test_code= ( + my_method.returns_call().match( + { + "type": "Return", + "value_type": "Name", + "value_id": "recs" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you returning `recs` list from the `{}` method?""".format(test_method) + + +@pytest.mark.test_energy_by_area_and_date_methods_module5 +def test_energy_by_area_and_date_methods_module5(parse): + # from datetime import date + # def get_data_by_area(self, rec_area=0): + # data = super().get_data_by_area("energy_usage", rec_area) + # return self._convert_data(recs) + # + # def get_data_by_date(self, rec_date=date.today()): + # recs = super().get_data_by_date("energy_usage", rec_date) # return self._convert_data(recs) test_file = "energy_info" @@ -465,6 +359,57 @@ def test_energy_by_area_method_return_module5(parse): # debug_test_case(my_method) + my_class_arguments = ( + my_class.def_args_(test_method).match( + { + "type": "FunctionDef", + "name": "get_data_by_area", + "args_type": "arguments", + "args_args_0_type": "arg", + "args_args_0_arg": "self", + "args_args_0_annotation": "nil", + "args_args_1_type": "arg", + "args_args_1_arg": "rec_area", + "args_args_1_annotation": "nil", + "args_vararg": "nil", + "args_kwarg": "nil", + "args_defaults_0_type": "Constant", + "args_defaults_0_value": 0, + } + ) + .exists() + ) + assert ( + my_class_arguments + ), """Are you defining a method `{0}` for the `{1}` class? + Are you declaring the correct name and number of parameters?""".format(test_method, test_class) + + test_code = ( + my_method.assign_().match( + { + "type": "Assign", + "targets_0_type": "Name", + "targets_0_id": "recs", + "value_type": "Call", + "value_func_type": "Attribute", + "value_func_value_type": "Call", + "value_func_value_func_type": "Name", + "value_func_value_func_id": "super", + "value_func_attr": "get_data_by_area", + "value_args_0_type": "Constant", + "value_args_0_value": "energy_usage", + "value_args_1_type": "Name", + "value_args_1_id": "rec_area" + } + ) + .exists() + ) + assert ( + test_code + ), """Are you creating a variable called `recs` set equal to + the `{}` method from the `{}` parent class? + Are you passing "energy" as the only argument to the method call?""".format(test_method, parent_class) + test_code = ( my_method.returns_call().match( { @@ -486,32 +431,13 @@ def test_energy_by_area_method_return_module5(parse): Are you calling the `_convert_data` method? Passing `recs` as the only argument?""".format(test_method) -@pytest.mark.test_energy_by_date_method_module5 -def test_energy_by_date_method_module5(parse): - # from datetime import date - # def get_data_by_date(self, rec_date=date.today()): - # recs = super().get_data_by_date("energy", rec_date) - - test_file = "energy_info" - parent_class = "HouseInfo" - test_class = "EnergyData" + # Now test get_data_by_date test_method = "get_data_by_date" - my_file = parse(test_file) - assert my_file.success, my_file.message - my_file_import = my_file.from_imports( "datetime", "date") 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 ( - 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) - - # debug_test_case_class(my_class, test_method) - my_method = my_file.class_(test_class).method(test_method) assert ( my_method.exists() @@ -573,32 +499,6 @@ def test_energy_by_date_method_module5(parse): the `{}` method from the `{}` parent class? Are you passing "energy" as the only argument to the method call?""".format(test_method, parent_class) -@pytest.mark.test_energy_by_date_method_return_module5 -def test_energy_by_date_method_return_module5(parse): - # ... - # return self._convert_data(recs) - - test_file = "energy_info" - parent_class = "HouseInfo" - test_class = "EnergyData" - test_method = "get_data_by_date" - - my_file = parse(test_file) - assert my_file.success, my_file.message - - my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class)) - 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) - - # debug_test_case_class(my_class, test_method) - - my_method = my_file.class_(test_class).method(test_method) - assert ( - my_method.exists() - ), "Are you defining a method called `{}`?".format(test_method) - # debug_test_case(my_method) test_code = ( @@ -731,14 +631,15 @@ def test_energy_calculate_usage_method_module5(parse): ), """Are you returning a `total_energy` from the `{}` method?""".format(test_method) -@pytest.mark.test_sensor_app_temp_info_by_area_module5 -def test_sensor_app_temp_info_by_area_module5(parse): +@pytest.mark.test_sensor_app_energy_info_by_area_module5 +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) - # NOTE: print statements are not validated - # print("House Humidity sensor records for area 1 = {}".format(len(recs))) + # print("\nHouse Energy sensor records for area 1 = {}".format(len(recs))) + # total_energy = energy_data.calculate_energy_usage(data=recs) + # print("\tEnergy Usage: {:2.2} Watts".format(total_energy)) test_file = "sensor_app" test_class = "EnergyData" @@ -809,8 +710,10 @@ def test_sensor_app_temp_info_by_area_module5(parse): "19_value_func_value_type": "Name", "19_value_func_value_id": "energy_data", "19_value_func_attr": "calculate_energy_usage", - "19_value_args_0_type": "Name", - "19_value_args_0_id": "recs", + "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", } ) .exists() @@ -818,17 +721,18 @@ def test_sensor_app_temp_info_by_area_module5(parse): assert ( test_code ), """Are you setting `total_energy` to the method call `calculate_energy_usage` from the `energy_data` object? - Are you passing `recs` as the only argument to the method? + Are you passing `data=recs` as the only argument to the method? """ -@pytest.mark.test_sensor_app_temp_info_by_date_module5 -def test_sensor_app_temp_info_by_date_module5(parse): +@pytest.mark.test_sensor_app_energy_info_by_date_module5 +def test_sensor_app_energy_info_by_date_module5(parse): # ... - # recs = energy_data.get_data_by_date(test_date) - # NOTE: print statements are not validated - # print("House Humidity sensor records for date: {} = {}".format(test_date.strftime("%m/%d/%y"), len(recs))) - # print("\tMaximum: {0}, Minimum: {1}, and Averrage: {2} energys".format(max(recs), min(recs), mean(recs))) + # recs = energy_data.get_data_by_date(rec_date=test_date) + # print("House Energy sensor records for date: {} = {}".format( + # test_date.strftime("%m/%d/%y"), len(recs))) + # total_energy = energy_data.calculate_energy_usage(data=recs) + # print("\tEnergy Usage: {:2.2} Watts".format(total_energy)) test_file = "sensor_app" test_class = "EnergyData" @@ -836,7 +740,7 @@ def test_sensor_app_temp_info_by_date_module5(parse): my_file = parse(test_file) assert my_file.success, my_file.message - # debug_test_case(my_file) + # debug_test_case(my_file) test_code = ( my_file.assign_().match( @@ -874,15 +778,10 @@ def test_sensor_app_temp_info_by_date_module5(parse): "21_value_func_value_type": "Name", "21_value_func_value_id": "energy_data", "21_value_func_attr": "calculate_energy_usage", - "21_value_args_0_type": "Call", - "21_value_args_0_func_type": "Attribute", - "21_value_args_0_func_value_type": "Name", - "21_value_args_0_func_value_id": "energy_data", - "21_value_args_0_func_attr": "get_data_by_date", - "21_value_args_0_keywords_0_type": "keyword", - "21_value_args_0_keywords_0_arg": "rec_date", - "21_value_args_0_keywords_0_value_type": "Name", - "21_value_args_0_keywords_0_value_id": "test_date" + "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" } ) .exists()