Skip to content

Commit a2afe62

Browse files
committed
Add another task
1 parent 01dcd5f commit a2afe62

File tree

1 file changed

+132
-78
lines changed

1 file changed

+132
-78
lines changed

tests/test_module1.py

Lines changed: 132 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_load_data_import_module1(parse):
2020

2121
csv_import = load_data.imports("csv")
2222
assert csv_import, "Are you importing `csv`?"
23-
23+
2424

2525
@pytest.mark.test_load_data_load_sensor_func_module1
2626
def test_load_data_load_sensor_func_module1(parse):
@@ -38,15 +38,15 @@ def test_load_data_load_sensor_func_module1(parse):
3838

3939
# print(json.dumps(load_sensor_data.assign_().n, indent=2))
4040
# assert False
41-
41+
4242
sensor_data = load_sensor_data.assign_().match(
43-
{
44-
"type": "Assign",
45-
"targets_0_type": "Name",
46-
"targets_0_id": "sensor_data",
47-
"value_type": "List",
48-
}
49-
)
43+
{
44+
"type": "Assign",
45+
"targets_0_type": "Name",
46+
"targets_0_id": "sensor_data",
47+
"value_type": "List",
48+
}
49+
)
5050
assert (
5151
sensor_data
5252
), "Are you creating a variable called `sensor_data` set equal to an empty list?"
@@ -73,33 +73,33 @@ def test_load_data_sensor_files_module1(parse):
7373
load_sensor_data.assign_()
7474
.match(
7575
{
76-
"1_type": "Assign",
77-
"1_targets_0_type": "Name",
78-
"1_targets_0_id": "sensor_files",
79-
"1_value_type": "Call",
80-
81-
"1_value_func_type": "Attribute",
82-
"1_value_func_value_type": "Name",
83-
"1_value_func_value_id": "glob",
84-
"1_value_func_attr": "glob",
85-
86-
"1_value_args_0_type": "Call",
87-
"1_value_args_0_func_type": "Attribute",
88-
"1_value_args_0_func_value_type": "Attribute",
89-
"1_value_args_0_func_value_value_type": "Name",
90-
"1_value_args_0_func_value_value_id": "os",
91-
"1_value_args_0_func_value_attr": "path",
92-
"1_value_args_0_func_attr": "join",
93-
94-
"1_value_args_0_args_0_type": "Call",
95-
"1_value_args_0_args_0_func_type": "Attribute",
96-
"1_value_args_0_args_0_func_value_type": "Name",
97-
"1_value_args_0_args_0_func_value_id": "os",
98-
"1_value_args_0_args_0_func_attr": "getcwd",
99-
"1_value_args_0_args_1_type": "Constant",
100-
"1_value_args_0_args_1_value": "datasets",
101-
"1_value_args_0_args_2_type": "Constant",
102-
"1_value_args_0_args_2_value": "*.csv"
76+
"1_type": "Assign",
77+
"1_targets_0_type": "Name",
78+
"1_targets_0_id": "sensor_files",
79+
"1_value_type": "Call",
80+
81+
"1_value_func_type": "Attribute",
82+
"1_value_func_value_type": "Name",
83+
"1_value_func_value_id": "glob",
84+
"1_value_func_attr": "glob",
85+
86+
"1_value_args_0_type": "Call",
87+
"1_value_args_0_func_type": "Attribute",
88+
"1_value_args_0_func_value_type": "Attribute",
89+
"1_value_args_0_func_value_value_type": "Name",
90+
"1_value_args_0_func_value_value_id": "os",
91+
"1_value_args_0_func_value_attr": "path",
92+
"1_value_args_0_func_attr": "join",
93+
94+
"1_value_args_0_args_0_type": "Call",
95+
"1_value_args_0_args_0_func_type": "Attribute",
96+
"1_value_args_0_args_0_func_value_type": "Name",
97+
"1_value_args_0_args_0_func_value_id": "os",
98+
"1_value_args_0_args_0_func_attr": "getcwd",
99+
"1_value_args_0_args_1_type": "Constant",
100+
"1_value_args_0_args_1_value": "datasets",
101+
"1_value_args_0_args_2_type": "Constant",
102+
"1_value_args_0_args_2_value": "*.csv"
103103
}
104104
)
105105
.exists()
@@ -109,7 +109,6 @@ def test_load_data_sensor_files_module1(parse):
109109
), "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()?"
110110

111111

