Improve image tests (#2500)

* Fix rear_imge test and description

* replace '/' by os.path.sep

* Extend error messages to include expected filenames

* fix image path (use elevation-images as base dir)

* add quotes around expected path

* Improve failure message

* remove redundant image description

---------

Co-authored-by: Giotta Simon <simon.giotta@ruag.ch>
Co-authored-by: Daniel W. Anner <daniel.anner@danstechsupport.com>
This commit is contained in:
raven 2024-12-26 18:31:24 +01:00 committed by GitHub
parent 92c1cbdfc3
commit 4092cea07c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -221,7 +221,7 @@ def test_definitions(file_path, schema, change_type):
# Check for images if front_image or rear_image is True
if (definition.get('front_image') or definition.get('rear_image')):
# Find images for given manufacturer, with matching device slug (exact match including case)
manufacturer_images = [image[1] for image in image_files if image[0] == file_path.split('/')[1] and os.path.basename(image[1]).split('.')[0] == this_device.get_slug()]
manufacturer_images = [image[1] for image in image_files if image[0] == file_path.split(os.path.sep)[1] and os.path.basename(image[1]).split('.')[0] == this_device.get_slug()]
if not manufacturer_images:
pytest.fail(f'{file_path} has Front or Rear Image set to True but no images found for manufacturer/device (slug={this_device.get_slug()})', False)
elif len(manufacturer_images)>2:
@ -232,13 +232,12 @@ def test_definitions(file_path, schema, change_type):
front_image = [image_path.split('/')[2] for image_path in manufacturer_images if os.path.basename(image_path).split('.')[1] == 'front']
if not front_image:
pytest.fail(f'{file_path} has front_image set to True but no matching image found for device ({manufacturer_images})', False)
pytest.fail(f'{file_path} has front_image set to True but no matching image found (looking for \'elevation-images{os.path.sep}{file_path.split(os.path.sep)[1]}{os.path.sep}{this_device.get_slug()}.front.ext\' but only found {manufacturer_images})', False)
# If rear_image is True, verify that a front image exists
# If rear_image is True, verify that a rear image exists
if(definition.get('rear_image')):
rear_image = [image_path.split('/')[2] for image_path in manufacturer_images if os.path.basename(image_path).split('.')[1] == 'rear']
if not rear_image:
pytest.fail(f'{file_path} has rear_image set to True but no images found for device', False)
pytest.fail(f'{file_path} has rear_image set to True but no matching image found (looking for \'elevation-images{os.path.sep}{file_path.split(os.path.sep)[1]}{os.path.sep}{this_device.get_slug()}.rear.ext\' but only found {manufacturer_images})', False)
iterdict(definition)