-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTesting.py
More file actions
72 lines (59 loc) · 2.23 KB
/
Testing.py
File metadata and controls
72 lines (59 loc) · 2.23 KB
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
"""
UNIT TESTING:
- Case 1: Negative port number
- Case 2: Negative value for maximum song length
- Case 3: City name as int instead of string
- Case 4: Playlist URL links to different website
- Case 5: Negative number in random bounds
"""
# Import Unittest module
import unittest
# Import RadioHost class
from RadioHost import RadioHost
# Custom error for a negative port number
class NegativePortNumber(Exception):
pass
# Custom error for negative value in song length
class NegativeMaximumSongLength(Exception):
pass
# Custom error if playlist URL is not in correct domain
class PlaylistDomainError(Exception):
pass
# Custom error for negative value in random bounds
class NegativeRandomBounds(Exception):
pass
class TestRadio(unittest.TestCase):
def setUp(self):
self.maininstance = RadioHost()
def test_negative_port(self):
testinstance = lambda: self.maininstance.startradio("TestPort",False)
try:
self.assertRaises(NegativePortNumber, testinstance)
except AssertionError:
print("Success.")
def test_negative_song_length(self):
testinstance = lambda: self.maininstance.startradio("TestSongLength",False)
try:
self.assertRaises(NegativeMaximumSongLength, testinstance)
except AssertionError:
print("Success.")
def test_city_name_as_string(self):
testinstance = lambda: self.maininstance.startradio("TestCityName",False)
try:
self.assertRaises(TypeError, testinstance)
except AssertionError:
print("Success.")
def test_playlist_URL_in_domain(self):
testinstance = lambda: self.maininstance.startradio("TestPlaylistDomain",False)
try:
self.assertRaises(PlaylistDomainError, testinstance)
except AssertionError:
print("Success.")
def test_negative_random_bounds(self):
testinstance = lambda: self.maininstance.startradio("TestRandomBounds",False)
try:
self.assertRaises(NegativeRandomBounds, testinstance)
except AssertionError:
print("Success.")
if __name__ == '__main__':
unittest.main()