From 6f19923a918f7fb63a444b0c99950fdbe9d2f74c Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Tue, 8 Nov 2022 11:40:39 +0100 Subject: New upstream version 20221106+py3 --- tests/unit/test_directory.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/unit/test_directory.py') 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)) -- cgit v1.2.3