Skip to content

Commit defa7e7

Browse files
committed
Update test cases.
1 parent 235e52a commit defa7e7

File tree

6 files changed

+335
-285
lines changed

6 files changed

+335
-285
lines changed

sensor/sensor_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
print("Sensor Data App")
99
##############################
1010

11+
# Module 1 code here:
12+
1113
# Module 2 code here:
1214

1315
# Module 3 code here:
1416

1517
# Module 4 code here:
1618

17-
# Module 5 code here:
18-
19-
# Module 6 code here:
19+
# Module 5 code here:

tests/test_module1.py

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -328,32 +328,70 @@ def test_load_data_load_recs_module1(parse):
328328

329329
@pytest.mark.test_sensor_app_load_data_return_module1
330330
def test_sensor_app_load_data_return_module1(parse):
331-
# from load_data import load_sensor_data
331+
# First, let's verify the user did not accidentally deleted
332+
# the two lines provided for them.
333+
332334
# data = [] # list to store data read from files
333335
# print("Sensor Data App")
334-
#
335-
# data = load_sensor_data()
336-
# print("Loaded records {}".format(len(data)))
336+
337+
sensor = parse("sensor_app")
338+
assert sensor.success, sensor.message
339+
340+
original_data = (
341+
sensor.assign_().match(
342+
{
343+
"0_type": "Assign",
344+
"0_targets_0_type": "Name",
345+
"0_targets_0_id": "data",
346+
"0_value_type": "List",
347+
}
348+
)
349+
.exists()
350+
)
351+
assert (
352+
original_data
353+
), """Do you have a `data` variable set to an empty list on top of the file?
354+
You need to have these two lines of code before you being testing Module1
355+
data = []
356+
print("Sensor Data App")
357+
"""
337358

338-
test_file = "sensor_app"
339-
test_class = "HouseInfo"
340-
test_method = "__init__"
359+
print_app = (
360+
sensor.calls().match(
361+
{
362+
"type": "Expr",
363+
"value_type": "Call",
364+
"value_func_type": "Name",
365+
"value_func_id": "print",
366+
"value_args_0_type": "Constant",
367+
"value_args_0_value": "Sensor Data App"
368+
}
369+
)
370+
.exists()
371+
)
372+
assert (
373+
print_app
374+
), """Do you have a `print("Sensor Data App")` statement?
375+
You need to have these two lines of code before you being testing Module1
376+
data = []
377+
print("Sensor Data App")"""
341378

342-
my_file = parse(test_file)
343-
assert my_file.success, my_file.message
379+
380+
######################################################
381+
# Now we can test the actual module
382+
######################################################
344383

384+
# from load_data import load_sensor_data
385+
# data = load_sensor_data()
386+
# print("Loaded records {}".format(len(data)))
345387

