-
Notifications
You must be signed in to change notification settings - Fork 3
/
project_test.py
executable file
·107 lines (93 loc) · 3.9 KB
/
project_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python
"""Unit test for project.py"""
import project
import unittest
import wx
class image_path(unittest.TestCase):
"""Test image path validator and image path settings"""
# By default there are four directions, two seasons, 1 frame and 2 layers
# Test setting/getting all of these to ensure that this method always sets/returns the correct one
directions = [0,1,2,3]
seasons = [0,1]
frames = [0]
layers = [0,1]
knownvalues = (
(None,""),
("string",True),
(True,False),
(1,False),
(-1,False),
({},False),
([],False),
)
def test_knownvalues_validate(self):
"""Test that known values are validated correctly"""
for testvalue, expected in self.knownvalues:
p = project.Project()
for d in self.directions:
for s in self.seasons:
for f in self.frames:
for l in self.layers:
result = p.image_path(d,s,f,l, testvalue, validate=True)
self.assertEqual(expected, result)
def test_knownvalues_set(self):
"""Test that known values are set correctly"""
for testvalue, expected in self.knownvalues:
p = project.Project()
for d in self.directions:
for s in self.seasons:
for f in self.frames:
for l in self.layers:
result = p.image_path(d,s,f,l, testvalue)
self.assertEqual(expected, result)
def test_setvalues(self):
"""Test setting/getting values works"""
# Try setting a unique value for each view, then reading it back after all have been set
p = project.Project()
for d in self.directions:
for s in self.seasons:
for f in self.frames:
for l in self.layers:
testvalue = str(d) + str(s) + str(f) + str(l)
result = p.image_path(d,s,f,l,testvalue)
self.assertEqual(result, True)
for d in self.directions:
for s in self.seasons:
for f in self.frames:
for l in self.layers:
expected = str(d) + str(s) + str(f) + str(l)
self.assertEqual(expected, p.image_path(d,s,f,l))
class dat_lump_knownvalues(unittest.TestCase):
"""Test dat_lump validator"""
knownvalues = (
(None,"Obj=building\nName=test_1\nType=cur\nPassengers=100\nintro_year=1900\nchance=100"),
("string",True),
(True,False),
(1,False),
(-1,False),
({},False),
([],False),
)
def test_knownvalues_validate(self):
"""Test that known values are validated correctly"""
for testvalue, expected in self.knownvalues:
p = project.Project()
result = p.dat_lump(testvalue, validate=True)
self.assertEqual(expected, result)
def test_knownvalues_set(self):
"""Test that known values are set correctly"""
for testvalue, expected in self.knownvalues:
p = project.Project()
result = p.dat_lump(testvalue)
self.assertEqual(expected, result)
def test_setvalues(self):
"""Test setting/getting values works"""
for testvalue, expected in self.knownvalues:
# Use fresh project instance each time
p = project.Project()
# If setting works then the value output should equal the value input
if p.dat_lump(testvalue) == True:
self.assertEqual(testvalue, p.dat_lump())
if __name__ == "__main__":
app = wx.App()
unittest.main()