Skip to content

Commit

Permalink
Merged in backlog/review-compound-extension-tests (pull request #253)
Browse files Browse the repository at this point in the history
Backlog/review compound extension tests

Approved-by: Henrik Norin
Approved-by: Steve Petterborg
  • Loading branch information
hdd committed Nov 12, 2020
2 parents 099d445 + 1ac65b8 commit ae78364
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 56 deletions.
6 changes: 4 additions & 2 deletions source/ftrack_api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,10 +1933,12 @@ def create_component(
synchronous=True
)

# Pick the first valid result or None
file_type = next((result for result in file_type if result), None)
if not file_type:
file_type = os.path.splitext(path)[-1]
file_type = os.path.splitext(path)[-1]

data.setdefault('file_type',file_type)
data.setdefault('file_type', file_type)

return self._create_component(
'FileComponent', path, data, location
Expand Down
89 changes: 35 additions & 54 deletions test/unit/structure/test_get_file_from_string_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,99 +15,80 @@ def structure():
return ftrack_api.structure.id.IdStructure(prefix='another_path')


def container_component():
'''Return container component.'''
session = ftrack_api.Session()

entity = session.create('ContainerComponent', {
'id': '03ab9967-f86c-4b55-8252-cd187d0c244a',
'name': 'container_component'
})

return entity


def file_compound_extension_component_event(container=None):
def file_compound_extension_no_component_event(component_file=None):

'''
Return file component with compound extension through
**ftrack.api.session.get-file-type-from-string** event.
'''

plugin_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..','..','fixture', 'plugin')
)
session = ftrack_api.Session(plugin_paths=[plugin_path])
session = ftrack_api.Session()

entity = session.create('FileComponent', {
'id': 'f6cd40cb-d1c0-469f-a2d5-10369be8a724',
'name': '0010',
'file_type': '.foo.bar',
'container': container
})
entity = session.create_component(
component_file
)

return entity


def sequence_compound_extension_component_event(padding=0):
def file_compound_extension_component_event(component_file=None):

'''
Return sequence component with *padding* through
Return file component with compound extension through
**ftrack.api.session.get-file-type-from-string** event.
'''

plugin_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', 'fixture', 'plugin')
os.path.join(os.path.dirname(__file__), '..','..','fixture', 'plugin')
)
session = ftrack_api.Session(plugin_paths=[plugin_path])

entity = session.create('SequenceComponent', {
'id': 'ff17edad-2129-483b-8b59-d1a654c8497b',
'name': 'sequence_component',
'file_type': '.foo.bar',
'padding': padding

})
entity = session.create_component(
component_file
)

return entity


@pytest.mark.parametrize('entity, context, expected', [
(
file_compound_extension_component_event(), {},
'another_path/f/6/c/d/40cb-d1c0-469f-a2d5-10369be8a724.foo.bar'
file_compound_extension_component_event('mytest.foo.bar'), {},
'.foo.bar'
),
(
file_compound_extension_component_event('mytest.%4d.foo.bar'), {},
'.foo.bar'
),
(
file_compound_extension_component_event(container_component()), {},
'another_path/0/3/a/b/9967-f86c-4b55-8252-cd187d0c244a/'
'f6cd40cb-d1c0-469f-a2d5-10369be8a724.foo.bar'
),
file_compound_extension_component_event('mytest'), {},
''
),
(
file_compound_extension_component_event(
sequence_compound_extension_component_event()
), {},
'another_path/f/f/1/7/edad-2129-483b-8b59-d1a654c8497b/file.0010.foo.bar'
file_compound_extension_no_component_event('mytest.foo.bar'), {},
'.bar'
),
(
sequence_compound_extension_component_event(padding=0), {},
'another_path/f/f/1/7/edad-2129-483b-8b59-d1a654c8497b/file.%d.foo.bar'
(
file_compound_extension_no_component_event('mytest.%4d.foo.bar'), {},
'.bar'
),
(
sequence_compound_extension_component_event(padding=4), {},
'another_path/f/f/1/7/edad-2129-483b-8b59-d1a654c8497b/file.%04d.foo.bar'
(
file_compound_extension_no_component_event('mytest'), {},
''
),
], ids=[
'file-compound-extension-component',
'file-component-compound-extension-in-container',
'file-component-compound-extension-in-sequence',
'unpadded-sequence-compound-extension-component',
'padded-sequence-compound-extension-component',
'file-compound-extension-component-event',
'file-sequence-compound-extension-component-event',
'no-file-compound-extension-component-event',
'file-compound-extension-no-component-event',
'file-sequence-compound-extension-no-component-event',
'no-file-compound-extension-no-component-event'
])
def test_get_resource_identifier(structure, entity, context, expected):
'''Get resource identifier.'''
if inspect.isclass(expected) and issubclass(expected, Exception):
with pytest.raises(expected):
structure.get_resource_identifier(entity, context)
else:
assert structure.get_resource_identifier(entity, context) == expected
assert structure.get_resource_identifier(entity, context).endswith(expected)

0 comments on commit ae78364

Please sign in to comment.