- Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathtest.py
32 lines (26 loc) · 1.21 KB
/
test.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
importio, sys, pytest, os, random, re
@pytest.mark.it("Import the random package")
deftest_import_random():
path=os.path.dirname(os.path.abspath(__file__))+'/app.py'
withopen(path, 'r') ascontent_file:
content=content_file.read()
regex=re.compile(r"import(\s)+random")
assertbool(regex.search(content)) ==True
@pytest.mark.it("Use a for loop to loop 10 times")
deftest_for_loop():
path=os.path.dirname(os.path.abspath(__file__))+'/app.py'
withopen(path, 'r') ascontent_file:
content=content_file.read()
regex=re.compile(r"for(\s)+(\w)+(\s){1,3}in(\s){1,3}range")
assertbool(regex.search(content)) ==True
@pytest.mark.it("Use the randint function to add a random number to the list each time you loop")
deftest_for_randint():
path=os.path.dirname(os.path.abspath(__file__))+'/app.py'
withopen(path, 'r') ascontent_file:
content=content_file.read()
regex=re.compile(r"random\.randint\s*\(\s*\d+\s*,\s*\d+\s*\)")
assertbool(regex.search(content)) ==True
@pytest.mark.it("The list my_list should have 15 items in the end")
deftest_for_size():
fromappimportmy_list
assertlen(my_list) ==15