-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_tests.py
83 lines (70 loc) · 3.71 KB
/
unit_tests.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
import unittest
from message import Message
from datastore import Datastore
class TestSingleMessages(unittest.TestCase):
"""
Ensure a single message passed to a given datastore gets the expected response.
"""
def test_valid_but_unusual_package_names(self):
legal_messages = ['REMOVE|png++|\n', 'REMOVE|pkg-config|\n', 'REMOVE|mysql-connector-c++|\n']
for message in legal_messages:
self.assertNotEqual(str(Message.Error), Datastore().process_message(message))
def test_invalid_messages(self):
legal_messages = ['INDEX|cloog|gmp,isl,pkg-config\n', 'INDEX|ceylon|\n', 'REMOVE|cloog|\n', 'QUERY|cloog|\n']
for message in legal_messages:
# assert original message is not broken
self.assertNotEqual(str(Message.Error), Datastore().process_message(message))
# assert mangled message is broken
self.assertEqual(str(Message.Error), Datastore().process_message(' ' + message))
self.assertEqual(str(Message.Error), Datastore().process_message(message + ' '))
self.assertEqual(str(Message.Error), Datastore().process_message(message[:-1]))
self.assertEqual(str(Message.Error), Datastore().process_message(message[:-1] + ',' + message[-1:]))
def test_index_already_exists(self):
message = 'INDEX|cloog|gmp,isl,pkg-config\n'
dependency_map = {'cloog':[], 'ceylon':['cloog']}
datastore = Datastore(dependency_map)
self.assertEqual(str(Message.OK), datastore.process_message(message))
def test_index_with_unindexed_dependency(self):
message = 'INDEX|cloog|gmp,isl,pkg-config\n'
dependency_map = {'gmp':[], 'isl':['cmake']}
datastore = Datastore(dependency_map)
self.assertEqual(str(Message.Fail), datastore.process_message(message))
def test_index_with_all_indexed_dependencies(self):
message = 'INDEX|cloog|gmp,isl,pkg-config\n'
dependency_map = {'gmp':[], 'isl':['cmake'], 'pkg-config':[]}
datastore = Datastore(dependency_map)
self.assertEqual(str(Message.OK), datastore.process_message(message))
def test_index_with_no_dependencies(self):
message = 'INDEX|ceylon|\n'
dependency_map = {}
datastore = Datastore(dependency_map)
self.assertEqual(str(Message.OK), datastore.process_message(message))
def test_remove_already_doesnt_exist(self):
message = 'REMOVE|cloog|\n'
dependency_map = {}
datastore = Datastore(dependency_map)
self.assertEqual(str(Message.OK), datastore.process_message(message))
def test_remove_has_dependents(self):
message = 'REMOVE|cloog|\n'
dependency_map = {'gmp':['cloog', 'cmake'], 'cloog':[]}
dependents_count = {'cloog':1, 'cmake':1}
datastore = Datastore(dependency_map, dependents_count)
self.assertEqual(str(Message.Fail), datastore.process_message(message))
def test_remove_exists(self):
message = 'REMOVE|cloog|\n'
dependency_map = {'gmp':['cmake'], 'cloog':[]}
dependents_count = {'cmake':1}
datastore = Datastore(dependency_map, dependents_count)
self.assertEqual(str(Message.OK), datastore.process_message(message))
def test_query_exists(self):
message = 'QUERY|cloog|\n'
dependency_map = {'gmp':['cmake'], 'cloog':[]}
datastore = Datastore(dependency_map)
self.assertEqual(str(Message.OK), datastore.process_message(message))
def test_query_doesnt_exist(self):
message = 'QUERY|cloog|\n'
dependency_map = {'gmp':['cmake']}
datastore = Datastore(dependency_map)
self.assertEqual(str(Message.Fail), datastore.process_message(message))
if __name__ == '__main__':
unittest.main()