/
test.py
61 lines (45 loc) · 1.23 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
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
#unittest.py - Run unit tests on various aspects of the client.
import unittest
class TestPacketGeneration(unittest.TestCase):
import packet
id = {
}
def test_login_packet(self):
import packet
#comes with predefined values
id = packet.ID()
testcase = {
"__type":"LoginRequest:#Messages.RequestMessages",
"Identity":packet.id_packet(id),
"ProcessLabel":"test",
"ProcessType" :3
}
self.assertEqual(testcase,packet.login_request(id,plabel="test"))
class TestJsonDict(unittest.TestCase):
#test that json and python dicts are equivalent
def test_dict_json_equivalence(self):
import json
testdict = {
"a":1,
"b":2,
"c":3,
"sub": {"a":1}
}
for item in testdict:
self.assertEqual(testdict[item],json.loads(json.dumps(testdict))[item])
class TestSocketCreation(unittest.TestCase):
#create a local socket on an unused port
def test_local_socket(self):
import network
try:
a = network.connect("127.0.0.1:22")
self.assertFalse(a == None) #Socket Creation Failed - Connection Refused
except:
self.assertTrue(False) #Socket creation failed - Exception Raised
#close the socket - not part of the test
try:
a.close()
except:
pass
if __name__ == "__main__":
unittest.main()