@@ -188,16 +188,21 @@ def test_yuv_analysis1(camera, mode):
188
188
if resolution == (2592 , 1944 ):
189
189
pytest .xfail ('Cannot encode video at max resolution' )
190
190
class YUVTest (picamera .array .PiYUVAnalysis ):
191
- def analyse (self , a ):
191
+ def __init__ (self , camera ):
192
+ super (YUVTest , self ).__init__ (camera )
193
+ self .write_called = False
194
+ def analyze (self , a ):
195
+ self .write_called = True
192
196
assert a .shape == (resolution [1 ], resolution [0 ], 3 )
193
197
with YUVTest (camera ) as stream :
194
198
camera .start_recording (stream , 'yuv' )
195
199
camera .wait_recording (1 )
196
200
camera .stop_recording ()
201
+ assert stream .write_called
197
202
198
203
def test_yuv_analysis2 (fake_cam ):
199
204
class YUVTest (picamera .array .PiYUVAnalysis ):
200
- def analyse (self , a ):
205
+ def analyze (self , a ):
201
206
assert (a [..., 0 ] == 1 ).all ()
202
207
assert (a [..., 1 ] == 2 ).all ()
203
208
assert (a [..., 2 ] == 3 ).all ()
@@ -211,16 +216,21 @@ def test_rgb_analysis1(camera, mode):
211
216
if resolution == (2592 , 1944 ):
212
217
pytest .xfail ('Cannot encode video at max resolution' )
213
218
class RGBTest (picamera .array .PiRGBAnalysis ):
214
- def analyse (self , a ):
219
+ def __init__ (self , camera ):
220
+ super (RGBTest , self ).__init__ (camera )
221
+ self .write_called = False
222
+ def analyze (self , a ):
223
+ self .write_called = True
215
224
assert a .shape == (resolution [1 ], resolution [0 ], 3 )
216
225
with RGBTest (camera ) as stream :
217
226
camera .start_recording (stream , 'rgb' )
218
227
camera .wait_recording (1 )
219
228
camera .stop_recording ()
229
+ assert stream .write_called
220
230
221
231
def test_rgb_analysis2 (fake_cam ):
222
232
class RGBTest (picamera .array .PiRGBAnalysis ):
223
- def analyse (self , a ):
233
+ def analyze (self , a ):
224
234
assert (a [..., 0 ] == 1 ).all ()
225
235
assert (a [..., 1 ] == 2 ).all ()
226
236
assert (a [..., 2 ] == 3 ).all ()
@@ -236,12 +246,17 @@ def test_motion_analysis1(camera, mode):
236
246
width = ((resolution [0 ] + 15 ) // 16 ) + 1
237
247
height = (resolution [1 ] + 15 ) // 16
238
248
class MATest (picamera .array .PiMotionAnalysis ):
239
- def analyse (self , a ):
249
+ def __init__ (self , camera ):
250
+ super (MATest , self ).__init__ (camera )
251
+ self .write_called = False
252
+ def analyze (self , a ):
253
+ self .write_called = True
240
254
assert a .shape == (height , width )
241
255
with MATest (camera ) as stream :
242
256
camera .start_recording ('/dev/null' , 'h264' , motion_output = stream )
243
257
camera .wait_recording (1 )
244
258
camera .stop_recording ()
259
+ assert stream .write_called
245
260
246
261
def test_motion_analysis2 (camera , mode ):
247
262
resolution , framerate = mode
@@ -252,13 +267,18 @@ def test_motion_analysis2(camera, mode):
252
267
width = ((resize [0 ] + 15 ) // 16 ) + 1
253
268
height = (resize [1 ] + 15 ) // 16
254
269
class MATest (picamera .array .PiMotionAnalysis ):
255
- def analyse (self , a ):
270
+ def __init__ (self , camera , size ):
271
+ super (MATest , self ).__init__ (camera , size )
272
+ self .write_called = False
273
+ def analyze (self , a ):
274
+ self .write_called = True
256
275
assert a .shape == (height , width )
257
276
with MATest (camera , size = resize ) as stream :
258
277
camera .start_recording (
259
278
'/dev/null' , 'h264' , motion_output = stream , resize = resize )
260
279
camera .wait_recording (1 )
261
280
camera .stop_recording ()
281
+ assert stream .write_called
262
282
263
283
def test_overlay_array1 (camera , mode ):
264
284
resolution , framerate = mode
@@ -289,3 +309,19 @@ def test_overlay_array2(camera, mode):
289
309
camera .remove_overlay (overlay )
290
310
assert not camera .overlays
291
311
312
+ def test_bayer_bad (camera ):
313
+ stream = picamera .array .PiBayerArray (camera )
314
+ stream .write (b'\x00 ' * 12000000 )
315
+ with pytest .raises (picamera .PiCameraValueError ):
316
+ stream .flush ()
317
+
318
+ def test_array_writable (camera ):
319
+ stream = picamera .array .PiRGBArray (camera )
320
+ assert stream .writable
321
+
322
+ def test_array_no_analyze (camera ):
323
+ stream = picamera .array .PiRGBAnalysis (camera )
324
+ res = camera .resolution .pad ()
325
+ with pytest .raises (NotImplementedError ):
326
+ stream .write (b'\x00 ' * (res .width * res .height * 3 ))
327
+
0 commit comments