-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckLab3.py
More file actions
573 lines (496 loc) · 27.4 KB
/
Copy pathCheckLab3.py
File metadata and controls
573 lines (496 loc) · 27.4 KB
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
#!/usr/bin/env python3
'''
Name: CheckLab3.py
Updated: September 19, 2019 by Raymond Chan
Reasons: (1) for Python version 3.6.8
(2) add report header with user and system information
(3) update description for each unit test
Updated: September 25, 2019 by Raymond Chan
Reasons: (1) add Linux system version to report header
Usage:
Check all sections for the Lab 3
./CheckLab3 -f -v
Check a specific lab section
./CheckLab3 -f -v lab3x
Description:
This script is used to give students more feedback and hints while working
on Lab 3. Python scripts for Lab 3 and this script should be in the same
directory. All the Python scripts must use the correct naming scheme.
'''
import subprocess
import unittest
import sys
import os
import hashlib
import urllib.request
import socket
import time
#Import student files, do not give errors if they don't exist
#try:
# import lab3b as lab3bStudent
#except:
# """Could not find lab3b.py"""
##try:
# import lab3c as lab3cStudent
#except:
# """Could not find lab3c.py"""
class lab3a(unittest.TestCase):
"""All test cases for lab3a - functions & arguments"""
def test_0(self):
"""[Lab 3] - [Investigation 1] - [Part 4] - Functions - Test for file creation: ./lab3a.py"""
error_output = 'your file cannot be found (HINT: make sure you AND your file are in the correct directory)'
self.assertTrue(os.path.exists('./lab3a.py'), msg=error_output)
def test_1(self):
"""[Lab 3] - [Investigation 1] - [Part 4] - Functions - Test for errors running: ./lab3a.py"""
# Run students program
p = subprocess.Popen([sys.executable, './lab3a.py'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, err = p.communicate()
# Fail test if process returns a no zero exit status
return_code = p.wait()
error_output = 'your program exited with a error (HINT: make sure you copied the script exactly!)'
self.assertEqual(return_code, 0, msg=error_output)
def test_2(self):
"""[Lab 3] - [Investigation 1] - [Part 4] - Functions - Test for correct shebang line: ./lab3a.py"""
lab_file = open('./lab3a.py')
first_line = lab_file.readline()
lab_file.close()
error_output = 'your program does not have a shebang line(HINT: what should the first line contain)'
self.assertEqual(first_line.strip(), '#!/usr/bin/env python3', msg=error_output)
def test_4_function_return_text_value(self):
"""[Lab 3] - [Investigation 1] - [Part 4] - Functions - function print_out_text() has correct output"""
# Try to import before testing
try:
import lab3a as lab3aStudent
except:
self.fail('lab3a.py contains errors (HINT: make sure you copied the script exactly!')
expected_output = 'Good Morning Terry'
error_output = 'lab3a.py print_out_text() has wrong output (HINT: make sure you copied the script exactly!'
self.assertEqual(lab3aStudent.return_text_value(), expected_output, msg=error_output)
def test_5_function_return_number_value(self):
"""[Lab 3] - [Investigation 1] - [Part 4] - Functions - function print_out_text() has correct output"""
# Try to import before testing
try:
import lab3a as lab3aStudent
except:
self.fail('lab3a.py contains errors(HINT: make sure you copied the script exactly!')
expected_output = 15
error_output = 'lab3a.py print_out_text() has wrong output(HINT: make sure you copied the script exactly!'
self.assertEqual(lab3aStudent.return_number_value(), expected_output, msg=error_output)
class lab3b(unittest.TestCase):
"""All test cases for lab3b - functions & arguments"""
def test_0(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - Functions - Test for file creation: ./lab3b.py"""
error_output = 'your file cannot be found (HINT: make sure you AND your file are in the correct directory)'
self.assertTrue(os.path.exists('./lab3b.py'), msg=error_output)
def test_1(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - Functions - Test for errors running: ./lab3b.py"""
# Run students program
p = subprocess.Popen([sys.executable, './lab3b.py'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, err = p.communicate()
# Fail test if process returns a no zero exit status
return_code = p.wait()
error_output = 'your program exited with a error (HINT: make sure you copied the script exactly!)'
self.assertEqual(return_code, 0, msg=error_output)
def test_4_function_sum(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments - function sum_numbers() fails without 2 arguments"""
with self.assertRaises(Exception) as context:
import lab3b as lab3bStudent
lab3bStudent.sum_numbers()
def test_2(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - Functions - Test for correct shebang line: ./lab3b.py"""
lab_file = open('./lab3b.py')
first_line = lab_file.readline()
lab_file.close()
error_output = 'your program does not have a shebang line(HINT: what should the first line contain)'
self.assertEqual(first_line.strip(), '#!/usr/bin/env python3', msg=error_output)
def test_5_function_subtract(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments - function subtract_numbers() fails without 2 arguments"""
with self.assertRaises(Exception) as context:
import lab3b as lab3bStudent
lab3bStudent.subtract_numbers()
def test_6_function_multiply(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments - function multiply_numbers() fails without 2 arguments"""
with self.assertRaises(Exception) as context:
import lab3b as lab3bStudent
lab3bStudent.multiply_numbers()
def test_7_function_sum_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments - function add_numbers() adds correctly"""
# Try to import before testing
try:
import lab3b as lab3bStudent
except:
self.fail('lab3b.py contains errors(HINT: run the function and fix errors')
error_output = 'problem adding(HINT: sum_numbers(10, 5)'
self.assertEqual(str(lab3bStudent.sum_numbers(10, 5)), '15', msg=error_output)
def test_8_function_subtract_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments - function subtract_numbers() subtracts correctly"""
# Try to import before testing
try:
import lab3b as lab3bStudent
except:
self.fail('lab3b.py contains errors(HINT: run the function and fix errors')
error_output = 'problem subtracting(HINT: subtract_numbers(10, 5)'
self.assertEqual(str(lab3bStudent.subtract_numbers(10, 5)), '5', msg=error_output)
def test_9_function_multiply_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments - function multiply_numbers() multiplies correctly"""
# Try to import before testing
try:
import lab3b as lab3bStudent
except:
self.fail('lab3b.py contains errors(HINT: run the function and fix errors')
error_output = 'problem multiplying(HINT: multiply_numbers(10, 5)'
self.assertEqual(str(lab3bStudent.multiply_numbers(10, 5)), '50', msg=error_output)
class lab3c(unittest.TestCase):
"""All test cases for lab3c - functions & arguments & logic"""
def test_0(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - Functions - Test for file creation: ./lab3c.py"""
error_output = 'your file cannot be found(HINT: make sure you AND your file are in the correct directory)'
self.assertTrue(os.path.exists('./lab3c.py'), msg=error_output)
def test_1(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - Functions - Test for errors running: ./lab3c.py"""
# Run students program
p = subprocess.Popen([sys.executable, './lab3c.py'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, err = p.communicate()
# Fail test if process returns a no zero exit status
return_code = p.wait()
error_output = 'your program exited with a error(HINT: make sure you copied the script exactly!)'
self.assertEqual(return_code, 0, msg=error_output)
def test_4_function_sum(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() fails with 0 arguments"""
with self.assertRaises(Exception) as context:
lab3cStudent.operate()
def test_2(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - Functions - Test for correct shebang line: ./lab3X.py"""
lab_file = open('./lab3c.py')
first_line = lab_file.readline()
lab_file.close()
error_output = 'your program does not have a shebang line(HINT: what should the first line contain)'
self.assertEqual(first_line.strip(), '#!/usr/bin/env python3', msg=error_output)
def test_5_function_subtract(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() fails with 1 arguments"""
with self.assertRaises(Exception) as context:
lab3cStudent.operate(10)
def test_6_function_multiply(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() fails with 2 arguments"""
with self.assertRaises(Exception) as context:
lab3cStudent.operate(10, 5)
def test_7_function_sum_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() adds correctly test 1"""
# Try to import before testing
try:
import lab3c as lab3cStudent
except:
self.fail('lab3c.py contains errors(HINT: run the function and fix errors')
error_output = 'problem adding(HINT: operate(10, 5, \'add\')'
self.assertEqual(str(lab3cStudent.operate(10, 5, 'add')), '15', msg=error_output)
def test_8_function_subtract_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() subtracts correctly test 1"""
# Try to import before testing
try:
import lab3c as lab3cStudent
except:
self.fail('lab3c.py contains errors(HINT: run the function and fix errors')
error_output = 'problem subtracting(HINT: operate(10, 5, \'subtract\')'
self.assertEqual(str(lab3cStudent.operate(10, 5, 'subtract')), '5', msg=error_output)
def test_9_function_multiply_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() multiplies correctly test 1"""
# Try to import before testing
try:
import lab3c as lab3cStudent
except:
self.fail('lab3c.py contains errors(HINT: run the function and fix errors')
error_output = 'problem multiplying(HINT: operate(10, 5, \'multiply\')'
self.assertEqual(str(lab3cStudent.operate(10, 5, 'multiply')), '50', msg=error_output)
def test_a_function_sum_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() adds correctly test 2"""
# Try to import before testing
try:
import lab3c as lab3cStudent
except:
self.fail('lab3c.py contains errors(HINT: run the function and fix errors')
error_output = 'problem adding(HINT: operate(5, 50, \'add\')'
self.assertEqual(str(lab3cStudent.operate(5, 50, 'add')), '55', msg=error_output)
def test_b_function_subtract_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() subtracts correctly test 2"""
# Try to import before testing
try:
import lab3c as lab3cStudent
except:
self.fail('lab3c.py contains errors(HINT: run the function and fix errors')
error_output = 'problem subtracting(HINT: operate(5, 50, \'subtract\')'
self.assertEqual(str(lab3cStudent.operate(5, 50, 'subtract')), '-45', msg=error_output)
def test_c_function_multiply_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() multiplies correctly test 2"""
# Try to import before testing
try:
import lab3c as lab3cStudent
except:
self.fail('lab3c.py contains errors(HINT: run the function and fix errors')
error_output = 'problem multiplying(HINT: operate(5, 50, \'multiply\')'
self.assertEqual(str(lab3cStudent.operate(5, 50, 'multiply')), '250', msg=error_output)
def test_d_function_multiply_output(self):
"""[Lab 3] - [Investigation 2] - [Part 1] - functions & arguments & logic - function operate() fails with division"""
# Try to import before testing
try:
import lab3c as lab3cStudent
except:
self.fail('lab3c.py contains errors(HINT: run the function and fix errors')
error_output = 'function operate shows wrong output(HINT: the output must match exactly)'
self.assertEqual(str(lab3cStudent.operate(5, 50, 'divide')), 'Error: function operator can be "add", "subtract", or "multiply"')
class lab3d(unittest.TestCase):
"""All test cases for lab3d - functions & subprocess"""
def test_0(self):
"""[Lab 3] - [Investigation 2] - [Part 2] - Functions - Test for file creation: ./lab3d.py"""
error_output = 'your file cannot be found(HINT: make sure you AND your file are in the correct directory)'
self.assertTrue(os.path.exists('./lab3d.py'), msg=error_output)
def test_a(self):
"""[Lab 3] - [Investigation 2] - [Part 2] - Functions - Test for errors running: ./lab3d.py"""
# Run students program
p = subprocess.Popen([sys.executable, './lab3d.py'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, err = p.communicate()
# Fail test if process returns a non zero exit status
return_code = p.wait()
error_output = 'your program exited with a error (HINT: make sure you copied the script exactly!)'
self.assertEqual(return_code, 0, msg=error_output)
def test_a_function_free_space(self):
"""[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - Test function succeeds with 0 arguments"""
# Try to import before testing
try:
import lab3d as lab3dStudent
except:
self.fail('lab3d.py contains errors (HINT: run the function and fix errors')
# Test function
try:
dummy = lab3dStudent.free_space()
except:
self.fail('free_space() function contains errors (HINT: run the function and fix errors')
def test_a1(self):
"""[Lab 3] - [Investigation 2] - [Part 2] - Functions - Test for correct shebang line: ./lab3d.py"""
lab_file = open('./lab3d.py')
first_line = lab_file.readline().strip()
lab_file.close()
error_output = 'your program does not have a shebang line (HINT: what should the first line contain)'
self.assertEqual(first_line, '#!/usr/bin/env python3', msg=error_output)
def test_b_function_correct_output_free_space(self):
"""[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - Test output shows free space of root"""
# Try to import before testing
try:
import lab3d as lab3dStudent
except:
self.fail('lab3d.py contains errors (HINT: run the function and fix errors')
p = subprocess.Popen(["df -h | grep '/$' | awk '{print $4}'"],
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
stdout, err = p.communicate()
try:
error_output = 'wrong output (HINT: show root directory free space only)'
self.assertEqual(stdout.decode('utf-8').strip(),
lab3dStudent.free_space().decode('utf-8').strip(), msg=error_output)
except AttributeError:
error_output = 'did you already decode utf-8(HINT: you will need to do this later)'
# If they already decoded the string an error will be raised this except fixes problem
self.assertEqual(stdout.decode('utf-8').strip(), lab3dStudent.free_space().strip(),
msg=error_output)
def test_c_function_decode_free_space(self):
"""[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - decode to utf-8 with string.decode('utf-8') successfully"""
# Try to import before testing
try:
import lab3d as lab3dStudent
except:
self.fail('lab3d.py contains errors(HINT: run the function and fix errors')
p = subprocess.Popen(["df -h | grep '/$' | awk '{print $4}'"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, err = p.communicate()
error_output = 'output did not decode to utf-8(HINT: use string.decode(\'utf-8\') to decode)'
# encode is used to turn unicode strings into bytes, decode turns bytes into unicode strings
self.assertEqual(type(stdout.decode('utf-8')), type(lab3dStudent.free_space()), msg=error_output)
def test_d_function_strip_free_space(self):
"""[Lab 3] - [Investigation 2] - [Part 2] - functions & subprocess - strip the new line character with string.strip() successfully """
# Try to import before testing
try:
import lab3d as lab3dStudent
except:
self.fail('lab3d.py contains errors(HINT: run the function and fix errors')
p = subprocess.Popen(["df -h | grep '/$' | awk '{print $4}'"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, err = p.communicate()
error_output= 'output did not strip new line character(HINT: use string.strip() to remove)'
self.assertNotEqual(stdout.decode('utf-8'), lab3dStudent.free_space(), msg=error_output)
class lab3e(unittest.TestCase):
"""All test cases for - functions & lists"""
def test_0(self):
"""[Lab 3] - [Investigation 3] - [Part 1] - Functions - Test for file creation: ./lab3e.py"""
error_output = 'your file cannot be found(HINT: make sure you AND your file are in the correct directory)'
self.assertTrue(os.path.exists('./lab3e.py'), msg=error_output)
def test_a(self):
"""[Lab 3] - [Investigation 3] - [Part 1] - Functions - Test for errors running: ./lab3e.py"""
# Run students program
p = subprocess.Popen([sys.executable, './lab3e.py'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, err = p.communicate()
# Fail test if process returns a no zero exit status
return_code = p.wait()
error_output = 'your program exited with a error(HINT: make sure you copied the script exactly!)'
self.assertEqual(return_code, 0, msg=error_output)
def test_a_function_list(self):
"""[Lab 3] - [Investigation 3] - [Part 1] - functions & lists - print first item in list"""
try:
import lab3e as lab3eStudent
except:
self.fail('your script contains errors')
expected_output = [100, 200, 300, 'six hundred']
error_output = ''
self.assertEqual(expected_output, lab3eStudent.give_list(), msg=error_output)
def test_a1(self):
"""[Lab 3] - [Investigation 3] - [Part 1] - Functions - Test for correct shebang line: ./lab3X.py"""
lab_file = open('./lab3e.py')
first_line = lab_file.readline()
lab_file.close()
error_output = 'your program does not have a shebang line(HINT: what should the first line contain)'
self.assertEqual(first_line.strip(), '#!/usr/bin/env python3', msg=error_output)
def test_b_function_first(self):
"""[Lab 3] - [Investigation 3] - [Part 1] - functions & lists - print first item in list"""
try:
import lab3e as lab3eStudent
except:
self.fail('your script contains errors')
expected_output = '100'
error_output = 'your function must return a string value(HINT: use the str() function)'
self.assertEqual(expected_output, lab3eStudent.give_first_item(), msg=error_output)
def test_c_function_first_and_last(self):
"""[Lab 3] - [Investigation 3] - [Part 1] - functions & lists - print last item in list"""
try:
import lab3e as lab3eStudent
except:
self.fail('your script contains errors')
expected_output = [100, 'six hundred']
error_output = ''
self.assertEqual(expected_output, lab3eStudent.give_first_and_last_item(), msg=error_output)
def test_d_function_second_and_third(self):
"""[Lab 3] - [Investigation 3] - [Part 1] - functions & lists - print last item in list"""
try:
import lab3e as lab3eStudent
except:
self.fail('your script contains errors')
expected_output = [200, 300]
error_output = ''
self.assertEqual(expected_output, lab3eStudent.give_second_and_third_item(), msg=error_output)
class lab3f(unittest.TestCase):
"""All test cases for lab3f - for loops & arguments & if statements"""
def test_0(self):
"""[Lab 3] - [Investigation 3] - [Part 3] - functions & lists & for loops - Test for file creation: ./lab3f.py"""
error_output = 'your file cannot be found(HINT: make sure you AND your file are in the correct directory)'
self.assertTrue(os.path.exists('./lab3f.py'), msg=error_output)
def test_a(self):
"""[Lab 3] - [Investigation 3] - [Part 3] - functions & lists & for loops - Test for errors running: ./lab3f.py"""
# Run students program
p = subprocess.Popen([sys.executable, './lab3f.py'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, err = p.communicate()
# Fail test if process returns a no zero exit status
return_code = p.wait()
error_output = 'your program exited with a error(HINT: make sure you copied the script exactly!)'
self.assertEqual(return_code, 0, msg=error_output)
def test_a1(self):
"""[Lab 3] - [Investigation 3] - [Part 3] - functions & lists & for loops - Test for correct shebang line: ./lab3f.py"""
lab_file = open('./lab3f.py')
first_line = lab_file.readline()
lab_file.close()
error_output = 'your program does not have a shebang line(HINT: what should the first line contain)'
self.assertEqual(first_line.strip(), '#!/usr/bin/env python3', msg=error_output)
def test_b_function_add_item_to_list(self):
"""[Lab 3] - [Investigation 3] - [Part 3] - functions & lists & for loops - check for correct items in list"""
try:
import lab3f as lab3fStudent
except:
self.fail('your script contains errors')
tmp = lab3fStudent.add_item_to_list(lab3fStudent.my_list)
expected_output = [ 1, 2, 3, 4, 5, 6 ]
error_output = ''
self.assertEqual(expected_output, lab3fStudent.my_list, msg=error_output)
def test_c_function_add_item_to_list(self):
"""[Lab 3] - [Investigation 3] - [Part 3] - functions & lists & for loops - check for correct items in list"""
try:
import lab3f as lab3fStudent
except:
self.fail('your script contains errors')
tmp = lab3fStudent.add_item_to_list(lab3fStudent.my_list)
tmp = lab3fStudent.add_item_to_list(lab3fStudent.my_list)
expected_output = [ 1, 2, 3, 4, 5, 6, 7, 8 ]
error_output = ''
self.assertEqual(expected_output, lab3fStudent.my_list, msg=error_output)
def test_d_function_remove_items_from_list(self):
"""[Lab 3] - [Investigation 3] - [Part 3] - functions & lists & for loops - check for correct items in list"""
try:
import lab3f as lab3fStudent
except:
self.fail('your script contains errors')
tmp = lab3fStudent.remove_items_from_list(lab3fStudent.my_list, [1,5,6])
expected_output = [ 2, 3, 4, 7, 8 ]
error_output = ''
self.assertEqual(expected_output, lab3fStudent.my_list, msg=error_output)
def test_e_function_remove_items_from_list(self):
"""[Lab 3] - [Investigation 3] - [Part 3] - functions & lists & for loops - check for correct items in list"""
try:
import lab3f as lab3fStudent
except:
self.fail('your script contains errors')
tmp = lab3fStudent.remove_items_from_list(lab3fStudent.my_list, [8, 7])
expected_output = [ 2, 3, 4 ]
error_output = ''
self.assertEqual(expected_output, lab3fStudent.my_list, msg=error_output)
def ChecksumLatest(url=None):
dat = ''
with urllib.request.urlopen(url) as response:
for line in response:
line = line.decode('utf-8')
dat = dat + line
checksum = hashlib.sha256(dat.encode('utf-8')).digest()
#print("internet", checksum)
return checksum
def ChecksumLocal(filename=None):
fil = open(filename, 'r', encoding='utf-8')
dat = fil.readlines()
textdata = ''
for line in dat:
textdata = textdata + line
checksum = hashlib.sha256(textdata.encode('utf-8')).digest()
#print("local", checksum)
return checksum
def CheckForUpdates():
try:
lab_name = 'CheckLab3.py'
lab_num = 'lab3'
print('Checking for updates...')
if ChecksumLatest(url='https://ict.senecacollege.ca/~eric.brauer/ops445/labs/LabCheckScripts/' + lab_name) != ChecksumLocal(filename='./' + lab_name):
print()
print(' There is a update available for ' + lab_name + ' please consider updating:')
print(' cd ~/ops445/' + lab_num + '/')
print(' pwd # <-- i.e. confirm that you are in the correct directory')
print(' rm ' + lab_name)
print(' ls ' + lab_name + ' || wget https://ict.senecacollege.ca/~eric.brauer/ops445/labs/LabCheckScripts/' + lab_name)
print()
return
print('Running latest version...')
return
except:
# Cleanly skip updating if any errors occur for offline or matrix issues
print('No connection made...')
print('Skipping updates...')
return
def displayReportHeader():
report_heading = 'OPS445 Lab Report - System Information for running '+sys.argv[0]
print(report_heading)
print(len(report_heading) * '=')
import getpass
print(' User login name:', getpass.getuser())
print(' Linux system name:', socket.gethostname())
print(' Python executable:',sys.executable)
print(' Python version: ',sys.version_info.major,sys.version_info.minor,sys.version_info.micro,sep='')
print(' OS Platform:',sys.platform)
print(' Working Directory:',os.getcwd())
print(' Start at:',time.asctime())
print(len(report_heading) * '=')
return
if __name__ == '__main__':
# CheckForUpdates()
# wait = input('Press ENTER to run the Lab Check...')
if len(sys.argv) == 3:
displayReportHeader()
unittest.main()