-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_session2.py
116 lines (88 loc) · 3.14 KB
/
test_session2.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
# DO NOT CHANGE THIS TEST FILE
import subprocess
import sys
try:
import memory_profiler
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", 'memory-profiler'])
finally:
import memory_profiler
from memory_profiler import memory_usage
import pytest
import session2
import time
import os.path
import re
import inspect
README_CONTENT_CHECK_FOR = [
'Something',
'SomethingNew',
'add_something',
'clear_memory',
'critical_function',
'compare_strings_old',
'compare_strings_new',
'sleep',
'char_list',
'collection',
'__init__'
]
memory_used = []
def test_clear_memory():
memory_used = memory_usage((session2.critical_function))
assert (memory_used[len(memory_used) - 1] - memory_used[0]) < 4
def test_memory_actually_increased():
# This test will check whether we are actually increase the memory during running the function f
memory_used2 = memory_usage((session2.critical_function))
peak = max(memory_used2)
assert (peak - memory_used2[0]) > 8, "Seems like you have changed the program! Are you trying to cheat!"
def test_performance():
start1 = time.perf_counter()
session2.compare_strings_old(10000000)
end1 = time.perf_counter()
delta1 = end1 - start1
start2 = time.perf_counter()
session2.compare_strings_new(10000000)
end2 = time.perf_counter()
delta2 = end2 - start2
assert delta1 / delta2 >= 10.0
def test_readme_exists():
assert os.path.isfile("README.md"), "README.md file missing!"
def test_readme_contents():
readme = open("README.md", "r")
readme_words = readme.read().split()
readme.close()
assert len(readme_words) >= 500, "Make your README.md file interesting! Add atleast 500 words"
def test_readme_proper_description():
READMELOOKSGOOD = True
f = open("README.md", "r")
content = f.read()
f.close()
for c in README_CONTENT_CHECK_FOR:
if c not in content:
READMELOOKSGOOD = False
pass
assert READMELOOKSGOOD == True, "You have not described all the functions/class well in your README.md file"
def test_readme_file_for_formatting():
f = open("README.md", "r", encoding="utf-8")
content = f.read()
f.close()
assert content.count("#") >= 10
def test_class_repr():
s = session2.Something()
s_n = session2.SomethingNew()
assert 'object at' not in s.__repr__() and 'object at' not in s_n.__repr__()
def test_indentations():
''' Returns pass if used four spaces for each level of syntactically \
significant indenting.'''
lines = inspect.getsource(session2)
spaces = re.findall('\n +.', lines)
for space in spaces:
assert len(space) % 4 == 2, "Your script contains misplaced indentations"
assert len(re.sub(r'[^ ]', '', space)) % 4 == 0, "Your code indentation does not follow PEP8 guidelines"
def test_function_name_had_cap_letter():
functions = inspect.getmembers(session2, inspect.isfunction)
for function in functions:
assert len(re.findall('([A-Z])', function[0])) == 0, "You have used Capital letter(s) in your function names"
if __name__ == '__main__':
test_clear_memory()