1
+ import pytest
2
+
3
+ from profile import get_profile
4
+
5
+
6
+ def test_get_profile_no_name ():
7
+ with pytest .raises (TypeError ):
8
+ assert get_profile ()
9
+
10
+
11
+ def test_get_profile_no_age ():
12
+ with pytest .raises (TypeError ):
13
+ assert get_profile ('tim' )
14
+
15
+
16
+ def test_get_profile_valueerror ():
17
+ with pytest .raises (ValueError ):
18
+ assert get_profile ('tim' , 'nonint' )
19
+
20
+
21
+ def test_get_profile_too_many_sports ():
22
+ with pytest .raises (ValueError ):
23
+ sports = ['tennis' , 'basketball' , 'badminton' ,
24
+ 'baseball' , 'volleyball' , 'boxing' ]
25
+ assert get_profile ('tim' , 36 , * sports )
26
+
27
+
28
+ def test_get_profile_dict ():
29
+ assert get_profile ('tim' , 36 ) == {'name' : 'tim' , 'age' : 36 }
30
+
31
+
32
+ def test_get_profile_one_sport ():
33
+ expected = {'name' : 'tim' , 'age' : 36 ,
34
+ 'sports' : ['tennis' ]}
35
+ assert get_profile ('tim' , 36 , 'tennis' ) == expected
36
+
37
+
38
+ def test_get_profile_two_sports ():
39
+ expected = {'name' : 'tim' , 'age' : 36 ,
40
+ 'sports' : ['basketball' , 'tennis' ]}
41
+ assert get_profile ('tim' , 36 , 'tennis' , 'basketball' ) == expected
42
+
43
+
44
+ def test_get_profile_award ():
45
+ expected = {'name' : 'tim' , 'age' : 36 ,
46
+ 'awards' : {'champ' : 'helped out team in crisis' }}
47
+ assert get_profile ('tim' , 36 ,
48
+ champ = 'helped out team in crisis' ) == expected
49
+
50
+
51
+ def test_get_profile_two_sports_and_one_award ():
52
+ expected = {'name' : 'tim' , 'age' : 36 ,
53
+ 'sports' : ['basketball' , 'tennis' ],
54
+ 'awards' : {'champ' : 'helped out team in crisis' }}
55
+ assert get_profile ('tim' , 36 , 'tennis' , 'basketball' ,
56
+ champ = 'helped out team in crisis' ) == expected
57
+
58
+
59
+ def test_get_profile_two_sports_and_three_awards ():
60
+ expected = {'name' : 'tim' , 'age' : 36 ,
61
+ 'sports' : ['basketball' , 'tennis' ],
62
+ 'awards' : {'champ' : 'helped out the team in crisis' ,
63
+ 'service' : 'going the extra mile for our customers' ,
64
+ 'attitude' : 'unbeatable positive + uplifting' }}
65
+ assert get_profile ('tim' , 36 , 'tennis' , 'basketball' ,
66
+ service = 'going the extra mile for our customers' ,
67
+ champ = 'helped out the team in crisis' ,
68
+ attitude = 'unbeatable positive + uplifting' ) == expected
0 commit comments