Skip to content

Commit

Permalink
Improve image tests (#2500)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Daniel W. Anner <[email protected]>
  • Loading branch information
3 people authored Dec 26, 2024
1 parent 92c1cbd commit 4092cea
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tests/definitions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def iterlist(var):
# 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:
Expand All @@ -232,13 +232,12 @@ def iterlist(var):
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)

0 comments on commit 4092cea

Please sign in to comment.