@@ -50,102 +50,135 @@ def tearDown(self): |
50 | 50 |
|
51 | 51 | def test_verify_buffer(self): |
52 | 52 | # Expectation: A Frame buffer shall have exactly the specified size on construction. |
53 | | - self.assertEqual(Frame(0).get_buffer_size(), 0) |
54 | | - self.assertEqual(Frame(1024).get_buffer_size(), 1024) |
55 | | - self.assertEqual(Frame(1024 * 1024).get_buffer_size(), 1024 * 1024) |
| 53 | + # Allocation is performed by VimbaPython |
| 54 | + self.assertEqual(Frame(0, AllocationMode.AnnounceFrame).get_buffer_size(), 0) |
| 55 | + self.assertEqual(Frame(1024, AllocationMode.AnnounceFrame).get_buffer_size(), 1024) |
| 56 | + self.assertEqual(Frame(1024 * 1024, AllocationMode.AnnounceFrame).get_buffer_size(), |
| 57 | + 1024 * 1024) |
56 | 58 |
|
57 | | - def test_verify_no_copy_buffer_access(self): |
| 59 | + def test_verify_no_copy_empty_buffer_access(self): |
58 | 60 | # Expectation: Accessing the internal buffer must not create a copy |
59 | | - frame = Frame(10) |
| 61 | + # frame._buffer is only set on construction if buffer is allocated by VimbaPython |
| 62 | + frame = Frame(10, AllocationMode.AnnounceFrame) |
60 | 63 | self.assertEqual(id(frame._buffer), id(frame.get_buffer())) |
61 | 64 |
|
| 65 | + def test_verify_no_copy_filled_buffer_access(self): |
| 66 | + # Expectation: Accessing the internal buffer must not create a copy |
| 67 | + for allocation_mode in AllocationMode: |
| 68 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 69 | + with self.cam: |
| 70 | + frame = self.cam.get_frame(allocation_mode=allocation_mode) |
| 71 | + self.assertEqual(id(frame._buffer), id(frame.get_buffer())) |
| 72 | + |
62 | 73 | def test_get_id(self): |
63 | 74 | # Expectation: get_id() must return None if Its locally constructed |
64 | 75 | # else it must return the frame id. |
65 | | - self.assertIsNone(Frame(0).get_id()) |
| 76 | + for allocation_mode in AllocationMode: |
| 77 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 78 | + self.assertIsNone(Frame(0, allocation_mode).get_id()) |
66 | 79 |
|
67 | | - with self.cam: |
68 | | - self.assertIsNotNone(self.cam.get_frame().get_id()) |
| 80 | + with self.cam: |
| 81 | + self.assertIsNotNone( |
| 82 | + self.cam.get_frame(allocation_mode=allocation_mode).get_id()) |
69 | 83 |
|
70 | 84 | def test_get_timestamp(self): |
71 | 85 | # Expectation: get_timestamp() must return None if Its locally constructed |
72 | 86 | # else it must return the timestamp. |
73 | | - self.assertIsNone(Frame(0).get_timestamp()) |
| 87 | + for allocation_mode in AllocationMode: |
| 88 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 89 | + self.assertIsNone(Frame(0, allocation_mode).get_timestamp()) |
74 | 90 |
|
75 | | - with self.cam: |
76 | | - self.assertIsNotNone(self.cam.get_frame().get_timestamp()) |
| 91 | + with self.cam: |
| 92 | + self.assertIsNotNone( |
| 93 | + self.cam.get_frame(allocation_mode=allocation_mode).get_timestamp()) |
77 | 94 |
|
78 | 95 | def test_get_offset(self): |
79 | 96 | # Expectation: get_offset_x() must return None if Its locally constructed |
80 | 97 | # else it must return the offset as int. Same goes for get_offset_y() |
| 98 | + for allocation_mode in AllocationMode: |
| 99 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 100 | + self.assertIsNone(Frame(0, allocation_mode).get_offset_x()) |
| 101 | + self.assertIsNone(Frame(0, allocation_mode).get_offset_y()) |
81 | 102 |
|
82 | | - self.assertIsNone(Frame(0).get_offset_x()) |
83 | | - self.assertIsNone(Frame(0).get_offset_y()) |
| 103 | + with self.cam: |
| 104 | + frame = self.cam.get_frame(allocation_mode=allocation_mode) |
| 105 | + self.assertIsNotNone(frame.get_offset_x()) |
| 106 | + self.assertIsNotNone(frame.get_offset_y()) |
84 | 107 |
|
85 | 108 | def test_get_dimension(self): |
86 | 109 | # Expectation: get_width() must return None if Its locally constructed |
87 | 110 | # else it must return the offset as int. Same goes for get_height() |
| 111 | + for allocation_mode in AllocationMode: |
| 112 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 113 | + self.assertIsNone(Frame(0, allocation_mode).get_width()) |
| 114 | + self.assertIsNone(Frame(0, allocation_mode).get_height()) |
88 | 115 |
|
89 | | - self.assertIsNone(Frame(0).get_width()) |
90 | | - self.assertIsNone(Frame(0).get_height()) |
91 | | - |
92 | | - with self.cam: |
93 | | - frame = self.cam.get_frame() |
94 | | - self.assertIsNotNone(frame.get_width()) |
95 | | - self.assertIsNotNone(frame.get_height()) |
| 116 | + with self.cam: |
| 117 | + frame = self.cam.get_frame(allocation_mode=allocation_mode) |
| 118 | + self.assertIsNotNone(frame.get_width()) |
| 119 | + self.assertIsNotNone(frame.get_height()) |
96 | 120 |
|
97 | 121 | def test_get_image_size(self): |
98 | 122 | # Expectation: get_image_size() must return 0 if locally constructed |
99 | 123 | # else it must return the image_size as int. |
| 124 | + for allocation_mode in AllocationMode: |
| 125 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 126 | + self.assertEquals(Frame(0, allocation_mode).get_image_size(), 0) |
100 | 127 |
|
101 | | - self.assertEquals(Frame(0).get_image_size(), 0) |
102 | | - |
103 | | - with self.cam: |
104 | | - self.assertNotEquals(self.cam.get_frame().get_image_size(), 0) |
| 128 | + with self.cam: |
| 129 | + self.assertNotEquals( |
| 130 | + self.cam.get_frame(allocation_mode=allocation_mode).get_image_size(), 0) |
105 | 131 |
|
106 | 132 | def test_deepcopy(self): |
107 | 133 | # Expectation: a deepcopy must clone the frame buffer with its contents an |
108 | 134 | # update the internally store pointer in VmbFrame struct. |
| 135 | + for allocation_mode in AllocationMode: |
| 136 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 137 | + with self.cam: |
| 138 | + frame = self.cam.get_frame(allocation_mode=allocation_mode) |
109 | 139 |
|
110 | | - with self.cam: |
111 | | - frame = self.cam.get_frame() |
112 | | - |
113 | | - frame_cpy = copy.deepcopy(frame) |
| 140 | + frame_cpy = copy.deepcopy(frame) |
114 | 141 |
|
115 | | - # Ensure frames and their members are not the same object |
116 | | - self.assertNotEquals(id(frame), id(frame_cpy)) |
117 | | - self.assertNotEquals(id(frame._buffer), id(frame_cpy._buffer)) |
118 | | - self.assertNotEquals(id(frame._frame), id(frame_cpy._frame)) |
| 142 | + # Ensure frames and their members are not the same object |
| 143 | + self.assertNotEquals(id(frame), id(frame_cpy)) |
| 144 | + self.assertNotEquals(id(frame._buffer), id(frame_cpy._buffer)) |
| 145 | + self.assertNotEquals(id(frame._frame), id(frame_cpy._frame)) |
119 | 146 |
|
120 | | - # Ensure that both buffers have the same size and contain the same data. |
121 | | - self.assertEquals(frame.get_buffer_size(), frame_cpy.get_buffer_size()) |
122 | | - self.assertEquals(frame.get_buffer().raw, frame_cpy.get_buffer().raw) |
| 147 | + # Ensure that both buffers have the same size and contain the same data. |
| 148 | + self.assertEquals(frame.get_buffer_size(), frame_cpy.get_buffer_size()) |
| 149 | + self.assertTrue(all(a == b for a, b in zip(frame.get_buffer(), |
| 150 | + frame_cpy.get_buffer()))) |
123 | 151 |
|
124 | | - # Ensure that internal Frame Pointer points to correct buffer. |
125 | | - self.assertEquals(frame._frame.buffer, |
126 | | - ctypes.cast(frame._buffer, ctypes.c_void_p).value) |
| 152 | + # Ensure that internal Frame Pointer points to correct buffer. |
| 153 | + self.assertEquals(frame._frame.buffer, |
| 154 | + ctypes.cast(frame._buffer, ctypes.c_void_p).value) |
127 | 155 |
|
128 | | - self.assertEquals(frame_cpy._frame.buffer, |
129 | | - ctypes.cast(frame_cpy._buffer, ctypes.c_void_p).value) |
| 156 | + self.assertEquals(frame_cpy._frame.buffer, |
| 157 | + ctypes.cast(frame_cpy._buffer, ctypes.c_void_p).value) |
130 | 158 |
|
131 | | - self.assertEquals(frame._frame.bufferSize, frame_cpy._frame.bufferSize) |
| 159 | + self.assertEquals(frame._frame.bufferSize, frame_cpy._frame.bufferSize) |
132 | 160 |
|
133 | 161 | def test_get_pixel_format(self): |
134 | 162 | # Expectation: Frames have an image format set after acquisition |
135 | | - with self.cam: |
136 | | - self.assertNotEquals(self.cam.get_frame().get_pixel_format(), 0) |
| 163 | + for allocation_mode in AllocationMode: |
| 164 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 165 | + with self.cam: |
| 166 | + self.assertNotEquals( |
| 167 | + self.cam.get_frame(allocation_mode=allocation_mode).get_pixel_format(), 0) |
137 | 168 |
|
138 | 169 | def test_incompatible_formats_value_error(self): |
139 | 170 | # Expectation: Conversion into incompatible formats must lead to an value error |
140 | | - with self.cam: |
141 | | - frame = self.cam.get_frame() |
| 171 | + for allocation_mode in AllocationMode: |
| 172 | + with self.subTest(f'allocation_mode={str(allocation_mode)}'): |
| 173 | + with self.cam: |
| 174 | + frame = self.cam.get_frame(allocation_mode=allocation_mode) |
142 | 175 |
|
143 | | - current_fmt = frame.get_pixel_format() |
144 | | - convertable_fmt = current_fmt.get_convertible_formats() |
| 176 | + current_fmt = frame.get_pixel_format() |
| 177 | + convertable_fmt = current_fmt.get_convertible_formats() |
145 | 178 |
|
146 | | - for fmt in PixelFormat.__members__.values(): |
147 | | - if (fmt != current_fmt) and (fmt not in convertable_fmt): |
148 | | - self.assertRaises(ValueError, frame.convert_pixel_format, fmt) |
| 179 | + for fmt in PixelFormat.__members__.values(): |
| 180 | + if (fmt != current_fmt) and (fmt not in convertable_fmt): |
| 181 | + self.assertRaises(ValueError, frame.convert_pixel_format, fmt) |
149 | 182 |
|
150 | 183 | def test_convert_to_all_given_formats(self): |
151 | 184 | # Expectation: A Series of Frame, each acquired with a different Pixel format |
|