def validate_filepath(self, filepath): # type: (Union[str, Path]) -> None ''' Attempts to parse the given filepath. Args: filepath (str or Path): filepath to asset file. Raises: ValidationError: If parse fails. ValidationError: If asset directory name is invalid. ''' filepath = Path(filepath) try: data = AssetNameParser(self.filename_fields).parse(filepath.name) except ParseException as e: raise ValidationError(repr(e)) if self.asset_type == 'file': return parser = AssetNameParser(self.asset_name_fields) actual = self.get_asset_path(filepath).name try: parser.parse(actual) except ParseException as e: raise ValidationError(repr(e)) expected = parser.to_string(data) if actual != expected: msg = 'Invalid asset directory name. ' msg += f'Expecting: {expected}. Found: {actual} in ' msg += f'{filepath.as_posix()}.' raise ValidationError(msg)
def test_recurse_init(self): fields = [ 'project', 'specification', 'descriptor', 'version', 'frame', 'extension' ] expected = 'p-proj002_s-spec062_d-desc_v099_f0078.exr' parser = AssetNameParser(fields) result = parser.parse(expected) result = parser.to_string(result) self.assertEqual(result, expected)