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_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_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_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 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_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_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 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 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_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_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_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_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 getVersionNodes(self): # TODO: Use 'path' to look up versions rather than hard-coding test data. tags = self.data() pth = paths.Path(tags, format=self._pathFormat) path = pth.getPath() # print('VersionSelector getVersionNodes path:', path) rootNode = self.__internalRemap.get(path) if rootNode is not None: return rootNode exts = ['mb', 'ma'] versions_1 = [ ('v001.001', 'john', 'description', random.choice(exts)), ('v002.001', 'davidc', 'description', random.choice(exts)), ('v002.002', 'davidc', 'description', random.choice(exts)), ('v002.003', 'davidc', 'description', random.choice(exts)), ('v002.004', 'john', 'description', random.choice(exts)), ('v003.001', 'bob', 'description', random.choice(exts)), ] versions_2 = [ ('v001.001', 'davidc', 'description', random.choice(exts)), ] versions_3 = [ ('v001.001', 'davidc', 'description', random.choice(exts)), ('v002.001', 'davidc', 'description', random.choice(exts)), ('v003.001', 'davidc', 'description', random.choice(exts)), ('v004.001', 'davidc', 'description', random.choice(exts)), ('v005.001', 'davidc', 'description', random.choice(exts)), ('v006.001', 'davidc', 'description', random.choice(exts)), ('v007.001', 'davidc', 'description', random.choice(exts)), ('v008.001', 'davidc', 'description', random.choice(exts)), ('v009.001', 'davidc', 'description', random.choice(exts)), ('v010.001', 'davidc', 'description', random.choice(exts)), ('v011.001', 'davidc', 'description', random.choice(exts)), ('v012.001', 'john', 'description', random.choice(exts)), ] versions_4 = [ ('v001.001', 'bob', 'description', random.choice(exts)), ('v001.002', 'bob', 'description', random.choice(exts)), ('v001.003', 'bob', 'description', random.choice(exts)), ('v001.004', 'bob', 'description', random.choice(exts)), ('v001.005', 'bob', 'description', random.choice(exts)), ('v001.006', 'bob', 'description', random.choice(exts)), ('v001.007', 'bob', 'description', random.choice(exts)), ('v001.008', 'bob', 'description', random.choice(exts)), ('v001.009', 'bob', 'description', random.choice(exts)), ('v001.010', 'bob', 'description', random.choice(exts)), ('v002.001', 'davidc', 'description', random.choice(exts)), ('v002.002', 'davidc', 'description', random.choice(exts)), ('v002.003', 'davidc', 'description', random.choice(exts)), ('v002.004', 'davidc', 'description', random.choice(exts)), ('v002.005', 'davidc', 'description', random.choice(exts)), ('v002.006', 'davidc', 'description', random.choice(exts)), ('v002.007', 'davidc', 'description', random.choice(exts)), ('v002.008', 'davidc', 'description', random.choice(exts)), ('v002.009', 'davidc', 'description', random.choice(exts)), ('v002.010', 'davidc', 'description', random.choice(exts)), ('v002.011', 'davidc', 'description', random.choice(exts)), ('v002.012', 'davidc', 'description', random.choice(exts)), ] versions = [versions_1, versions_2, versions_3, versions_4] versions = random.choice(versions) major_versions = {} minor_versions = {} rootNode = nodes.Node('ROOT') for version in versions: ver = version[0] split = str(ver).split('.') major_ver = split[0] minor_ver = split[1] user = version[1] desc = version[2] file_ext = version[3] data = { 'major': major_ver, 'minor': minor_ver, 'version': ver, 'user': user, 'description': desc, 'ext': file_ext, } # Create Major Version if major_ver in major_versions: majorNode = major_versions[major_ver] else: majorNode = MajorVersionNode(major_ver, parent=rootNode, data=data) # Create Minor Version if ver in minor_versions: minorNode = minor_versions[major_ver] else: minorNode = MinorVersionNode(minor_ver, user, desc, parent=majorNode, data=data) major_versions[major_ver] = majorNode minor_versions[ver] = minorNode self.__internalRemap[path] = rootNode return rootNode
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())