Pytest Test Case - Renamed File w/o Slug/PN Change (#1708)

* Updating tests to solve the issue in PR#1667 which fails on a renamed file (with a valid slug)

* preseving old functionality
This commit is contained in:
Daniel W. Anner 2023-10-23 16:11:49 -04:00 committed by GitHub
parent cc11ac6174
commit 6aae04ac3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View File

@ -32,7 +32,7 @@ def _get_definition_files():
# Map each definition file to its schema as a tuple (file, schema)
for file in sorted(glob.glob(f"{path}/*/*", recursive=True)):
file_list.append((file, schema))
file_list.append((file, schema, 'skip'))
return file_list
@ -67,11 +67,11 @@ def _get_diff_from_upstream():
if file.change_type in CHANGE_TYPE_LIST:
# If the file is renamed, ensure we are picking the right schema
if 'R' in file.change_type and path in file.rename_to:
file_list.append((file.rename_to, schema))
file_list.append((file.rename_from, schema, file.change_type))
elif path in file.a_path:
file_list.append((file.a_path, schema))
file_list.append((file.a_path, schema, file.change_type))
elif path in file.b_path:
file_list.append((file.b_path, schema))
file_list.append((file.b_path, schema, file.change_type))
return file_list
@ -127,8 +127,8 @@ else:
KNOWN_MODULES = pickle_operations.read_pickle_data(f'{temp_dir.name}/tests/known-modules.pickle')
@pytest.mark.parametrize(('file_path', 'schema'), definition_files)
def test_definitions(file_path, schema):
@pytest.mark.parametrize(('file_path', 'schema', 'change_type'), definition_files)
def test_definitions(file_path, schema, change_type):
"""
Validate each definition file using the provided JSON schema and check for duplicate entries.
"""
@ -161,10 +161,10 @@ def test_definitions(file_path, schema):
# Identify if the definition is for a Device or Module
if "device-types" in file_path:
# A device
this_device = DeviceType(definition, file_path)
this_device = DeviceType(definition, file_path, change_type)
else:
# A module
this_device = ModuleType(definition, file_path)
this_device = ModuleType(definition, file_path, change_type)
# Verify the slug is valid, only if the definition type is a Device
if this_device.isDevice:

View File

@ -4,7 +4,7 @@ class DeviceType:
def __new__(cls, *args, **kwargs):
return super().__new__(cls)
def __init__(self, definition, file_path):
def __init__(self, definition, file_path, change_type):
self.file_path = file_path
self.isDevice = True
self.definition = definition
@ -16,6 +16,7 @@ class DeviceType:
self.part_number = definition.get('part_number', "")
self._slug_part_number = self._slugify_part_number()
self.failureMessage = None
self.change_type = change_type
def _slugify_manufacturer(self):
return self.manufacturer.casefold().replace(" ", "-").replace("sfp+", "sfpp").replace("poe+", "poep").replace("-+", "-plus-").replace("+", "-plus").replace("_", "-").replace("!", "").replace("/", "-").replace(",", "").replace("'", "").replace("*", "-").replace("&", "and")
@ -48,8 +49,9 @@ class DeviceType:
pass
elif len(known_slug_list_intersect) == 1:
if self.file_path not in known_slug_list_intersect[0][1]:
self.failureMessage = f'{self.file_path} has a duplicate slug: "{self.slug}"'
return False
if 'R' not in self.change_type:
self.failureMessage = f'{self.file_path} has a duplicate slug: "{self.slug}"'
return False
return True
else:
self.failureMessage = f'{self.file_path} has a duplicate slug "{self.slug}"'
@ -126,7 +128,7 @@ class ModuleType:
def __new__(cls, *args, **kwargs):
return super().__new__(cls)
def __init__(self, definition, file_path):
def __init__(self, definition, file_path, change_type):
self.file_path = file_path
self.isDevice = False
self.definition = definition
@ -135,6 +137,7 @@ class ModuleType:
self._slug_model = self._slugify_model()
self.part_number = definition.get('part_number', "")
self._slug_part_number = self._slugify_part_number()
self.change_type = change_type
def get_filepath(self):
return self.file_path