[go: up one dir, main page]

Menu

[r998]: / Segtool / test_section.py  Maximize  Restore  History

Download this file

92 lines (69 with data), 3.0 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
modules = {'Section' : [0, '', 'none://Section.py' ]
}
import wx
from Section import Section
from Section import ImageSegmentation
from Section import GlobalColors
from lxml import etree
import unittest
class TestSectionIO(unittest.TestCase):
def setUp(self):
self.points = [(0,0), (1,2), (4,12)]
self.points_upscaled = [(0,0), (2,4), (8,24)]
color = "red"
self.section = Section(color=color,points=self.points)
def testEqualSelf(self):
self.assertEqual(self.section, self.section)
def testModel(self):
root = etree.Element("frame")
self.section.Save(root)
self.assertEqual(len(root), 1,
msg=etree.tostring(root, pretty_print=True))
for s in root:
load_section = Section(node=s)
self.assertEqual(load_section, self.section, msg=etree.tostring(s, pretty_print=True) )
def testGetPoints(self):
points = self.section.GetPoints( 2.0 )
self.assertEqual(points, self.points_upscaled)
def testSetPoints(self):
self.section.SetPoints( self.points_upscaled, 2.0 )
self.assertEqual(self.section.points, self.points)
def testGetMask(self):
app = wx.App()
points = [(1.0, 1.0), (3.0,1.0), (3.0, 2.5), (1.0,2.0)]
section = Section(color="black",points=points)
mask_points = [(1.0, 1.0), (2.0,1.0), (3.0, 1.0),
(1.0, 2.0), (2.0,2.0), (3.0, 2.0)]
mask = section.GetMask(wx.Size(4,4), 1.0)
self.assertEqual(len(mask), len(mask_points))
for p in mask_points:
assert(p in mask)
def testGetMaskZoomed(self):
app = wx.App()
points = [(1.0, 1.0), (3.0,1.0), (3.0, 1.5)]
section = Section(color="black",points=points)
mask_points = [(2.0, 2.0), (3.0, 2.0), (4.0, 2.0), (5.0, 2.0), (6.0, 2.0),
(4.0, 3.0), (5.0, 3.0),(6.0, 3.0)]
mask = section.GetMask(wx.Size(8,8), 2.0)
self.assertEqual(len(mask), len(mask_points))
for p in mask_points:
assert(p in mask)
def testGetMask2(self):
app = wx.App()
points = [(1.0, 1.0), (4.0,1.0), (4.0, 4.0), (1.0, 4.0)]
section = Section(color="black",points=points)
mask_points = [(1.0, 1.0), (1.0, 2.0), (1.0, 3.0), (1.0, 4.0),
(2.0, 1.0), (2.0, 2.0), (2.0, 3.0), (2.0, 4.0),
(3.0, 1.0), (3.0, 2.0), (3.0, 3.0), (3.0, 4.0),
(4.0, 1.0), (4.0, 2.0), (4.0, 3.0), (4.0, 4.0)]
mask = section.GetMask(wx.Size(6,6), 1.0)
print mask
self.assertEqual(len(mask), len(mask_points))
for p in mask_points:
assert(p in mask)
def suite():
suite = unittest.makeSuite(TestSectionIO, 'test')
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')