def test_init(self): fmt = paths.PathFormat() value = fmt.getString() self.assertEqual(value, None) data = '/{project}/{shot}/{assetType}/{name}/{user}_{version}.{ext}' fmt = paths.PathFormat(data) value = fmt.getString() self.assertEqual(value, data)
def test_splitPathIntoTags(self): fmt = paths.PathFormat('/projects/{project}/{sequence}/{shot}/{department}/{task}/{name}_{major}.{minor}.{ext}') value = '/projects/xmen/fin/fin0020/{department}/{task}/{name}_{major}.{minor}.{ext}' pth = paths.Path(value, format=fmt) self.assertEqual(pth.getPath(showMissingKeys=True), value) fmt = paths.PathFormat('/{name}_{version}.{ext}') value = '/myAsset_v001.obj' # pth = paths.Path(, format=fmt) tags = paths.Path._splitPathIntoTags(value, fmt) values = {'name': 'myAsset', 'version': 'v001', 'ext': 'obj'} self.assertEqual(values, tags)
def test_setTagValue(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') tags = {'name': 'myAsset', 'version': 'v001', 'ext': 'obj'} pth = paths.Path(tags, format=fmt) self.assertEqual(pth.getTagValue('name'), 'myAsset') pth.setTagValue('name', 'myFile') self.assertEqual(pth.getTagValue('name'), 'myFile')
def test_getTagKeyIndex(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') pth = paths.Path('/myAsset_v001.obj', format=fmt) keys = fmt.computeOrderedTagKeys() for i, key in enumerate(keys): j = pth.getTagKeyIndex(key) self.assertEqual(j, i)
def test_init(self): fmtStr = '/{path}/{name}/{version}.{ext}' fmt = paths.PathFormat(fmtStr) pth = paths.Path() self.assertEqual(pth.getPath(), None) self.assertEqual(pth.getTags(), None) data = '/path/to/file.txt' pth = paths.Path(data) self.assertEqual(pth.getPath(), None) pth.setPathFormat(fmt) self.assertEqual(pth.getPath(), data) pth = paths.Path(path=data, format=fmt) self.assertEqual(data, pth.getPath()) data = {'key': 'value'} pth = paths.Path(data) self.assertEqual(pth.getTags(), None) pth.setPathFormat(fmt) self.assertEqual(pth.getTags(), data) pth = paths.Path(tags=data, format=fmt) self.assertEqual(data, pth.getTags()) pth1 = paths.Path('/my/path/goes/here', format=fmtStr) fmt2 = pth1.getPathFormat() self.assertEqual(fmt.getString(), fmt2.getString())
def test_getTags(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') tags1 = {'name': 'myAsset', 'version': 'v001', 'ext': 'obj'} pth = paths.Path(tags1, format=fmt) tags2 = pth.getTags() self.assertTrue(tags1 is not tags2) self.assertEqual(tags1, tags2)
def test_setTags(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') tags = {'name': 'myAsset', 'version': 'v001', 'ext': 'obj'} pth = paths.Path(tags, format=fmt) tags_copy = pth.getTags() tags.update(version='v002') pth.setTags(tags) self.assertTrue(tags is not tags_copy) self.assertNotEqual(pth.getTags(), tags_copy)
def test_getTagValue(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') value = '/myAsset_v001.obj' pth = paths.Path(value, format=fmt) self.assertEqual(pth.getTagValue('name'), 'myAsset') self.assertEqual(pth.getTagValue('nonexistantkey'), None) pth = paths.Path() self.assertEqual(pth.getTagValue('key'), None)
def test_getPath(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') value = '/myAsset_v001.obj' pth = paths.Path(value, format=fmt) self.assertEqual(pth.getPath(), value) path = pth.getPath() self.assertEqual(pth.getPath(), path) pth.setPath('/myAsset_v001.') path = pth.getPath(showMissingKeys=True) self.assertEqual(path, '/myAsset_v001.{ext}') fmt = paths.PathFormat('/projects/{project}/{name}_{version}.{ext}') pth = paths.Path({'name': 'myAsset', 'version': 'v001', 'ext': 'obj'}, format=fmt) self.assertEqual(pth.getPath(), '/projects/') fmt = paths.PathFormat('/projects/{project}/{name}_{version}.{ext}') pth = paths.Path({'name': 'myAsset', 'version': 'v001', 'ext': 'obj'}, format=fmt) self.assertEqual(pth.getPath(), '/projects/')
def slotPathTextUpdated(self, text): print('PathEdit slotPathTextUpdated', text) fmt = paths.PathFormat(self.pathFormat()) pth = paths.Path(text, format=fmt) path = pth.getPath(showMissingKeys=True) print('slotPathTextUpdated path:', path) # pos = self.lineEdit.cursorPosition() # self.lineEdit.setText(path) # self.lineEdit.setCursorPosition(pos) # print('PathEdit slotPathTextUpdated 2', path) # self.updatePathText() return
def test_pathAndTagsConversion(self): fmt = paths.PathFormat('/{project}/{shot}/{assetType}/{name}/{user}_{version}.{ext}') pth = paths.Path({'project': 'dunkirk', 'shot': 'sh0010', 'assetType': 'rig'}, format=fmt) pth.setTagValue('user', 'davidc') pth.setTagValue('ext', 'doc') pth.setTagValue('name', 'myAsset') pth.setTagValue('version', 'v001') path = pth.getPath() path = path.replace('myAsset', 'car001') pth.setPath(path) tags = pth.getTags() self.assertIn('version', tags) tags['shot'] = 'sh0020' pth.setTags(tags)
def updatePathText(self): if len(self._tagChanged) == 0: return tagData = self.getTags().copy() fmt = paths.PathFormat(self.pathFormat()) orderedKeys = fmt.computeOrderedTagKeys() index = -1 for i, key in enumerate(orderedKeys): if key in tagData: if self._tagChanged.get(key) is not True: continue value = tagData.get(key) if value is None: continue index = i # print('PathEdit updatePathText last index:', index) # print('PathEdit updatePathText tagChanged:', self._tagChanged) if index < 0: return resetKeys = orderedKeys[index + 1:] for key in resetKeys: tagData[key] = None self.setTags(tagData) pth = paths.Path(tagData, format=fmt) tooltip = computeToolTip(pth, fmt, tagData) path = pth.getPath(showMissingKeys=True) # print('PathEdit updatePathText path:', path) # print('PathEdit updatePathText path tags:', pth.getTags()) # print('PathEdit updatePathText path tag values:', pth.getTagValuesOrdered()) # print('PathEdit updatePathText path tag keys:', pth.getTagKeysOrdered()) self.lineEdit.setText(path) self.lineEdit.setToolTip(tooltip) if self.qtEqualOrAbove_4_7_X(): self.lineEdit.setPlaceholderText("File Path...") # tagData['path'] = path # tagData['tooltip'] = tooltip self.signalPathUpdated.emit(tagData)
def test_isValid(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') tags = {'name': 'myAsset', 'version': 'v001', 'ext': 'obj'} pth = paths.Path(tags, format=fmt) self.assertTrue(pth.isValid())
def test_setPath(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') pth = paths.Path(format=fmt) value = '/myAsset_v001.obj' pth.setPath(value) self.assertEqual(pth.getPath(), value)
def test_getTagKeysOrdered(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') pth = paths.Path('/myAsset_v001.obj', format=fmt) keys = ['name', 'version', 'ext'] self.assertEqual(keys, pth.getTagKeysOrdered())
def test_getTagValuesOrdered(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') pth = paths.Path('/myAsset_v001.obj', format=fmt) values = ['myAsset', 'v001', 'obj'] self.assertEqual(values, pth.getTagValuesOrdered())
def test_setString(self): fmt = paths.PathFormat() data = '/{project}/{sequence}{shot}/{user}.{ext}' fmt.setString(data) value = fmt.getString() self.assertEqual(value, data)
def test_exists(self): fmt = paths.PathFormat('/{name}_{version}.{ext}') tags = {'name': 'myAsset', 'version': 'v001', 'ext': 'obj'} pth = paths.Path(tags, format=fmt) self.assertFalse(pth.exists())