-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
29 lines (24 loc) · 1.18 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
import io, sys, pytest, os, re, datetime
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
@pytest.mark.it("Each element should to have the correct output")
def test_multp(capsys, app):
import app
people = [
{ "name": 'Joe', "birthDate": datetime.datetime(1986,10,24) },
{ "name": 'Bob', "birthDate": datetime.datetime(1975,5,24) },
{ "name": 'Erika', "birthDate": datetime.datetime(1989,6,12) },
{ "name": 'Dylan', "birthDate": datetime.datetime(1999,12,14) },
{ "name": 'Steve', "birthDate": datetime.datetime(2003,4,24) }
]
def calculateAge(birthDate):
today = datetime.date.today()
age = today.year - birthDate.year - ((today.month, today.day) < (birthDate.month, birthDate.day))
return age
name_list = list(map(lambda person: "Hello, my name is " + person["name"] + " and I am " + str(calculateAge(person["birthDate"])) + " years old" , people))
captured = capsys.readouterr()
assert str(name_list) in captured.out
@pytest.mark.it("Use the map function")
def test_map():
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
content = f.read()
assert content.find("map") > 0