-
Notifications
You must be signed in to change notification settings - Fork 313
/
test_validator.py
613 lines (508 loc) · 29.2 KB
/
test_validator.py
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
import pytest
import io
import os
from textwrap import dedent
from nbformat.v4 import new_output
from ..validator import Validator
from . import (
create_code_cell, create_text_cell)
from io import StringIO
from nbgrader.validator import Validator
@pytest.fixture
def validator() -> Validator:
return Validator()
@pytest.fixture
def stream() -> StringIO:
return io.StringIO()
class TestValidator(object):
def _add_error(self, cell):
cell.outputs.append(new_output(
"error",
ename="Error",
evalue="oh noes, an error occurred!",
traceback=["oh noes, an error occurred!"]
))
return cell
def _add_error_2(self, cell):
cell.outputs.append(new_output(
"stream",
name="stderr",
text="Error Message"
))
return cell
def test_indent(self, validator):
# test normal indenting
assert validator._indent("Hello, world!") == " Hello, world!"
assert validator._indent("Hello,\n world!") == " Hello,\n world!"
# test truncation
validator.width = 10
assert validator._indent("Hello, world!") == " Hel..."
assert validator._indent("Hello,\n world!") == " Hel...\n wo..."
# test that ansi escape sequences are removed and not counted towards
# the line width
assert validator._indent("\x1b[30mHello, world!\x1b[0m") == " Hel..."
assert validator._indent("\x1b[30mHello,\n world!\x1b[0m") == " Hel...\n wo..."
def test_print_type_changed(self, validator, stream):
cell = create_code_cell()
validator.stream = stream
validator.width = 20
validator._print_type_changed("markdown", "code", cell.source.strip())
expected = dedent(
"""
====================
The following markdown cell has changed to a code cell:
print("someth...
### BEGIN SOL...
print("hello"...
### END SOLUT...
"""
)
assert stream.getvalue() == expected
def test_print_changed(self, validator, stream):
cell = create_code_cell()
validator.stream = stream
validator.width = 20
validator._print_changed(cell.source.strip())
expected = dedent(
"""
====================
The following cell has changed:
print("someth...
### BEGIN SOL...
print("hello"...
### END SOLUT...
"""
)
assert stream.getvalue() == expected
def test_print_error_code_cell(self, validator, stream):
cell = create_code_cell()
validator.stream = stream
validator.width = 20
validator._print_error(cell.source.strip(), validator._extract_error(cell))
expected = dedent(
"""
====================
The following cell failed:
print("someth...
### BEGIN SOL...
print("hello"...
### END SOLUT...
The error was:
You did not p...
"""
)
assert stream.getvalue() == expected
def test_print_error_code_cell_error(self, validator, stream):
cell = self._add_error(create_code_cell())
validator.stream = stream
validator.width = 20
validator._print_error(cell.source.strip(), validator._extract_error(cell))
expected = dedent(
"""
====================
The following cell failed:
print("someth...
### BEGIN SOL...
print("hello"...
### END SOLUT...
The error was:
oh noes, an e...
"""
)
assert stream.getvalue() == expected
def test_print_error_code_cell_error_2(self, validator, stream):
cell = self._add_error_2(create_code_cell())
validator.stream = stream
validator.width = 20
validator._print_error(cell.source.strip(), validator._extract_error(cell))
expected = dedent(
"""
====================
The following cell failed:
print("someth...
### BEGIN SOL...
print("hello"...
### END SOLUT...
The error was:
Error Message
"""
)
print(stream.getvalue())
assert stream.getvalue() == expected
def test_print_error_markdown_cell(self, validator, stream):
cell = create_text_cell()
validator.stream = stream
validator.width = 20
validator._print_error(cell.source.strip(), validator._extract_error(cell))
expected = dedent(
"""
====================
The following cell failed:
this is the a...
The error was:
You did not p...
"""
)
assert stream.getvalue() == expected
def test_print_pass(self, validator, stream):
cell = create_code_cell()
validator.stream = stream
validator.width = 20
validator._print_pass(cell.source.strip())
expected = dedent(
"""
====================
The following cell passed:
print("someth...
### BEGIN SOL...
print("hello"...
### END SOLUT...
"""
)
assert stream.getvalue() == expected
def test_print_num_type_changed_0(self, validator, stream):
validator.stream = stream
validator._print_num_type_changed(0)
assert stream.getvalue() == ""
def test_print_num_type_changed_1(self, validator, stream):
validator.stream = stream
validator._print_num_type_changed(1)
assert stream.getvalue().startswith("THE TYPES OF 1 CELL(S) HAVE CHANGED!")
def test_print_num_changed_0(self, validator: Validator, stream: StringIO) -> None:
validator.stream = stream
validator._print_num_changed(0)
assert stream.getvalue() == ""
def test_print_num_changed_1(self, validator, stream):
validator.stream = stream
validator._print_num_changed(1)
assert stream.getvalue().startswith("THE CONTENTS OF 1 TEST CELL(S) HAVE CHANGED!")
def test_print_num_failed(self, validator, stream):
validator.stream = stream
validator._print_num_failed(0)
assert stream.getvalue() == "Success! Your notebook passes all the tests.\n"
def test_print_num_failed_1(self, validator, stream):
validator.stream = stream
validator._print_num_failed(1)
assert stream.getvalue().startswith("VALIDATION FAILED ON 1 CELL(S)!")
def test_print_num_passed(self, validator, stream):
validator.stream = stream
validator._print_num_passed(0)
assert stream.getvalue() == "Success! The notebook does not pass any tests.\n"
def test_print_num_passed_1(self, validator, stream):
validator.stream = stream
validator._print_num_passed(1)
assert stream.getvalue().startswith("NOTEBOOK PASSED ON 1 CELL(S)!")
def test_submitted_unchanged(self, validator, stream):
"""Does the validation fail on an unchanged notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-unchanged.ipynb")
validator.stream = stream
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "VALIDATION FAILED ON 3 CELL(S)! If you submit your assignment as it is, you WILL NOT"
def test_submitted_changed(self, validator, stream):
"""Does the validation pass on an changed notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-changed.ipynb")
validator.stream = stream
validator.validate_and_print(filename)
assert stream.getvalue() == "Success! Your notebook passes all the tests.\n"
def test_invert_submitted_unchanged(self, validator, stream):
"""Does the inverted validation pass on an unchanged notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-unchanged.ipynb")
validator.stream = stream
validator.invert = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "NOTEBOOK PASSED ON 1 CELL(S)!"
def test_invert_submitted_changed(self, validator, stream):
"""Does the inverted validation fail on a changed notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "NOTEBOOK PASSED ON 2 CELL(S)!"
def test_grade_cell_changed(self, validator, stream):
"""Does the validate fail if a grade cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
validator.stream = stream
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE CONTENTS OF 1 TEST CELL(S) HAVE CHANGED! This might mean that even though the tests"
def test_grade_cell_changed_ignore_checksums(self, validator, stream):
"""Does the validate pass if a grade cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
validator.stream = stream
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "Success! Your notebook passes all the tests."
def test_invert_grade_cell_changed(self, validator, stream):
"""Does the validate fail if a grade cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE CONTENTS OF 1 TEST CELL(S) HAVE CHANGED! This might mean that even though the tests"
def test_invert_grade_cell_changed_ignore_checksums(self, validator, stream):
"""Does the validate fail if a grade cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "NOTEBOOK PASSED ON 2 CELL(S)!"
def test_submitted_unchanged_ignore_checksums(self, validator, stream):
"""Does the validation fail on an unchanged notebook with ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-unchanged.ipynb")
validator.stream = stream
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "VALIDATION FAILED ON 1 CELL(S)! If you submit your assignment as it is, you WILL NOT"
def test_locked_cell_changed(self, validator, stream):
"""Does the validate fail if a locked cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
validator.stream = stream
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE CONTENTS OF 2 TEST CELL(S) HAVE CHANGED! This might mean that even though the tests"
def test_locked_cell_changed_ignore_checksums(self, validator: Validator, stream: StringIO) -> None:
"""Does the validate pass if a locked cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
validator.stream = stream
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "VALIDATION FAILED ON 1 CELL(S)! If you submit your assignment as it is, you WILL NOT"
def test_invert_locked_cell_changed(self, validator, stream):
"""Does the validate fail if a locked cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE CONTENTS OF 2 TEST CELL(S) HAVE CHANGED! This might mean that even though the tests"
def test_invert_locked_cell_changed_ignore_checksums(self, validator, stream):
"""Does the validate fail if a locked cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "NOTEBOOK PASSED ON 1 CELL(S)!"
def test_submitted_unchanged_json(self, validator):
"""Does the validation fail on an unchanged notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-unchanged.ipynb")
output = validator.validate(filename)
assert list(output.keys()) == ["failed"]
assert len(output["failed"]) == 3
assert output["failed"][0]["source"] == "assert a == 1"
assert output["failed"][1]["source"] == "YOUR ANSWER HERE"
assert output["failed"][1]["error"] == "You did not provide a response."
assert output["failed"][2]["source"] == "# YOUR CODE HERE\nraise NotImplementedError()"
def test_submitted_changed_json(self, validator):
"""Does the validation pass on an changed notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-changed.ipynb")
output = validator.validate(filename)
assert list(output.keys()) == []
def test_invert_submitted_unchanged_json(self, validator):
"""Does the inverted validation pass on an unchanged notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-unchanged.ipynb")
validator.invert = True
output = validator.validate(filename)
assert list(output.keys()) == ["passed"]
assert len(output["passed"]) == 1
assert output["passed"][0]["source"] == 'print("Success!")'
def test_invert_submitted_changed_json(self, validator):
"""Does the inverted validation fail on a changed notebook?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-changed.ipynb")
validator.invert = True
output = validator.validate(filename)
assert list(output.keys()) == ["passed"]
assert len(output["passed"]) == 2
assert output["passed"][0]["source"] == 'print("Success!")'
assert output["passed"][1]["source"] == 'assert a == 1'
def test_grade_cell_changed_json(self, validator):
"""Does the validate fail if a grade cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
output = validator.validate(filename)
assert list(output.keys()) == ["changed"]
assert len(output["changed"]) == 1
assert output["changed"][0]["source"] == '#assert a == 1'
def test_grade_cell_changed_ignore_checksums_json(self, validator):
"""Does the validate pass if a grade cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == []
def test_invert_grade_cell_changed_json(self, validator):
"""Does the validate fail if a grade cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
validator.invert = True
output = validator.validate(filename)
assert list(output.keys()) == ["changed"]
assert len(output["changed"]) == 1
assert output["changed"][0]["source"] == '#assert a == 1'
def test_invert_grade_cell_changed_ignore_checksums_json(self, validator):
"""Does the validate fail if a grade cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-changed.ipynb")
validator.invert = True
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["passed"]
assert len(output["passed"]) == 2
assert output["passed"][0]["source"] == 'print("Success!")'
assert output["passed"][1]["source"] == '#assert a == 1'
def test_submitted_unchanged_ignore_checksums_json(self, validator):
"""Does the validation fail on an unchanged notebook with ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-unchanged.ipynb")
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["failed"]
assert len(output["failed"]) == 1
assert output["failed"][0]["source"] == 'assert a == 1'
def test_locked_cell_changed_json(self, validator):
"""Does the validate fail if a locked cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
output = validator.validate(filename)
assert list(output.keys()) == ["changed"]
assert len(output["changed"]) == 2
assert output["changed"][0]["source"] == '#print("Don\'t change this cell!")'
assert output["changed"][1]["source"] == "This cell shouldn't \nbe changed."
def test_locked_cell_changed_ignore_checksums_json(self, validator):
"""Does the validate pass if a locked cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["failed"]
assert len(output["failed"]) == 1
assert output["failed"][0]["source"] == 'assert a == 1'
def test_invert_locked_cell_changed_json(self, validator):
"""Does the validate fail if a locked cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
validator.invert = True
output = validator.validate(filename)
assert list(output.keys()) == ["changed"]
assert len(output["changed"]) == 2
assert output["changed"][0]["source"] == '#print("Don\'t change this cell!")'
assert output["changed"][1]["source"] == "This cell shouldn't \nbe changed."
def test_invert_locked_cell_changed_ignore_checksums_json(self, validator):
"""Does the validate fail if a locked cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-locked-cell-changed.ipynb")
validator.invert = True
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["passed"]
assert len(output["passed"]) == 1
assert output["passed"][0]["source"] == 'print("Success!")'
def test_answer_cell_type_changed(self, validator: Validator, stream: StringIO) -> None:
"""Does the validate fail if the type of a answer cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
validator.stream = stream
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_answer_cell_type_changed_ignore_checksums(self, validator, stream):
"""Does the validate fail if the type of a answer cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
validator.stream = stream
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_invert_answer_cell_type_changed(self, validator, stream):
"""Does the validate fail if the type of a answer cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_invert_answer_cell_type_changed_ignore_checksums(self, validator, stream):
"""Does the validate fail if the type of a answer cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_answer_cell_type_changed_json(self, validator):
"""Does the validate fail if the type of a answer cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "# YOUR CODE HERE\nraise NotImplementedError()"
def test_answer_cell_type_changed_ignore_checksums_json(self, validator):
"""Does the validate pass if the type of a answer cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "# YOUR CODE HERE\nraise NotImplementedError()"
def test_invert_answer_cell_type_changed_json(self, validator):
"""Does the validate fail if the type of a answer cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
validator.invert = True
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "# YOUR CODE HERE\nraise NotImplementedError()"
def test_invert_answer_cell_type_changed_ignore_checksums_json(self, validator):
"""Does the validate fail if the type of a answer cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-answer-cell-type-changed.ipynb")
validator.invert = True
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "# YOUR CODE HERE\nraise NotImplementedError()"
def test_grade_cell_type_changed(self, validator, stream):
"""Does the validate fail if the type of a grade cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
validator.stream = stream
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_grade_cell_type_changed_ignore_checksums(self, validator, stream):
"""Does the validate fail if the type of a grade cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
validator.stream = stream
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_invert_grade_cell_type_changed(self, validator, stream):
"""Does the validate fail if the type of a grade cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_invert_grade_cell_type_changed_ignore_checksums(self, validator, stream):
"""Does the validate fail if the type of a grade cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
validator.stream = stream
validator.invert = True
validator.ignore_checksums = True
validator.validate_and_print(filename)
assert stream.getvalue().split("\n")[0] == "THE TYPES OF 1 CELL(S) HAVE CHANGED! This might mean that even though the tests are"
def test_grade_cell_type_changed_json(self, validator):
"""Does the validate fail if the type of a grade cell has changed?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "assert a == 1"
def test_grade_cell_type_changed_ignore_checksums_json(self, validator):
"""Does the validate pass if the type of a grade cell has changed but we're ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "assert a == 1"
def test_invert_grade_cell_type_changed_json(self, validator):
"""Does the validate fail if the type of a grade cell has changed, even with --invert?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
validator.invert = True
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "assert a == 1"
def test_invert_grade_cell_type_changed_ignore_checksums_json(self, validator):
"""Does the validate fail if the type of a grade cell has changed with --invert and ignoring checksums?"""
filename = os.path.join(os.path.dirname(__file__), "preprocessors", "files", "submitted-grade-cell-type-changed.ipynb")
validator.invert = True
validator.ignore_checksums = True
output = validator.validate(filename)
assert list(output.keys()) == ["type_changed"]
assert len(output["type_changed"]) == 1
assert output["type_changed"][0]["source"] == "assert a == 1"