Skip to content

Commit b55064c

Browse files
committed
Fixed the tuning test
Deliberately using a bad tuning file was breaking the tuning test - I couldn't recreate Picamera objects. I've now updated the default tuning such that it fetches the camera's type at import time - this means I can keep resetting the tuning, even if the camera is in an odd state. It may be worth moving this logic into the main module as well.
1 parent e239ad2 commit b55064c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/test_tuning.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import os
22
from picamera2 import Picamera2
3+
from labthings_picamera2 import recalibrate_utils
34

45
import pytest
56

67

8+
MODEL = Picamera2.global_camera_info()[0]['Model']
9+
10+
11+
def check_camera_available():
12+
assert len(Picamera2.global_camera_info()) >= 1
13+
14+
715
def load_default_tuning():
8-
with Picamera2() as cam:
9-
cp = cam.camera_properties
10-
fname = f"{cp['Model']}.json"
11-
return cam.load_tuning_file(fname)
16+
fname = f"{MODEL}.json"
17+
return Picamera2.load_tuning_file(fname)
1218

1319

1420
def generate_bad_tuning():
@@ -39,13 +45,20 @@ def _test_bad_tuning_after_good_tuning(configure):
3945
if configure:
4046
cam.configure(cam.create_preview_configuration())
4147
del cam
48+
recalibrate_utils.recreate_camera_manager()
4249
print(f"Opening camera with tuning['version'] = {bad_tuning['version']}")
4350
with pytest.raises(IndexError):
4451
# The bad version should cause a problem
4552
cam = Picamera2(tuning=bad_tuning)
4653
print_tuning()
4754
print("Success (not expected)!")
4855
del cam
56+
recalibrate_utils.recreate_camera_manager()
57+
with Picamera2(tuning=default_tuning) as cam:
58+
# Reload the camera with working tuning, or it will stop responding
59+
# and fail future tests
60+
pass
61+
del cam
4962

5063

5164
@pytest.mark.filterwarnings("ignore: Exception ignored")

0 commit comments

Comments
 (0)