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

Latest commit

 

History

History
History
407 lines (351 loc) · 13.4 KB

File metadata and controls

407 lines (351 loc) · 13.4 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
import pytest
import json
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):
# import os
# import glob
# import csv
load_data = parse("load_data")
assert load_data.success, load_data.message
os_import = load_data.imports("os")
assert os_import, "Are you importing `os`?"
glob_import = load_data.imports("glob")
assert glob_import, "Are you importing `glob`?"
csv_import = load_data.imports("csv")
assert csv_import, "Are you importing `csv`?"
@pytest.mark.test_load_data_load_sensor_func_module1
def test_load_data_load_sensor_func_module1(parse):
# def load_sensor_data():
# sensor_data = []
load_data = parse("load_data")
assert load_data.success, load_data.message
load_sensor_data = load_data.defines("load_sensor_data")
assert (
load_sensor_data.exists()
), "Are you defining a function called `load_sensor_data` with no input parameters?"
sensor_data = load_sensor_data.assign_().match(
{
"type": "Assign",
"targets_0_type": "Name",
"targets_0_id": "sensor_data",
"value_type": "List",
}
)
assert (
sensor_data
), "Are you creating a variable called `sensor_data` set equal to an empty list?"
@pytest.mark.test_load_data_sensor_files_module1
def test_load_data_sensor_files_module1(parse):
# ....
# sensor_files = glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv'))
load_data = parse("load_data")
assert load_data.success, load_data.message
# load_sensor_data = load_data.query("def load_sensor_data(): ??")
load_sensor_data = load_data.defines("load_sensor_data")
load_sensor_data_exists = load_sensor_data.exists()
assert (
load_sensor_data_exists
), "Are you defining a function called `load_sensor_data` with the correct arguments?"
sensor_files = (
load_sensor_data.assign_()
.match(
{
"1_type": "Assign",
"1_targets_0_type": "Name",
"1_targets_0_id": "sensor_files",
"1_value_type": "Call",
"1_value_func_type": "Attribute",
"1_value_func_value_type": "Name",
"1_value_func_value_id": "glob",
"1_value_func_attr": "glob",
"1_value_args_0_type": "Call",
"1_value_args_0_func_type": "Attribute",
"1_value_args_0_func_value_type": "Attribute",
"1_value_args_0_func_value_value_type": "Name",
"1_value_args_0_func_value_value_id": "os",
"1_value_args_0_func_value_attr": "path",
"1_value_args_0_func_attr": "join",
"1_value_args_0_args_0_type": "Call",
"1_value_args_0_args_0_func_type": "Attribute",
"1_value_args_0_args_0_func_value_type": "Name",
"1_value_args_0_args_0_func_value_id": "os",
"1_value_args_0_args_0_func_attr": "getcwd",
"1_value_args_0_args_1_type": "Constant",
"1_value_args_0_args_1_value": "datasets",
"1_value_args_0_args_2_type": "Constant",
"1_value_args_0_args_2_value": "*.csv"
}
)
.exists()
)
assert (
sensor_files
), "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):
# ....
# for sensor_file in sensor_files:
# with open(sensor_file) as data_file:
# data_reader = csv.DictReader(data_file, delimiter=',')
load_data = parse("load_data")
assert load_data.success, load_data.message
# load_sensor_data = load_data.defines("load_sensor_data")
load_sensor_data = load_data.query("def load_sensor_data(): ??")
assert (
load_sensor_data.exists()
), "Are you defining a function called `load_sensor_data` with the correct arguments?"
first_for_exists = (
load_sensor_data.for_()
.match(
{
"target_type": "Name",
"target_id": "sensor_file",
"iter_type": "Name",
"iter_id": "sensor_files",
}
)
.exists()
)
assert (
first_for_exists
), 'Do you have a `for` loop, looping through `sensor_files`? Is the current loop value called `sensor_file`?'
with_exists = (
load_sensor_data.for_()
.match(
{
"0_type": "With",
"0_items_0_type": "withitem",
"0_items_0_context_expr_type": "Call",
"0_items_0_context_expr_func_type": "Name",
"0_items_0_context_expr_func_id": "open",
"0_items_0_context_expr_args_0_type": "Name",
"0_items_0_context_expr_args_0_id": "sensor_file",
"0_items_0_optional_vars_type": "Name",
"0_items_0_optional_vars_id": "data_file"
}
)
.exists()
)
assert (
with_exists
), "Do you have a call to `open` in your `with` code and are you passing `open` the correct argument?"
data_reader = (
load_sensor_data.for_()
.match(
{
"0_body_0_type": "Assign",
"0_body_0_targets_0_type": "Name",
"0_body_0_targets_0_id": "data_reader",
"0_body_0_value_type": "Call",
"0_body_0_value_func_type": "Attribute",
"0_body_0_value_func_value_type": "Name",
"0_body_0_value_func_value_id": "csv",
"0_body_0_value_func_attr": "DictReader",
"0_body_0_value_args_0_type": "Name",
"0_body_0_value_args_0_id": "data_file",
"0_body_0_value_keywords_0_type": "keyword",
"0_body_0_value_keywords_0_arg": "delimiter",
"0_body_0_value_keywords_0_value_type": "Constant",
"0_body_0_value_keywords_0_value_value": ",",
}
)
.exists()
)
assert (
data_reader
), "Are you assigning `data_reader` the result of `csv.DictReader()` with the correct input argument and delimeter?"
@pytest.mark.test_load_data_load_recs_module1
def test_load_data_load_recs_module1(parse):
# def load_sensor_data():
# ....
# for row in data_reader:
# sensor_data.append(row)
# return sensor_data
load_data = parse("load_data")
assert load_data.success, load_data.message
load_sensor_data = load_data.query("def load_sensor_data(): ??")
assert (
load_sensor_data.exists()
), "Are you defining a function called `load_sensor_data` with the correct arguments?"
first_for_exists = (
load_sensor_data.for_()
.match(
{
"target_type": "Name",
"target_id": "sensor_file",
"iter_type": "Name",
"iter_id": "sensor_files",
}
)
.exists()
)
assert (
first_for_exists
), 'Do you have a `for` loop, looping through `sensor_files`? Is the current loop value called `sensor_file`?'
with_exists = (
load_sensor_data.for_()
.match(
{
"0_type": "With",
"0_items_0_type": "withitem",
"0_items_0_context_expr_type": "Call",
"0_items_0_context_expr_func_type": "Name",
"0_items_0_context_expr_func_id": "open",
"0_items_0_context_expr_args_0_type": "Name",
"0_items_0_context_expr_args_0_id": "sensor_file",
"0_items_0_optional_vars_type": "Name",
"0_items_0_optional_vars_id": "data_file"
}
)
.exists()
)
assert (
with_exists
), "Do you have a call to `open` in your `with` code and are you passing `open` the correct argument?"
data_reader = (
load_sensor_data.for_()
.match(
{
"0_body_0_type": "Assign",
"0_body_0_targets_0_type": "Name",
"0_body_0_targets_0_id": "data_reader",
"0_body_0_value_type": "Call",
"0_body_0_value_func_type": "Attribute",
"0_body_0_value_func_value_type": "Name",
"0_body_0_value_func_value_id": "csv",
"0_body_0_value_func_attr": "DictReader",
"0_body_0_value_args_0_type": "Name",
"0_body_0_value_args_0_id": "data_file",
"0_body_0_value_keywords_0_type": "keyword",
"0_body_0_value_keywords_0_arg": "delimiter",
"0_body_0_value_keywords_0_value_type": "Constant",
"0_body_0_value_keywords_0_value_value": ",",
}
)
.exists()
)
assert (
data_reader
), "Are you assigning `data_reader` the result of `csv.DictReader()` with the correct input argument and delimeter?"
second_for_exist = (
load_sensor_data.for_()
.match(
{
"0_body_1_type": "For",
"0_body_1_target_type": "Name",
"0_body_1_target_id": "row",
"0_body_1_iter_type": "Name",
"0_body_1_iter_id": "data_reader",
}
)
.exists()
)
assert (
second_for_exist
), """Do you have a second `for` loop, looping through `data_reader`?
Is the current loop value called `row`?
Is this loop part of the `with` block?"""
sensor_data_append = (
load_sensor_data.for_()
.match(
{
"0_body_1_body_0_type": "Expr",
"0_body_1_body_0_value_type": "Call",
"0_body_1_body_0_value_func_type": "Attribute",
"0_body_1_body_0_value_func_value_type": "Name",
"0_body_1_body_0_value_func_value_id": "sensor_data",
"0_body_1_body_0_value_func_attr": "append",
"0_body_1_body_0_value_args_0_type": "Name",
"0_body_1_body_0_value_args_0_id": "row"
}
)
.exists()
)
assert (
sensor_data_append
), 'Are you appending the `row` records to the `sensor_data` list?'
returns_load_sensor_data = load_sensor_data.returns("sensor_data")
assert (
returns_load_sensor_data
), 'Are you returning `sensor_data` from `load_sensor_data` function?'
# Test Length of return value
# recs = load_sensor_data() # this is defined above
assert (
len(recs) == 2000
), """The length of your sensor_data list is incorrect.
Are you scanning both data files?"""
@pytest.mark.test_sensor_app_load_data_return_module1
def test_sensor_app_load_data_return_module1(parse):
# 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")
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")
"""
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")"""
######################################################
# Now we can test the actual module
######################################################
# from load_data import load_sensor_data
# 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?"
data = (
sensor.assign_().match(
{
"1_type": "Assign",
"1_targets_0_type": "Name",
"1_targets_0_id": "data",
"1_value_type": "Call",
"1_value_func_type": "Name",
"1_value_func_id": "load_sensor_data",
}
)
.exists()
)
assert (
data
), "Are you creating a variable called `data` set equal to `load_sensor_data()` function?"
Morty Proxy This is a proxified and sanitized view of the page, visit original site.