Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 6 sensor/sensor_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
print("Sensor Data App")
##############################

# Module 1 code here:

# Module 2 code here:

# Module 3 code here:

# Module 4 code here:

# Module 5 code here:

# Module 6 code here:
# Module 5 code here:
76 changes: 55 additions & 21 deletions 76 tests/test_module1.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,32 +328,70 @@ def test_load_data_load_recs_module1(parse):

@pytest.mark.test_sensor_app_load_data_return_module1
def test_sensor_app_load_data_return_module1(parse):
# from load_data import load_sensor_data
# First, let's verify the user did not accidentally deleted
# the two lines provided for them.

# data = [] # list to store data read from files
# print("Sensor Data App")
#
# data = load_sensor_data()
# print("Loaded records {}".format(len(data)))

sensor = parse("sensor_app")
assert sensor.success, sensor.message

original_data = (
sensor.assign_().match(
{
"0_type": "Assign",
"0_targets_0_type": "Name",
"0_targets_0_id": "data",
"0_value_type": "List",
}
)
.exists()
)
assert (
original_data
), """Do you have a `data` variable set to an empty list on top of the file?
You need to have these two lines of code before you being testing Module1
data = []
print("Sensor Data App")
"""

test_file = "sensor_app"
test_class = "HouseInfo"
test_method = "__init__"
print_app = (
sensor.calls().match(
{
"type": "Expr",
"value_type": "Call",
"value_func_type": "Name",
"value_func_id": "print",
"value_args_0_type": "Constant",
"value_args_0_value": "Sensor Data App"
}
)
.exists()
)
assert (
print_app
), """Do you have a `print("Sensor Data App")` statement?
You need to have these two lines of code before you being testing Module1
data = []
print("Sensor Data App")"""

my_file = parse(test_file)
assert my_file.success, my_file.message

######################################################
# Now we can test the actual module
######################################################

# from load_data import load_sensor_data
# data = load_sensor_data()
# print("Loaded records {}".format(len(data)))

