-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_session8.py
101 lines (80 loc) · 2.76 KB
/
test_session8.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
import pytest , os , inspect
import re , random, session8
README_CONTENT_CHECK_FOR = ['check_fn_docs',
'next_fibo_number',
'mul',
'add',
'div',
'function_counter'
]
#1 README Exists
def test_readme_exists():
assert os.path.isfile("README.md"), "README.md file missing!"
#2 README Formatting
def test_readme_for_formatting():
readme = open('README.md','r')
content = readme.read()
readme.close()
assert content.count('#') >= 5 , "Kindly format the README.md"
#3 README Words Count
def test_readme_words_counts():
readme = open('README.md','r')
readme_words = readme.read().split()
readme.close()
assert len(readme_words) >= 100 , "Kindly define README properly"
#4 function name had caps letter
def test_funcation_had_cap_letter():
functions = inspect.getmembers(session8, 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"
#5 PEP8 Guidelines
def test_fourspace():
lines = inspect.getsource(session8)
spaces = re.findall('\n +.', lines)
for space in spaces:
assert re.search('[a-zA-Z#@\'\"]', space), "Your code intentation does not follow PEP8 guidelines"
assert len(re.sub(r'[a-zA-Z#@\n\"\']', '', space)) % 4 == 0,"Your code intentation does not follow PEP8 guidelines"
#6 check docstring exist
def test_docstring_length():
a = session8.check_fn_docs()
assert a(session8.mul) == True
#7 check next fibonacci number
def test_fibonacci():
k = session8.next_fibo_number()
k()
k()
k()
assert k() == 2
#8
def test_function_single_dict_call():
c = session8.function_counter( session8.add )
c()
c()
c()
c = session8.function_counter( session8.mul )
c()
c = session8.function_counter( session8.div )
c()
k = c()
assert k == {'add': 3, 'div': 2, 'mul': 1}
#9
def test_function_calling_sep_dict():
c = session8.function_two_dict(session8.add, session8.userA)
c()
c()
l = session8.function_two_dict(session8.mul,session8.userA)
l()
l()
x = session8.function_two_dict(session8.div,session8.userA)
x()
x()
c = session8.function_two_dict(session8.add,session8.userB)
c()
c()
c()
l = session8.function_two_dict(session8.mul,session8.userB)
l()
x = session8.function_two_dict(session8.div,session8.userB)
x()
x()
assert session8.userA == {'add': 2, 'div': 2, 'mul': 2} and session8.userB == {'add': 3, 'div': 2, 'mul': 1}