Skip to content

Commit 1c8f4fd

Browse files
committed
A bit of work on coverage
1 parent 9c94208 commit 1c8f4fd

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

Diff for: picamera/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def __init__(self, camera, size=None):
528528
self.camera = camera
529529
self.size = size
530530

531-
def writeable(self):
531+
def writable(self):
532532
return True
533533

534534
def write(self, b):

Diff for: tests/test_array.py

+42-6
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,21 @@ def test_yuv_analysis1(camera, mode):
188188
if resolution == (2592, 1944):
189189
pytest.xfail('Cannot encode video at max resolution')
190190
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
192196
assert a.shape == (resolution[1], resolution[0], 3)
193197
with YUVTest(camera) as stream:
194198
camera.start_recording(stream, 'yuv')
195199
camera.wait_recording(1)
196200
camera.stop_recording()
201+
assert stream.write_called
197202

198203
def test_yuv_analysis2(fake_cam):
199204
class YUVTest(picamera.array.PiYUVAnalysis):
200-
def analyse(self, a):
205+
def analyze(self, a):
201206
assert (a[..., 0] == 1).all()
202207
assert (a[..., 1] == 2).all()
203208
assert (a[..., 2] == 3).all()
@@ -211,16 +216,21 @@ def test_rgb_analysis1(camera, mode):
211216
if resolution == (2592, 1944):
212217
pytest.xfail('Cannot encode video at max resolution')
213218
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
215224
assert a.shape == (resolution[1], resolution[0], 3)
216225
with RGBTest(camera) as stream:
217226
camera.start_recording(stream, 'rgb')
218227
camera.wait_recording(1)
219228
camera.stop_recording()
229+
assert stream.write_called
220230

221231
def test_rgb_analysis2(fake_cam):
222232
class RGBTest(picamera.array.PiRGBAnalysis):
223-
def analyse(self, a):
233+
def analyze(self, a):
224234
assert (a[..., 0] == 1).all()
225235
assert (a[..., 1] == 2).all()
226236
assert (a[..., 2] == 3).all()
@@ -236,12 +246,17 @@ def test_motion_analysis1(camera, mode):
236246
width = ((resolution[0] + 15) // 16) + 1
237247
height = (resolution[1] + 15) // 16
238248
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
240254
assert a.shape == (height, width)
241255
with MATest(camera) as stream:
242256
camera.start_recording('/dev/null', 'h264', motion_output=stream)
243257
camera.wait_recording(1)
244258
camera.stop_recording()
259+
assert stream.write_called
245260

246261
def test_motion_analysis2(camera, mode):
247262
resolution, framerate = mode
@@ -252,13 +267,18 @@ def test_motion_analysis2(camera, mode):
252267
width = ((resize[0] + 15) // 16) + 1
253268
height = (resize[1] + 15) // 16
254269
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
256275
assert a.shape == (height, width)
257276
with MATest(camera, size=resize) as stream:
258277
camera.start_recording(
259278
'/dev/null', 'h264', motion_output=stream, resize=resize)
260279
camera.wait_recording(1)
261280
camera.stop_recording()
281+
assert stream.write_called
262282

263283
def test_overlay_array1(camera, mode):
264284
resolution, framerate = mode
@@ -289,3 +309,19 @@ def test_overlay_array2(camera, mode):
289309
camera.remove_overlay(overlay)
290310
assert not camera.overlays
291311

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

Comments
 (0)