112-
113112
@pytest.mark.test_load_data_sensor_files_query_module1
114113
def test_load_data_sensor_files_query_module1(parse):
115114

@@ -120,7 +119,8 @@ def test_load_data_sensor_files_query_module1(parse):
120119
load_data = parse("load_data")
121120
assert load_data.success, load_data.message
122121

123-
sensor_files = load_data.query("glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv'))")
122+
sensor_files = load_data.query(
123+
"glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv'))")
124124
sensor_files_exists = sensor_files.exists()
125125
assert (
126126
sensor_files_exists
@@ -147,7 +147,7 @@ def test_load_data_for_files_module1(parse):
147147
assert (
148148
load_sensor_data.exists()
149149
), "Are you defining a function called `load_sensor_data` with the correct arguments?"
150-
150+
151151
# print(json.dumps(load_sensor_data.for_().n, indent=2)) # TODO Remove
152152
# print(json.dumps(load_sensor_data.assign_().n, indent=2))
153153
# print(json.dumps(load_sensor_data.returns_call().n, indent=2))
@@ -169,20 +169,20 @@ def test_load_data_for_files_module1(parse):
169169
assert (
170170
first_for_exists
171171
), 'Do you have a `for` loop, looping through `sensor_files`? Is the current loop value called `sensor_file`?'
172-
172+
173173
with_exists = (
174174
load_sensor_data.for_()
175175
.match(
176176
{
177-
"0_type": "With",
178-
"0_items_0_type": "withitem",
179-
"0_items_0_context_expr_type": "Call",
180-
"0_items_0_context_expr_func_type": "Name",
181-
"0_items_0_context_expr_func_id": "open",
182-
"0_items_0_context_expr_args_0_type": "Name",
183-
"0_items_0_context_expr_args_0_id": "sensor_file",
184-
"0_items_0_optional_vars_type": "Name",
185-
"0_items_0_optional_vars_id": "data_file"
177+
"0_type": "With",
178+
"0_items_0_type": "withitem",
179+
"0_items_0_context_expr_type": "Call",
180+
"0_items_0_context_expr_func_type": "Name",
181+
"0_items_0_context_expr_func_id": "open",
182+
"0_items_0_context_expr_args_0_type": "Name",
183+
"0_items_0_context_expr_args_0_id": "sensor_file",
184+
"0_items_0_optional_vars_type": "Name",
185+
"0_items_0_optional_vars_id": "data_file"
186186
}
187187
)
188188
.exists()
@@ -195,20 +195,20 @@ def test_load_data_for_files_module1(parse):
195195
load_sensor_data.for_()
196196
.match(
197197
{
198-
"0_body_0_type": "Assign",
199-
"0_body_0_targets_0_type": "Name",
200-
"0_body_0_targets_0_id": "data_reader",
201-
"0_body_0_value_type": "Call",
202-
"0_body_0_value_func_type": "Attribute",
203-
"0_body_0_value_func_value_type": "Name",
204-
"0_body_0_value_func_value_id": "csv",
205-
"0_body_0_value_func_attr": "DictReader",
206-
"0_body_0_value_args_0_type": "Name",
207-
"0_body_0_value_args_0_id": "data_file",
208-
"0_body_0_value_keywords_0_type": "keyword",
209-
"0_body_0_value_keywords_0_arg": "delimiter",
210-
"0_body_0_value_keywords_0_value_type": "Constant",
211-
"0_body_0_value_keywords_0_value_value": ",",
198+
"0_body_0_type": "Assign",
199+
"0_body_0_targets_0_type": "Name",
200+
"0_body_0_targets_0_id": "data_reader",
201+
"0_body_0_value_type": "Call",
202+
"0_body_0_value_func_type": "Attribute",
203+
"0_body_0_value_func_value_type": "Name",
204+
"0_body_0_value_func_value_id": "csv",
205+
"0_body_0_value_func_attr": "DictReader",
206+
"0_body_0_value_args_0_type": "Name",
207+
"0_body_0_value_args_0_id": "data_file",
208+
"0_body_0_value_keywords_0_type": "keyword",
209+
"0_body_0_value_keywords_0_arg": "delimiter",
210+
"0_body_0_value_keywords_0_value_type": "Constant",
211+
"0_body_0_value_keywords_0_value_value": ",",
212212
}
213213
)
214214
.exists()
@@ -221,31 +221,31 @@ def test_load_data_for_files_module1(parse):
221221
load_sensor_data.for_()
222222
.match(
223223
{
224-
"0_body_1_type": "For",
225-
"0_body_1_target_type": "Name",
226-
"0_body_1_target_id": "row",
227-
"0_body_1_iter_type": "Name",
228-
"0_body_1_iter_id": "data_reader",
224+
"0_body_1_type": "For",
225+
"0_body_1_target_type": "Name",
226+
"0_body_1_target_id": "row",
227+
"0_body_1_iter_type": "Name",
228+
"0_body_1_iter_id": "data_reader",
229229
}
230230
)
231231
.exists()
232232
)
233233
assert (
234234
second_for_exist
235235
), 'Do you have a second `for` loop, looping through `data_reader`? Is the current loop value called `row`?'
236-
236+
237237
sensor_data_append = (
238238
load_sensor_data.for_()
239239
.match(
240240
{
241-
"0_body_1_body_0_type": "Expr",
242-
"0_body_1_body_0_value_type": "Call",
243-
"0_body_1_body_0_value_func_type": "Attribute",
244-
"0_body_1_body_0_value_func_value_type": "Name",
245-
"0_body_1_body_0_value_func_value_id": "sensor_data",
246-
"0_body_1_body_0_value_func_attr": "append",
247-
"0_body_1_body_0_value_args_0_type": "Name",
248-
"0_body_1_body_0_value_args_0_id": "row"
241+
"0_body_1_body_0_type": "Expr",
242+
"0_body_1_body_0_value_type": "Call",
243+
"0_body_1_body_0_value_func_type": "Attribute",
244+
"0_body_1_body_0_value_func_value_type": "Name",
245+
"0_body_1_body_0_value_func_value_id": "sensor_data",
246+
"0_body_1_body_0_value_func_attr": "append",
247+
"0_body_1_body_0_value_args_0_type": "Name",
248+
"0_body_1_body_0_value_args_0_id": "row"
249249
}
250250
)
251251
.exists()
@@ -257,4 +257,58 @@ def test_load_data_for_files_module1(parse):
257257
returns_load_sensor_data = load_sensor_data.returns("sensor_data")
258258
assert (
259259
returns_load_sensor_data
260-
), 'Are you returning `sensor_data` from `load_sensor_data` function?'
260+
), 'Are you returning `sensor_data` from `load_sensor_data` function?'
261+
262+
263+
@pytest.mark.test_load_data_return_module1
264+
def test_sensor_load_data_return_module1(parse):
265+
# from load_data import load_sensor_data
266+
# data = load_sensor_data()
267+
# print("Loaded records {}".format(len(data)))
268+
269+
sensor = parse("sensor_app")
270+
assert sensor.success, sensor.message
271+
272+
load_sensor_data_import = sensor.from_imports(
273+
"load_data", "load_sensor_data")
274+
assert load_sensor_data_import, "Are you importing `load_sensor_data` from load_data?"
275+
276+
# print(json.dumps(sensor.assign_().n, indent=2))
277+
# print(json.dumps(sensor.calls().n, indent=2))
278+
# assert False
279+
280+
data = sensor.assign_().match(
281+
{
282+
"type": "Assign",
283+
"targets_0_type": "Name",
284+
"targets_0_id": "data",
285+
"value_type": "Call",
286+
"value_func_type": "Name",
287+
"value_func_id": "load_sensor_data",
288+
}
289+
)
290+
assert (
291+
data
292+
), "Are you creating a variable called `data` set equal to `load_sensor_data()` function?"
293+
294+
print_data = sensor.calls().match(
295+
{
296+
"type": "Expr",
297+
"value_type": "Call",
298+
"value_func_type": "Name",
299+
"value_func_id": "print",
300+
"value_args_0_type": "Call",
301+
"value_args_0_func_type": "Attribute",
302+
"value_args_0_func_value_type": "Constant",
303+
"value_args_0_func_value_value": "Loaded records {}",
304+
"value_args_0_func_attr": "format",
305+
"value_args_0_args_0_type": "Call",
306+
"value_args_0_args_0_func_type": "Name",
307+
"value_args_0_args_0_func_id": "len",
308+
"value_args_0_args_0_args_0_type": "Name",
309+
"value_args_0_args_0_args_0_id": "data"
310+
}
311+
)
312+
assert (
313+
print_data
314+
), "Are you calling `print()` and passing in `format()`? Are you passing 1 values to `format()` `len(data)`"

0 commit comments

Comments
 (0)