11import unittest
22from mapmanagercore .annotations .mutation import AnnotationsBaseMut
3- from mapmanagercore .loader .base import Loader
3+ from mapmanagercore .lazy_geo_pd_images .loader .base import ImageLoader
4+ from mapmanagercore .schemas .segment import Segment
5+ from mapmanagercore .schemas .spine import Spine
6+
47
58class TestAnnotationsBaseMut (unittest .TestCase ):
69
710 def new (self ):
8- return AnnotationsBaseMut (Loader ())
11+ return AnnotationsBaseMut (ImageLoader ())
912
1013 def test_undo_redo_simple_spine (self ):
1114 annotations = self .new ()
12- annotations .updateSpine (("spine_id" , 0 ), { "z" : 0 } )
13- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 0 )
15+ annotations .updateSpine (("spine_id" , 0 ), Spine ( z = 0 ) )
16+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 0 )
1417
1518 # Undo the update
1619 annotations .undo ()
1720 self .assertNotIn (("spine_id" , 0 ), annotations ._points .index )
1821
1922 # Redo the update
2023 annotations .redo ()
21- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 0 )
24+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 0 )
2225
2326 # Redo again (should have no effect)
2427 annotations .redo ()
25- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 0 )
28+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 0 )
2629
27- annotations .updateSpine (("spine_id" , 0 ), { "z" : 1 } )
28- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 1 )
30+ annotations .updateSpine (("spine_id" , 0 ), Spine ( z = 1 ) )
31+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 1 )
2932 annotations .undo ()
30- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 0 )
33+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 0 )
3134 annotations .redo ()
32- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 1 )
35+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 1 )
3336 annotations .undo ()
34- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 0 )
37+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 0 )
3538
3639 # Undo twice (should have no effect)
3740 annotations .undo ()
@@ -42,48 +45,48 @@ def test_undo_redo_simple_spine(self):
4245 def test_undo_redo_replace (self ):
4346 annotations = self .new ()
4447 # Test replaceLog
45- annotations .updateSpine (("spine_id" , 0 ), { "z" : 2 } )
48+ annotations .updateSpine (("spine_id" , 0 ), Spine ( z = 2 ) )
4649 self .assertEqual (len (annotations ._log .operations ), 1 )
47- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 2 )
50+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 2 )
4851
49- annotations .updateSpine (("spine_id" , 0 ), { "z" : 3 } )
52+ annotations .updateSpine (("spine_id" , 0 ), Spine ( z = 3 ) )
5053 self .assertEqual (len (annotations ._log .operations ), 2 )
51- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 3 )
54+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 3 )
5255
53- annotations .updateSpine (("spine_id" , 0 ), { "z" : 4 } , replaceLog = True )
56+ annotations .updateSpine (("spine_id" , 0 ), Spine ( z = 4 ) , replaceLog = True )
5457 self .assertEqual (len (annotations ._log .operations ), 2 )
55- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 4 )
58+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 4 )
5659
5760 annotations .undo ()
58- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 2 )
61+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 2 )
5962
6063 annotations .undo ()
6164 self .assertNotIn (("spine_id" , 0 ), annotations ._points .index )
6265
6366 annotations .redo ()
64- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 2 )
67+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 2 )
6568
6669 annotations .redo ()
67- self .assertEqual (annotations ._points . loc [("spine_id" , 0 ), "z" ], 4 )
70+ self .assertEqual (annotations .points [("spine_id" , 0 ), "z" ], 4 )
6871
6972 def test_undo_redo_simple_segment (self ):
7073 annotations = self .new ()
71- annotations .updateSegment (("segment_id" , 0 ), { " radius" : 1 } )
74+ annotations .updateSegment (("segment_id" , 0 ), Segment ( radius = 1 ) )
7275 self .assertEqual (
73- annotations ._lineSegments . loc [("segment_id" , 0 ), "radius" ], 1 )
76+ annotations .segments [("segment_id" , 0 ), "radius" ], 1 )
7477
7578 # Undo the update
7679 annotations .undo ()
77- self .assertNotIn (("segment_id" , 0 ), annotations ._lineSegments .index )
80+ self .assertNotIn (("segment_id" , 0 ), annotations .segments .index )
7881
7982 # Redo the update
8083 annotations .redo ()
8184 self .assertEqual (
82- annotations ._lineSegments . loc [("segment_id" , 0 ), "radius" ], 1 )
85+ annotations .segments [("segment_id" , 0 ), "radius" ], 1 )
8386
8487 def test_delete_spine (self ):
8588 annotations = self .new ()
86- annotations .updateSpine (("spine_id" , 0 ), { "z" : 0 } )
89+ annotations .updateSpine (("spine_id" , 0 ), Spine ( z = 0 ) )
8790 self .assertIn (("spine_id" , 0 ), annotations ._points .index )
8891
8992 # Delete the spine
@@ -100,57 +103,58 @@ def test_delete_spine(self):
100103
101104 def test_delete_segment (self ):
102105 annotations = self .new ()
103- annotations .updateSegment (("segment_id" , 0 ), { " radius" : 1 } )
104- self .assertIn (("segment_id" , 0 ), annotations ._lineSegments .index )
106+ annotations .updateSegment (("segment_id" , 0 ), Segment ( radius = 1 ) )
107+ self .assertIn (("segment_id" , 0 ), annotations .segments .index )
105108
106109 # Delete the segment
107110 annotations .deleteSegment (("segment_id" , 0 ))
108- self .assertNotIn (("segment_id" , 0 ), annotations ._lineSegments .index )
111+ self .assertNotIn (("segment_id" , 0 ), annotations .segments .index )
109112
110113 # Undo the deletion
111114 annotations .undo ()
112- self .assertIn (("segment_id" , 0 ), annotations ._lineSegments .index )
115+ self .assertIn (("segment_id" , 0 ), annotations .segments .index )
113116
114117 # Redo the deletion
115118 annotations .redo ()
116- self .assertNotIn (("segment_id" , 0 ), annotations ._lineSegments .index )
117-
119+ self .assertNotIn (("segment_id" , 0 ), annotations .segments .index )
120+
118121 def test_multi_segment (self ):
119122 annotations = self .new ()
120- annotations .updateSegment (("segment_id" , 0 ), {"radius" : 1 })
121- annotations .updateSegment (("segment_id2" , 0 ), {"radius" : 2 })
122- self .assertIn (("segment_id" , 0 ), annotations ._lineSegments .index )
123- self .assertIn (("segment_id2" , 0 ), annotations ._lineSegments .index )
124-
125- self .assertEqual (annotations ._lineSegments .loc [("segment_id" , 0 ), "radius" ], 1 )
126- self .assertEqual (annotations ._lineSegments .loc [("segment_id2" , 0 ), "radius" ], 2 )
127-
128- annotations .updateSegment ([("segment_id" , 0 ), ("segment_id2" , 0 )], {"radius" : 3 })
129- self .assertEqual (annotations ._lineSegments .loc [("segment_id" , 0 ), "radius" ], 3 )
130- self .assertEqual (annotations ._lineSegments .loc [("segment_id2" , 0 ), "radius" ], 3 )
131-
123+ annotations .updateSegment (("segment_id" , 0 ), Segment (radius = 1 ))
124+ annotations .updateSegment (("segment_id2" , 0 ), Segment (radius = 2 ))
125+ self .assertIn (("segment_id" , 0 ), annotations .segments .index )
126+ self .assertIn (("segment_id2" , 0 ), annotations .segments .index )
127+
128+ self .assertEqual (annotations .segments [("segment_id" , 0 ), "radius" ], 1 )
129+ self .assertEqual (annotations .segments [("segment_id2" , 0 ), "radius" ], 2 )
130+
131+ annotations .updateSegment (
132+ [("segment_id" , 0 ), ("segment_id2" , 0 )], Segment (radius = 3 ))
133+ self .assertEqual (annotations .segments [("segment_id" , 0 ), "radius" ], 3 )
134+ self .assertEqual (annotations .segments [("segment_id2" , 0 ), "radius" ], 3 )
135+
132136 annotations .undo ()
133- self .assertEqual (annotations ._lineSegments . loc [("segment_id" , 0 ), "radius" ], 1 )
134- self .assertEqual (annotations ._lineSegments . loc [("segment_id2" , 0 ), "radius" ], 2 )
135-
137+ self .assertEqual (annotations .segments [("segment_id" , 0 ), "radius" ], 1 )
138+ self .assertEqual (annotations .segments [("segment_id2" , 0 ), "radius" ], 2 )
139+
136140 annotations .redo ()
137- self .assertEqual (annotations ._lineSegments . loc [("segment_id" , 0 ), "radius" ], 3 )
138- self .assertEqual (annotations ._lineSegments . loc [("segment_id2" , 0 ), "radius" ], 3 )
139-
141+ self .assertEqual (annotations .segments [("segment_id" , 0 ), "radius" ], 3 )
142+ self .assertEqual (annotations .segments [("segment_id2" , 0 ), "radius" ], 3 )
143+
140144 # Delete the segment
141145 annotations .deleteSegment ([("segment_id" , 0 ), ("segment_id2" , 0 )])
142- self .assertNotIn (("segment_id" , 0 ), annotations ._lineSegments .index )
143- self .assertNotIn (("segment_id2" , 0 ), annotations ._lineSegments .index )
146+ self .assertNotIn (("segment_id" , 0 ), annotations .segments .index )
147+ self .assertNotIn (("segment_id2" , 0 ), annotations .segments .index )
144148
145149 # Undo the deletion
146150 annotations .undo ()
147- self .assertIn (("segment_id" , 0 ), annotations ._lineSegments .index )
148- self .assertIn (("segment_id2" , 0 ), annotations ._lineSegments .index )
151+ self .assertIn (("segment_id" , 0 ), annotations .segments .index )
152+ self .assertIn (("segment_id2" , 0 ), annotations .segments .index )
149153
150154 # Redo the deletion
151155 annotations .redo ()
152- self .assertNotIn (("segment_id" , 0 ), annotations ._lineSegments .index )
153- self .assertNotIn (("segment_id2" , 0 ), annotations ._lineSegments .index )
156+ self .assertNotIn (("segment_id" , 0 ), annotations .segments .index )
157+ self .assertNotIn (("segment_id2" , 0 ), annotations .segments .index )
154158
155159
156160if __name__ == '__main__' :
0 commit comments