346-
my_file_import = my_file.from_imports(
388+
load_sensor_data_import = sensor.from_imports(
347389
"load_data", "load_sensor_data")
348-
assert my_file_import, "Are you importing `load_sensor_data` from `load_data`?"
390+
assert load_sensor_data_import, "Are you importing `load_sensor_data` from load_data?"
349391

350392
data = (
351-
my_file.assign_().match(
393+
sensor.assign_().match(
352394
{
353-
"0_type": "Assign",
354-
"0_targets_0_type": "Name",
355-
"0_targets_0_id": "data",
356-
"0_value_type": "List",
357395
"1_type": "Assign",
358396
"1_targets_0_type": "Name",
359397
"1_targets_0_id": "data",
@@ -366,8 +404,4 @@ def test_sensor_app_load_data_return_module1(parse):
366404
)
367405
assert (
368406
data
369-
), """Do you have a `data` variable set to an empty list on top of the file?
370-
Did you delete the starting code ?
371-
data = []
372-
print("Sensor Data App")
373-
In a new line, are you setting `data` to `load_sensor_data()` function call?"""
407+
), "Are you creating a variable called `data` set equal to `load_sensor_data()` function?"

tests/test_module2.py

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,9 @@ def test_sensor_app_house_info_by_area_module2(parse):
443443
# from house_info import HouseInfo
444444
# ...
445445
# house_info = HouseInfo(data)
446-
# recs = house_info.get_data_by_area("id", rec_area=1)
447-
# print("House sensor records for area 1 = {}".format(len(recs))) # NOT TEST IT
446+
# test_area = 1
447+
# recs = house_info.get_data_by_area("id", rec_area=test_area)
448+
# print("\nHouse sensor records for area {} = {}".format(test_area, len(recs)))
448449

449450
test_file = "sensor_app"
450451

@@ -481,29 +482,35 @@ def test_sensor_app_house_info_by_area_module2(parse):
481482
test_code = (
482483
my_file.assign_().match(
483484
{
484-
"3_type": "Assign",
485-
"3_targets_0_type": "Name",
486-
"3_targets_0_id": "recs",
487-
"3_value_type": "Call",
488-
"3_value_func_type": "Attribute",
489-
"3_value_func_value_type": "Name",
490-
"3_value_func_value_id": "house_info",
491-
"3_value_func_attr": "get_data_by_area",
492-
"3_value_args_0_type": "Constant",
493-
"3_value_args_0_value": "id",
494-
"3_value_keywords_0_type": "keyword",
495-
"3_value_keywords_0_arg": "rec_area",
496-
"3_value_keywords_0_value_type": "Constant",
497-
"3_value_keywords_0_value_value": 1,
485+
"3_type": "Assign",
486+
"3_targets_0_type": "Name",
487+
"3_targets_0_id": "test_area",
488+
"3_value_type": "Constant",
489+
"3_value_value": 1,
490+
"4_type": "Assign",
491+
"4_targets_0_type": "Name",
492+
"4_targets_0_id": "recs",
493+
"4_value_type": "Call",
494+
"4_value_func_type": "Attribute",
495+
"4_value_func_value_type": "Name",
496+
"4_value_func_value_id": "house_info",
497+
"4_value_func_attr": "get_data_by_area",
498+
"4_value_args_0_type": "Constant",
499+
"4_value_args_0_value": "id",
500+
"4_value_keywords_0_type": "keyword",
501+
"4_value_keywords_0_arg": "rec_area",
502+
"4_value_keywords_0_value_type": "Name",
503+
"4_value_keywords_0_value_id": "test_area",
498504
}
499505
)
500506
.exists()
501507
)
502508
assert (
503509
test_code
504-
), """Are you creating a variable `recs` and setting it to `house_info.get_data_by_area()`?
510+
), """Are you creating a variable called `test_area` and setting it to 1?
511+
Are you creating a variable `recs` and setting it to `house_info.get_data_by_area()`?
505512
Are you passing `"id"` as the first argument to the method?
506-
Are you passing `rec_area=1` as the second argument to the method?"""
513+
Are you passing `rec_area=test_area` as the second argument to the method?"""
507514

508515

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

530538
# debug_test_case(my_file)
531539

532540
test_code = (
533541
my_file.assign_().match(
534542
{
535-
"4_type": "Assign",
536-
"4_targets_0_type": "Name",
537-
"4_targets_0_id": "test_date",
538-
"4_value_type": "Call",
539-
"4_value_func_type": "Attribute",
540-
"4_value_func_value_type": "Name",
541-
"4_value_func_value_id": "datetime",
542-
"4_value_func_attr": "strptime",
543-
"4_value_args_0_type": "Constant",
544-
"4_value_args_0_value": "5/9/20",
545-
"4_value_args_1_type": "Constant",
546-
"4_value_args_1_value": "%m/%d/%y",
543+
"5_type": "Assign",
544+
"5_targets_0_type": "Name",
545+
"5_targets_0_id": "test_date",
546+
"5_value_type": "Call",
547+
"5_value_func_type": "Attribute",
548+
"5_value_func_value_type": "Name",
549+
"5_value_func_value_id": "datetime",
550+
"5_value_func_attr": "strptime",
551+
"5_value_args_0_type": "Constant",
552+
"5_value_args_0_value": "5/9/20",
553+
"5_value_args_1_type": "Constant",
554+
"5_value_args_1_value": "%m/%d/%y",
547555
}
548556
)
549557
.exists()
550558
)
551559
assert (
552560
test_code
553561
), """Are you creating an instance of the `datetime` class called `test_date`
562+
554563
which takes `"5/9/20"` and `"%m/%d/%y"` as the two arguments?"""
555564

556565
test_code = (
557566
my_file.assign_().match(
558567
{
559-
"5_type": "Assign",
560-
"5_targets_0_type": "Name",
561-
"5_targets_0_id": "recs",
562-
"5_value_type": "Call",
563-
"5_value_func_type": "Attribute",
564-
"5_value_func_value_type": "Name",
565-
"5_value_func_value_id": "house_info",
566-
"5_value_func_attr": "get_data_by_date",
567-
"5_value_args_0_type": "Constant",
568-
"5_value_args_0_value": "id",
569-
"5_value_keywords_0_type": "keyword",
570-
"5_value_keywords_0_arg": "rec_date",
571-
"5_value_keywords_0_value_type": "Name",
572-
"5_value_keywords_0_value_id": "test_date"
573-
568+
"6_type": "Assign",
569+
"6_targets_0_type": "Name",
570+
"6_targets_0_id": "recs",
571+
"6_value_type": "Call",
572+
"6_value_func_type": "Attribute",
573+
"6_value_func_value_type": "Name",
574+
"6_value_func_value_id": "house_info",
575+
"6_value_func_attr": "get_data_by_date",
576+
"6_value_args_0_type": "Constant",
577+
"6_value_args_0_value": "id",
578+
"6_value_keywords_0_type": "keyword",
579+
"6_value_keywords_0_arg": "rec_date",
580+
"6_value_keywords_0_value_type": "Name",
581+
"6_value_keywords_0_value_id": "test_date",
574582
}
575583
)
576584
.exists()

0 commit comments

Comments
 (0)