my_file_import = my_file.from_imports(
load_sensor_data_import = sensor.from_imports(
"load_data", "load_sensor_data")
assert my_file_import, "Are you importing `load_sensor_data` from `load_data`?"
assert load_sensor_data_import, "Are you importing `load_sensor_data` from load_data?"

data = (
my_file.assign_().match(
sensor.assign_().match(
{
"0_type": "Assign",
"0_targets_0_type": "Name",
"0_targets_0_id": "data",
"0_value_type": "List",
"1_type": "Assign",
"1_targets_0_type": "Name",
"1_targets_0_id": "data",
Expand All @@ -366,8 +404,4 @@ def test_sensor_app_load_data_return_module1(parse):
)
assert (
data
), """Do you have a `data` variable set to an empty list on top of the file?
Did you delete the starting code ?
data = []
print("Sensor Data App")
In a new line, are you setting `data` to `load_sensor_data()` function call?"""
), "Are you creating a variable called `data` set equal to `load_sensor_data()` function?"
98 changes: 53 additions & 45 deletions 98 tests/test_module2.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ def test_sensor_app_house_info_by_area_module2(parse):
# from house_info import HouseInfo
# ...
# house_info = HouseInfo(data)
# recs = house_info.get_data_by_area("id", rec_area=1)
# print("House sensor records for area 1 = {}".format(len(recs))) # NOT TEST IT
# test_area = 1
# recs = house_info.get_data_by_area("id", rec_area=test_area)
# print("\nHouse sensor records for area {} = {}".format(test_area, len(recs)))

test_file = "sensor_app"

Expand Down Expand Up @@ -481,29 +482,35 @@ def test_sensor_app_house_info_by_area_module2(parse):
test_code = (
my_file.assign_().match(
{
"3_type": "Assign",
"3_targets_0_type": "Name",
"3_targets_0_id": "recs",
"3_value_type": "Call",
"3_value_func_type": "Attribute",
"3_value_func_value_type": "Name",
"3_value_func_value_id": "house_info",
"3_value_func_attr": "get_data_by_area",
"3_value_args_0_type": "Constant",
"3_value_args_0_value": "id",
"3_value_keywords_0_type": "keyword",
"3_value_keywords_0_arg": "rec_area",
"3_value_keywords_0_value_type": "Constant",
"3_value_keywords_0_value_value": 1,
"3_type": "Assign",
"3_targets_0_type": "Name",
"3_targets_0_id": "test_area",
"3_value_type": "Constant",
"3_value_value": 1,
"4_type": "Assign",
"4_targets_0_type": "Name",
"4_targets_0_id": "recs",
"4_value_type": "Call",
"4_value_func_type": "Attribute",
"4_value_func_value_type": "Name",
"4_value_func_value_id": "house_info",
"4_value_func_attr": "get_data_by_area",
"4_value_args_0_type": "Constant",
"4_value_args_0_value": "id",
"4_value_keywords_0_type": "keyword",
"4_value_keywords_0_arg": "rec_area",
"4_value_keywords_0_value_type": "Name",
"4_value_keywords_0_value_id": "test_area",
}
)
.exists()
)
assert (
test_code
), """Are you creating a variable `recs` and setting it to `house_info.get_data_by_area()`?
), """Are you creating a variable called `test_area` and setting it to 1?
Are you creating a variable `recs` and setting it to `house_info.get_data_by_area()`?
Are you passing `"id"` as the first argument to the method?
Are you passing `rec_area=1` as the second argument to the method?"""
Are you passing `rec_area=test_area` as the second argument to the method?"""


@pytest.mark.test_sensor_app_house_info_by_date_module2
Expand All @@ -526,51 +533,52 @@ def test_sensor_app_house_info_by_date_module2(parse):
my_file_import = my_file.from_imports(
"datetime", "date")
assert my_file_import, "Are you importing `date` from `datetime` module?"


# debug_test_case(my_file)

test_code = (
my_file.assign_().match(
{
"4_type": "Assign",
"4_targets_0_type": "Name",
"4_targets_0_id": "test_date",
"4_value_type": "Call",
"4_value_func_type": "Attribute",
"4_value_func_value_type": "Name",
"4_value_func_value_id": "datetime",
"4_value_func_attr": "strptime",
"4_value_args_0_type": "Constant",
"4_value_args_0_value": "5/9/20",
"4_value_args_1_type": "Constant",
"4_value_args_1_value": "%m/%d/%y",
"5_type": "Assign",
"5_targets_0_type": "Name",
"5_targets_0_id": "test_date",
"5_value_type": "Call",
"5_value_func_type": "Attribute",
"5_value_func_value_type": "Name",
"5_value_func_value_id": "datetime",
"5_value_func_attr": "strptime",
"5_value_args_0_type": "Constant",
"5_value_args_0_value": "5/9/20",
"5_value_args_1_type": "Constant",
"5_value_args_1_value": "%m/%d/%y",
}
)
.exists()
)
assert (
test_code
), """Are you creating an instance of the `datetime` class called `test_date`

which takes `"5/9/20"` and `"%m/%d/%y"` as the two arguments?"""

test_code = (
my_file.assign_().match(
{
"5_type": "Assign",
"5_targets_0_type": "Name",
"5_targets_0_id": "recs",
"5_value_type": "Call",
"5_value_func_type": "Attribute",
"5_value_func_value_type": "Name",
"5_value_func_value_id": "house_info",
"5_value_func_attr": "get_data_by_date",
"5_value_args_0_type": "Constant",
"5_value_args_0_value": "id",
"5_value_keywords_0_type": "keyword",
"5_value_keywords_0_arg": "rec_date",
"5_value_keywords_0_value_type": "Name",
"5_value_keywords_0_value_id": "test_date"

"6_type": "Assign",
"6_targets_0_type": "Name",
"6_targets_0_id": "recs",
"6_value_type": "Call",
"6_value_func_type": "Attribute",
"6_value_func_value_type": "Name",
"6_value_func_value_id": "house_info",
"6_value_func_attr": "get_data_by_date",
"6_value_args_0_type": "Constant",
"6_value_args_0_value": "id",
"6_value_keywords_0_type": "keyword",
"6_value_keywords_0_arg": "rec_date",
"6_value_keywords_0_value_type": "Name",
"6_value_keywords_0_value_id": "test_date",
}
)
.exists()
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.