summaryrefslogtreecommitdiff
path: root/tests/unit/test_directory.py
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2022-11-08 11:40:45 +0100
committerChristoph Berg <christoph.berg@credativ.de>2022-11-08 11:40:45 +0100
commit42b1373eff59af2aebb218ded3d2d55cc96dc630 (patch)
treed6e7e435fa41c65fff7a73dd7dc99bb4a12da5c8 /tests/unit/test_directory.py
parent176c8e29d64892072697c5d30513204773545a9b (diff)
parent6f19923a918f7fb63a444b0c99950fdbe9d2f74c (diff)
Update upstream source from tag 'upstream/20221106+py3'
Update to upstream version '20221106+py3' with Debian dir b54298e303932808cc08745c5f5133ad7b12628e
Diffstat (limited to 'tests/unit/test_directory.py')
-rw-r--r--tests/unit/test_directory.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/unit/test_directory.py b/tests/unit/test_directory.py
index d48bb48..c447173 100644
--- a/tests/unit/test_directory.py
+++ b/tests/unit/test_directory.py
@@ -1,5 +1,7 @@
import base64
+import glob
import json
+import os
import tempfile
from tests.unit import base
@@ -67,3 +69,26 @@ class TestDirectory(base.BaseTest):
self.assertEqual('Barmaster 2000', radio.MODEL)
self.assertEqual('A', radio.VARIANT)
+
+class TestDetectBruteForce(base.BaseTest):
+ def test_detect_all(self):
+ # Attempt a brute-force detection of all test images.
+ #
+ # This confirms that no test image is detected by more than one
+ # radio class. If it is, fail and report those classes.
+
+ path = os.path.dirname(__file__)
+ path = os.path.join(path, '..', 'images', '*.img')
+ test_images = glob.glob(path)
+ self.assertNotEqual(0, len(test_images))
+ for image in test_images:
+ detections = []
+ filedata = open(image, 'rb').read()
+ for cls in directory.RADIO_TO_DRV:
+ if not hasattr(cls, 'match_model'):
+ continue
+ if cls.match_model(filedata, image):
+ detections.append(cls)
+ if len(detections) > 1:
+ raise Exception('Detection of %s failed: %s' % (image,
+ detections))