Adding elevation images folder and test logic (#1225)

* Added new test code for elevation images. Added elevation folder.

* Also adding first file with image definitions
This commit is contained in:
Daniel W. Anner 2023-03-24 16:50:47 -04:00 committed by GitHub
parent 128de187ea
commit f78c90d38b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 0 deletions

View File

@ -7,6 +7,8 @@ u_height: 1
is_full_depth: true # 21.65"
weight: 24.65
weight_unit: lb
front_image: true
rear_image: true
comments: '[Datasheet](https://onestore.nokia.com/asset/210990)'
console-ports:
- name: Console

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -47,6 +47,12 @@
"oz"
]
},
"front_image": {
"type": "boolean"
},
"rear_image": {
"type": "boolean"
},
"subdevice_role": {
"type": "string",
"enum": [

View File

@ -15,6 +15,10 @@ SCHEMAS = (
('module-types', 'moduletype.json'),
)
IMAGE_FILETYPES = (
'bmp', 'gif', 'pjp', 'jpg', 'pjpeg', 'jpeg', 'jfif', 'png', 'tif', 'tiff', 'webp'
)
COMPONENT_TYPES = (
'console-ports',
'console-server-ports',
@ -49,8 +53,24 @@ def _get_definition_files():
return ret
def _get_image_files():
"""
Return a list of all image files within the specified path and manufacturer.
"""
ret = []
for f in sorted(glob.glob(f"elevation-images/*/*", recursive=True)):
# f = 'elevation-images/Nokia/nokia-7220-ixr-h3-front.png'
# f.split('/')[1] = Nokia
assert f.split('/')[2].split('.')[-1] in IMAGE_FILETYPES, f"Invalid file extension: {f}"
ret.append((f.split('/')[1], f))
return ret
definition_files = _get_definition_files()
image_files = _get_image_files()
known_slugs = set()
@ -133,4 +153,27 @@ def test_definitions(file_path, schema):
elif isinstance(list_value, list):
iterlist(list_value)
# Check for images if front_image or rear_image is True
if (definition.get('front_image') or definition.get('rear_image')):
manufacturer_images = [image for image in image_files if image[0] == file_path.split('/')[1]]
if not manufacturer_images:
pytest.fail(f'{file_path} has Front or Rear Image set to True but no images found for manufacturer', False)
if(definition.get('front_image')):
devices = [image_path.split('/')[2] for image, image_path in manufacturer_images if image_path.split('/')[2].split('.')[1] == 'front']
if not devices:
pytest.fail(f'{file_path} has front_image set to True but no images found for device', False)
for device_image in devices:
assert slug.find(device_image.split('.')[0].casefold()) != -1, f'{file_path} has front_image set to True but no images found for device'
if(definition.get('rear_image')):
devices = [image_path.split('/')[2] for image, image_path in manufacturer_images if image_path.split('/')[2].split('.')[1] == 'rear']
if not devices:
pytest.fail(f'{file_path} has rear_image set to True but no images found for device', False)
for device_image in devices:
assert slug.find(device_image.split('.')[0].casefold()) != -1, f'{file_path} has rear_image set to True but no images found for device'
iterdict(definition)