def load_all_configs(cls): ''' 读取当前硬盘上所有DB_CONFIG 对应的json :return: None ''' config_path = DayuPath( os.environ.get( DAYU_CONFIG_STATIC_PATH, DayuPath(__file__).parent.child('static', cls.prefix + '_config_presets'))) assert config_path.exists() is True for json_preset in config_path.walk(): if json_preset.ext == '.json': with open(json_preset, 'r') as jf: preset_value = json.load(jf, encoding='utf-8') preset_key = json_preset.replace(config_path, '').replace('\\', '/') preset_key = preset_key.replace('.json', '').replace('default', '').strip('/') preset_key = cls.prefix + '.' + '.'.join( preset_key.split('/')) cls.all_configs.update({preset_key: preset_value}) return cls()
def mock_path(): dayu_path = DayuPath('~').expand_user().child(uuid4().hex) content_list = [ 'first_depth_0010.1001.dpx', 'first_depth_0010.1002.dpx', 'cam_test/A001C001_180212_RG8C.9876521.exr', 'cam_test/A001C001_180212_RG8C.9876522.exr', 'cam_test/A001C001_180212_RG8C.9876523.exr', 'vfx_test/pl_0010_plt_v0001.1001.exr', 'vfx_test/pl_0010_plt_v0001.1002.exr', 'vfx_test/pl_0010_plt_v0001.1003.exr', 'not_a_sequence/abc.exr', 'single_media_test/pl_0010_plt_v0001.1003.mov', 'single_media_test/MVI1022.MP4', u'single_media_test/测试中文.MP4', 'missing_test/dd_0090_ani_1001.jpg', 'missing_test/dd_0090_ani_1003.jpg', 'missing_test/dd_0090_ani_1005.jpg', 'ignore_test/._DS_store', 'ignore_test/..sdf', 'recursive_test/a_001.exr', 'recursive_test/a_002.exr', 'recursive_test/inside/b_100.exr', 'recursive_test/inside/b_101.exr', 'recursive_test/inside/b_102.exr', ] for x in content_list: file_path = DayuPath(u'{}/{}'.format(dayu_path, x)) file_path.parent.mkdir(parents=True) with open(file_path, 'w') as f: f.write('1') dayu_path.child('empty_folder', 'inside').mkdir(parents=True) return dayu_path
def test_root(self): self.assertEqual(DayuPath('/Users/andyguo/Desktop/abc.jpg').root, '/') self.assertEqual( DayuPath('/Volumes/filedata/td/finder.lnk').root, '/Volumes/filedata') self.assertIsInstance( DayuPath('/Volumes/filedata/td/finder.lnk').root, DayuPath)
def disk_path(self): ''' 将SubLevel 对象转换为普通的DiskPath 对象。 之后进行的所有操作,都必须对硬盘进行操作。而无法利用数据库的信息了。 :return: DiskPath 对象 ''' return DayuPath(self)
def disk_path(self, disk_type='publish', refresh=False): ''' 从orm 转换到DiskPath 的对象 :param disk_type: string,通常可以选择 'publish', 'work', 'cache'。(需要和storage_config 的内容保持一致) :return: DiskPath 对象(实际在硬盘上的存放路径) ''' if getattr(self, '_cache_{}_disk_path'.format(disk_type), None) and refresh is False: return getattr(self, '_cache_{}_disk_path'.format(disk_type), None) from dayu_path import DayuPath import util storage = util.get_storage_config(self.storage_config_name) db_config = util.get_db_config(self.db_config_name) parents = self.hierarchy result = storage.config[disk_type][sys.platform] for index, x in enumerate(parents[1:]): depth_config = db_config.config[str(index + 1)] param_list = [] for param in depth_config['to_disk_param'][x.meaning][disk_type]: match = DiskPathMixin._eval_regex.match(param) if match: func = getattr(util, match.groups()[0]) if func: param_list.append(func()) else: param_list.append(getattr(x, param)) result += depth_config['to_disk'][x.meaning][disk_type].format(*param_list) setattr(self, '_cache_{}_disk_path'.format(disk_type), DayuPath(result)) getattr(self, '_cache_{}_disk_path'.format(disk_type), None)._cache_orm = self return getattr(self, '_cache_{}_disk_path'.format(disk_type), None)
def generate_configs(): ''' 根据DECISION_TREE 全局变量生成json 文件结构的函数。 如果不希望拥有文件夹层级也可以不运行,因为只要把对应的json config 文件都放到sub_level_config_presets 文件夹内就好。 load_all_config() 函数只会读取json 的文件名作为选择条件,不会管文件夹层级。 但是推荐使用文件夹层级进行管理。 :return: ''' import os root_path = DayuPath( os.environ.get( DAYU_CONFIG_STATIC_PATH, DayuPath(__file__).parent.child('static', presets_root))) for x in itertools.product(*DECISION_TREE): temp = root_path.child(*x) temp.mkdir(parents=True) filename = '_'.join(list(x) + ['a0001.json']) temp = temp.child(filename) if not temp.exists(): with open(temp, 'w') as jf: jf.write('')
def run(self): import subprocess import time import select from dayu_path import DayuPath self.progress = { 'render_frame': None, 'render_fps': None, 'render_speed': None, 'elapse_time': None } shell_cmd = subprocess.Popen(self.cmd(), bufsize=0, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) output_file = DayuPath(self.filename) start_time = time.time() maybe_halt = 0 current_frame = prev_frame = None while True: if shell_cmd.poll() is not None: break rs, ws, es = select.select([shell_cmd.stdout.fileno()], [], [], 1) render_files = sorted( (x for x in output_file.parent.listdir() if '.temp' not in x), key=lambda f: f.ctime()) if render_files: last_file = render_files[-1] current_frame = last_file.frame if current_frame: self.progress['elapse_time'] = time.time() - start_time self.progress['render_frame'] = current_frame self.progress['render_fps'] = 0.0 if ( prev_frame is None) else (current_frame - prev_frame) prev_frame = current_frame if current_frame == self.end: maybe_halt += 1 if maybe_halt > 3: print 'finish, but halt' break yield self.progress yield (shell_cmd.returncode, shell_cmd.communicate()[0])
def load_all_configs(software=None): ''' 读取所有设置好的json 预设。需要json 文件存放在 sub_level_config_presets 文件内 必须在加载模块的时候运行一次! :return: ''' import os if software is None: software = os.getenv(DAYU_APP_NAME, '') root_path = DayuPath( os.environ.get( DAYU_CONFIG_STATIC_PATH, DayuPath(__file__).parent.child('static', presets_root, software))) for x in root_path.walk(filter=os.path.isfile): if x.endswith('.json'): with open(x, 'r') as jf: content = jf.read() if content: SUB_LEVEL_CONFIGS.update( {'.'.join(x.stem.split('_')): json.loads(content)})
def test_version(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/v001/111.mov').version, 'v001') self.assertEqual( DayuPath('/Users/andyguo/Desktop/V001/111.mov').version, 'V001') self.assertEqual( DayuPath('/Users/andyguo/Desktop/v001/A001C001_180212_DF3X.mov'). version, 'v001') self.assertEqual( DayuPath( '/Users/andyguo/Desktop/v003/pl_0010_plt_bga_v0002.1001.mov'). version, 'v0002') self.assertEqual( DayuPath( '/Users/andyguo/Desktop/dd/pl_0010_plt_bga.1001.mov').version, None) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/vv/pl_0010_plt_bga.1001.mov').version, None) self.assertEqual(DayuPath('not a path').version, None)
def test_restore_pattern(test_data): path = DayuPath(test_data['path']).restore_pattern(test_data['pattern']) assert path == test_data['result']
def test_to_pattern(test_data): dayu_path = DayuPath(test_data['path']).to_pattern(test_data['pattern']) assert dayu_path == test_data['result']
def test_pattern(test_data): assert DayuPath(test_data['case']).pattern == test_data['result']
def test_os_functions(test_data, mock_path): path = DayuPath(mock_path).child('cam_test', 'A001C001_180212_RG8C.9876521.exr') assert getattr(path, test_data) is not None
def test_escape(self): legal_path = DayuPath('/Users/andyguo/Desktop/111.mov') self.assertEqual(legal_path.escape(), '/Users/andyguo/Desktop/111.mov') whitespace_path = DayuPath( '/Users/andyguo/Desktop/some words with space.mov') self.assertEqual( whitespace_path.escape(), '/Users/andyguo/Desktop/some\ words\ with\ space.mov') bash_string = DayuPath('The$!cat#&ran\"\'up()a|<>tree`;') self.assertEqual(bash_string.escape(), r'The\$\!cat\#\&ran\"\'up\(\)a\|\<\>tree\`\;') unicode_string = DayuPath( u'/Users/andyguo/Desktop/中文 和 空格12234 rer.jpg') self.assertEqual(unicode_string.escape(), u'/Users/andyguo/Desktop/中文\ 和\ 空格12234\ rer.jpg')
def test___new__(test_data): if test_data['case'] == 'test_object': obj = DayuPath('/Users/andyguo/Desktop/111111111.jpg') assert DayuPath(obj) == obj else: assert DayuPath(test_data['case']) == test_data['result']
def test_root(): assert DayuPath('/Users/andyguo/Desktop/abc.jpg').root == '/' assert DayuPath( '/Volumes/filedata/td/finder.lnk').root == '/Volumes/filedata' assert isinstance( DayuPath('/Volumes/filedata/td/finder.lnk').root, DayuPath)
def test_to_pattern(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/1.jpg').to_pattern(), '/Users/andyguo/Desktop/1.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/11.jpg').to_pattern(), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/11.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/11.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/123.jpg').to_pattern(), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/123.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/123.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern(), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern('ss'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%02d.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%02d.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%02d.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%03d.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%03d.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%03d.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('1'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/##.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/##.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/##.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/###.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/###.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/###.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('f'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F2.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F2.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F2.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F3.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F3.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F3.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('dd'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.mov').to_pattern('%'), '/Users/andyguo/Desktop/MVI1001.mov') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.mov').to_pattern('#'), '/Users/andyguo/Desktop/MVI1001.mov') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.mov').to_pattern('$'), '/Users/andyguo/Desktop/MVI1001.mov') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.MP4').to_pattern(), '/Users/andyguo/Desktop/MVI1001.MP4')
def test_restore_pattern(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.12.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F2.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.12.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F3.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.012.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F4.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0012.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%d.jpg' ).restore_pattern(1920), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1920.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%0d.jpg' ).restore_pattern(192), '/Users/andyguo/Desktop/sd_0010_plt_v0002.192.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%02d.jpg' ).restore_pattern(1920), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1920.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%03d.jpg' ).restore_pattern(1001), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1001.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%04d.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.#.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.##.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.###.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.####.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%04d.jpg' ).restore_pattern(0), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0000.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg' ).restore_pattern(-1), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg' ).restore_pattern(2345), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg' ).restore_pattern(None), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg')
def test_pattern(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.jpg').pattern, None) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%d.jpg').pattern, '%d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%02d.jpg').pattern, '%02d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%03d.jpg').pattern, '%03d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%04d.jpg').pattern, '%04d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_#.jpg').pattern, '#') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_##.jpg').pattern, '##') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_###.jpg').pattern, '###') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_####.jpg').pattern, '####') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F.jpg').pattern, '$F') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F2.jpg').pattern, '$F2') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F3.jpg').pattern, '$F3') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F4.jpg').pattern, '$F4') self.assertEqual( DayuPath(u'/Users/andyguo/Desktop/中文的测试$F4.jpg').pattern, '$F4') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_%04d_ani_$F4.jpg').pattern, '%04d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/ani_$F4.mov').pattern, '$F4') self.assertEqual( DayuPath('/Users/andyguo/Desktop/abc.mov').pattern, None)
def test_is_local(self): self.assertFalse(DayuPath('/Volumes/filedata/td/finder.lnk').is_local) self.assertTrue(DayuPath('/Users/andyguo/Desktop/log.txt').is_local)
def test_os_functions(self): path = DayuPath(self.mock_path).child( 'cam_test', 'A001C001_180212_RG8C.9876521.exr') self.assertIsNotNone(path.state()) self.assertIsNotNone(path.lstate()) self.assertIsNotNone(path.exists()) self.assertIsNotNone(path.lexists()) self.assertIsNotNone(path.isfile()) self.assertIsNotNone(path.isdir()) self.assertIsNotNone(path.islink()) self.assertIsNotNone(path.ismount()) self.assertIsNotNone(path.atime()) self.assertIsNotNone(path.ctime()) self.assertIsNotNone(path.mtime()) self.assertIsNotNone(path.size())
def test_escape(test_data): path = DayuPath(test_data['path']) assert path.escape() == test_data['result']
def test___new__(self): self.assertEqual(DayuPath(''), None) self.assertEqual(DayuPath([]), None) self.assertEqual(DayuPath(tuple()), None) self.assertEqual(DayuPath(set()), None) self.assertEqual(DayuPath(dict()), None) self.assertEqual(DayuPath('any_string'), 'any_string') self.assertEqual(DayuPath('/Users/andyguo/Desktop/111111111.jpg'), '/Users/andyguo/Desktop/111111111.jpg') self.assertEqual(DayuPath(u'/Users/andyguo/Desktop/中文路径 测试.jpg'), u'/Users/andyguo/Desktop/中文路径 测试.jpg') self.assertEqual(DayuPath('D:/data/test.jpg'), 'd:/data/test.jpg') self.assertEqual(DayuPath('d:\\data\\test.jpg'), 'd:/data/test.jpg') self.assertEqual(DayuPath('D:\\data\\test.jpg'), 'd:/data/test.jpg') obj = DayuPath('/Users/andyguo/Desktop/111111111.jpg') self.assertIs(DayuPath(obj), obj)
def test_version(test_data): assert DayuPath(test_data['case']).version == test_data['result']
class TestDayuPath(TestCase): def test___new__(self): self.assertEqual(DayuPath(''), None) self.assertEqual(DayuPath([]), None) self.assertEqual(DayuPath(tuple()), None) self.assertEqual(DayuPath(set()), None) self.assertEqual(DayuPath(dict()), None) self.assertEqual(DayuPath('any_string'), 'any_string') self.assertEqual(DayuPath('/Users/andyguo/Desktop/111111111.jpg'), '/Users/andyguo/Desktop/111111111.jpg') self.assertEqual(DayuPath(u'/Users/andyguo/Desktop/中文路径 测试.jpg'), u'/Users/andyguo/Desktop/中文路径 测试.jpg') self.assertEqual(DayuPath('D:/data/test.jpg'), 'd:/data/test.jpg') self.assertEqual(DayuPath('d:\\data\\test.jpg'), 'd:/data/test.jpg') self.assertEqual(DayuPath('D:\\data\\test.jpg'), 'd:/data/test.jpg') obj = DayuPath('/Users/andyguo/Desktop/111111111.jpg') self.assertIs(DayuPath(obj), obj) def test_os_functions(self): path = DayuPath(self.mock_path).child( 'cam_test', 'A001C001_180212_RG8C.9876521.exr') self.assertIsNotNone(path.state()) self.assertIsNotNone(path.lstate()) self.assertIsNotNone(path.exists()) self.assertIsNotNone(path.lexists()) self.assertIsNotNone(path.isfile()) self.assertIsNotNone(path.isdir()) self.assertIsNotNone(path.islink()) self.assertIsNotNone(path.ismount()) self.assertIsNotNone(path.atime()) self.assertIsNotNone(path.ctime()) self.assertIsNotNone(path.mtime()) self.assertIsNotNone(path.size()) def test_frame(self): self.assertEqual(DayuPath('/Users/andyguo/Desktop/1.jpg').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/12.jpg').frame, 12) self.assertEqual( DayuPath('/Users/andyguo/Desktop/1001.jpg').frame, 1001) self.assertEqual(DayuPath('/Users/andyguo/Desktop/0024.jpg').frame, 24) self.assertEqual(DayuPath('/Users/andyguo/Desktop/1.mov').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/14.mov').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/123.mp4').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/v001.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/v002_999.jpg').frame, 999) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aaa_test.1.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aaa_test.12.jpg').frame, 12) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aaa_test.123.jpg').frame, 123) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aa_v001.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.012.jpg').frame, 12) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/pl_0010_plt_v0023_1234.jpg').frame, 1234) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.mov').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1023.jpg').frame, 1023) self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1023.MP4').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/test576bb.mov').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/test576bb.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/576_hkke.jpg').frame, -1) self.assertEqual( DayuPath(u'/Users/andyguo/Desktop/中文_1001.jpg').frame, 1001) self.assertEqual( DayuPath(u'/Users/andyguo/Desktop/中文 1001.jpg').frame, 1001) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/ttt/asdfasdf/pl_0010.1012.tiff').frame, 1012) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/ttt/asdfasdf/pl_0010.1012.mov').frame, -1) def test_pattern(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.jpg').pattern, None) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%d.jpg').pattern, '%d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%02d.jpg').pattern, '%02d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%03d.jpg').pattern, '%03d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_%04d.jpg').pattern, '%04d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_#.jpg').pattern, '#') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_##.jpg').pattern, '##') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_###.jpg').pattern, '###') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_####.jpg').pattern, '####') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F.jpg').pattern, '$F') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F2.jpg').pattern, '$F2') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F3.jpg').pattern, '$F3') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_$F4.jpg').pattern, '$F4') self.assertEqual( DayuPath(u'/Users/andyguo/Desktop/中文的测试$F4.jpg').pattern, '$F4') self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_%04d_ani_$F4.jpg').pattern, '%04d') self.assertEqual( DayuPath('/Users/andyguo/Desktop/ani_$F4.mov').pattern, '$F4') self.assertEqual( DayuPath('/Users/andyguo/Desktop/abc.mov').pattern, None) def test_to_pattern(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/1.jpg').to_pattern(), '/Users/andyguo/Desktop/1.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/11.jpg').to_pattern(), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/11.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/11.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/123.jpg').to_pattern(), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/123.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/123.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern(), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/1234.jpg').to_pattern('ss'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%02d.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%02d.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%02d.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%03d.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%03d.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%03d.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/%04d.jpg').to_pattern('1'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/##.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/##.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/##.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/###.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/###.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/###.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/####.jpg').to_pattern('f'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F2.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%02d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F2.jpg').to_pattern('#'), '/Users/andyguo/Desktop/##.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F2.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F2.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F3.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%03d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F3.jpg').to_pattern('#'), '/Users/andyguo/Desktop/###.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F3.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F3.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('%'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('#'), '/Users/andyguo/Desktop/####.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('$'), '/Users/andyguo/Desktop/$F4.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/$F4.jpg').to_pattern('dd'), '/Users/andyguo/Desktop/%04d.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.mov').to_pattern('%'), '/Users/andyguo/Desktop/MVI1001.mov') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.mov').to_pattern('#'), '/Users/andyguo/Desktop/MVI1001.mov') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.mov').to_pattern('$'), '/Users/andyguo/Desktop/MVI1001.mov') self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1001.MP4').to_pattern(), '/Users/andyguo/Desktop/MVI1001.MP4') def test_restore_pattern(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.12.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F2.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.12.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F3.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.012.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.$F4.jpg' ).restore_pattern(12), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0012.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%d.jpg' ).restore_pattern(1920), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1920.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%0d.jpg' ).restore_pattern(192), '/Users/andyguo/Desktop/sd_0010_plt_v0002.192.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%02d.jpg' ).restore_pattern(1920), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1920.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%03d.jpg' ).restore_pattern(1001), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1001.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%04d.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.#.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.##.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.###.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.####.jpg' ).restore_pattern(364), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0364.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.%04d.jpg' ).restore_pattern(0), '/Users/andyguo/Desktop/sd_0010_plt_v0002.0000.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg' ).restore_pattern(-1), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg' ).restore_pattern(2345), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg') self.assertEqual( DayuPath('/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg' ).restore_pattern(None), '/Users/andyguo/Desktop/sd_0010_plt_v0002.1234.jpg') def setUp(self): super(TestDayuPath, self).setUp() from uuid import uuid4 self.mock_path = DayuPath('~').expand_user().child(uuid4().hex) self.mock_path2 = DayuPath('~').expand_user().child(uuid4().hex) content_list = [ 'first_depth_0010.1001.dpx', 'first_depth_0010.1002.dpx', 'cam_test/A001C001_180212_RG8C.9876521.exr', 'cam_test/A001C001_180212_RG8C.9876522.exr', 'cam_test/A001C001_180212_RG8C.9876523.exr', 'vfx_test/pl_0010_plt_v0001.1001.exr', 'vfx_test/pl_0010_plt_v0001.1002.exr', 'vfx_test/pl_0010_plt_v0001.1003.exr', 'not_a_sequence/abc.exr', 'single_media_test/pl_0010_plt_v0001.1003.mov', 'single_media_test/MVI1022.MP4', u'single_media_test/测试中文.MP4', 'missing_test/dd_0090_ani_1001.jpg', 'missing_test/dd_0090_ani_1003.jpg', 'missing_test/dd_0090_ani_1005.jpg', 'ignore_test/._DS_store', 'ignore_test/..sdf', 'recursive_test/a_001.exr', 'recursive_test/a_002.exr', 'recursive_test/inside/b_100.exr', 'recursive_test/inside/b_101.exr', 'recursive_test/inside/b_102.exr', ] for x in content_list: file_path = DayuPath(u'{}/{}'.format(self.mock_path, x)) file_path.parent.mkdir(parents=True) with open(file_path, 'w') as f: f.write('1') self.mock_path.child('empty_folder', 'inside').mkdir(parents=True) def tearDown(self): super(TestDayuPath, self).tearDown() self.mock_path.rmtree() def test_scan(self): path = self.mock_path result = list(path.scan()) self.assertEqual(result[0], path.child('first_depth_0010.%04d.dpx')) self.assertEqual(result[0].frames, [1001, 1002]) self.assertEqual(result[0].missing, []) ground_truth_result = { path.child('first_depth_0010.%04d.dpx'): [[1001, 1002], []], path.child('cam_test', 'A001C001_180212_RG8C.%07d.exr'): [[9876521, 9876522, 9876523], []], path.child('vfx_test', 'pl_0010_plt_v0001.%04d.exr'): [[1001, 1002, 1003], []], path.child('not_a_sequence', 'abc.exr'): [[], []], path.child('single_media_test', 'pl_0010_plt_v0001.1003.mov'): [[], [] ], path.child('single_media_test', 'MVI1022.MP4'): [[], []], path.child(u'single_media_test', u'测试中文.MP4'): [[], []], path.child('missing_test', 'dd_0090_ani_%04d.jpg'): [[1001, 1003, 1005], [1002, 1004]], path.child('recursive_test', 'a_%03d.exr'): [[1, 2], []], path.child('recursive_test', 'inside', 'b_%03d.exr'): [[100, 101, 102], []], } ground_truth_result.update({ self.mock_path2.child('recursive_test', 'inside', 'b_%03d.exr'): [[100, 101, 102], []] }) print ground_truth_result.keys() for x in path.scan(recursive=True): if x: print x self.assertTrue(x in ground_truth_result.keys()) self.assertListEqual([x.frames, x.missing], ground_truth_result[x]) for x in self.mock_path2.scan(recursive=True): self.assertTrue(x in ground_truth_result.keys()) self.assertListEqual([x.frames, x.missing], ground_truth_result[x]) for x in path.child('vfx_test', 'pl_0010_plt_v0001.1001.exr').scan(): self.assertEqual( x, path.child('vfx_test', 'pl_0010_plt_v0001.%04d.exr')) self.assertEqual(x.frames, [1001, 1002, 1003]) self.assertEqual(x.missing, []) for x in path.child('missing_test').scan(): if x: self.assertEqual( x, path.child('missing_test', 'dd_0090_ani_%04d.jpg')) self.assertListEqual([x.frames, x.missing], ground_truth_result[x]) for x in path.child(u'single_media_test', u'测试中文.MP4').scan(): self.assertEqual(x, path.child(u'single_media_test', u'测试中文.MP4')) self.assertEqual(x.frames, []) self.assertEqual(x.missing, []) for x in path.child('not_a_sequence', 'abc.exr').scan(): self.assertEqual(x, path.child('not_a_sequence', 'abc.exr')) self.assertEqual(x.frames, []) self.assertEqual(x.missing, []) self.assertFalse( list(path.child('vfx_test', 'pl_0010_plt_v0002.1001.exr').scan())) self.assertFalse( list( path.child('vfx_test', 'pl_0010_plt_v0002.1001.exr').scan(recursive=True))) self.assertFalse(list(path.child('empty_folder').scan(recursive=True))) self.assertNotIn(path.child('ignore_test', '._DS_store'), [x for x in path.scan(recursive=True)]) self.assertNotIn(path.child('ignore_test', '..sdf'), [x for x in path.scan(recursive=True)]) self.assertNotIn(path.child('ignore_test', 'Thumbnail'), [x for x in path.scan(recursive=True)]) self.assertNotIn(path.child('ignore_test', 'temp.tmp'), [x for x in path.scan(recursive=True)]) def test_escape(self): legal_path = DayuPath('/Users/andyguo/Desktop/111.mov') self.assertEqual(legal_path.escape(), '/Users/andyguo/Desktop/111.mov') whitespace_path = DayuPath( '/Users/andyguo/Desktop/some words with space.mov') self.assertEqual( whitespace_path.escape(), '/Users/andyguo/Desktop/some\ words\ with\ space.mov') bash_string = DayuPath('The$!cat#&ran\"\'up()a|<>tree`;') self.assertEqual(bash_string.escape(), r'The\$\!cat\#\&ran\"\'up\(\)a\|\<\>tree\`\;') unicode_string = DayuPath( u'/Users/andyguo/Desktop/中文 和 空格12234 rer.jpg') self.assertEqual(unicode_string.escape(), u'/Users/andyguo/Desktop/中文\ 和\ 空格12234\ rer.jpg') def test_version(self): self.assertEqual( DayuPath('/Users/andyguo/Desktop/v001/111.mov').version, 'v001') self.assertEqual( DayuPath('/Users/andyguo/Desktop/V001/111.mov').version, 'V001') self.assertEqual( DayuPath('/Users/andyguo/Desktop/v001/A001C001_180212_DF3X.mov'). version, 'v001') self.assertEqual( DayuPath( '/Users/andyguo/Desktop/v003/pl_0010_plt_bga_v0002.1001.mov'). version, 'v0002') self.assertEqual( DayuPath( '/Users/andyguo/Desktop/dd/pl_0010_plt_bga.1001.mov').version, None) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/vv/pl_0010_plt_bga.1001.mov').version, None) self.assertEqual(DayuPath('not a path').version, None) @unittest.skip('only for mac local test') def test_root(self): self.assertEqual(DayuPath('/Users/andyguo/Desktop/abc.jpg').root, '/') self.assertEqual( DayuPath('/Volumes/filedata/td/finder.lnk').root, '/Volumes/filedata') self.assertIsInstance( DayuPath('/Volumes/filedata/td/finder.lnk').root, DayuPath) @unittest.skip('only for mac local test') def test_is_network(self): self.assertTrue(DayuPath('/Volumes/filedata/td/finder.lnk').is_network) self.assertFalse(DayuPath('/Users/andyguo/Desktop/log.txt').is_network) @unittest.skip('only for mac local test') def test_is_local(self): self.assertFalse(DayuPath('/Volumes/filedata/td/finder.lnk').is_local) self.assertTrue(DayuPath('/Users/andyguo/Desktop/log.txt').is_local)
def test_is_local(): assert not DayuPath('/Volumes/filedata/td/finder.lnk').is_local assert not DayuPath('/Users/andyguo/Desktop/log.txt').is_local
def test_frame(test_data): assert DayuPath(test_data['case']).frame == test_data['result']
def _set_path(self, value): path = DayuPath(value) for seq_obj in path.scan(): self.sequence_obj = seq_obj self._update_info()
def test_frame(self): self.assertEqual(DayuPath('/Users/andyguo/Desktop/1.jpg').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/12.jpg').frame, 12) self.assertEqual( DayuPath('/Users/andyguo/Desktop/1001.jpg').frame, 1001) self.assertEqual(DayuPath('/Users/andyguo/Desktop/0024.jpg').frame, 24) self.assertEqual(DayuPath('/Users/andyguo/Desktop/1.mov').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/14.mov').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/123.mp4').frame, -1) self.assertEqual(DayuPath('/Users/andyguo/Desktop/v001.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/v002_999.jpg').frame, 999) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aaa_test.1.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aaa_test.12.jpg').frame, 12) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aaa_test.123.jpg').frame, 123) self.assertEqual( DayuPath('/Users/andyguo/Desktop/aa_v001.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.012.jpg').frame, 12) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/pl_0010_plt_v0023_1234.jpg').frame, 1234) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/pl_0010_plt_v0023.mov').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1023.jpg').frame, 1023) self.assertEqual( DayuPath('/Users/andyguo/Desktop/MVI1023.MP4').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/test576bb.mov').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/test576bb.jpg').frame, -1) self.assertEqual( DayuPath('/Users/andyguo/Desktop/576_hkke.jpg').frame, -1) self.assertEqual( DayuPath(u'/Users/andyguo/Desktop/中文_1001.jpg').frame, 1001) self.assertEqual( DayuPath(u'/Users/andyguo/Desktop/中文 1001.jpg').frame, 1001) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/ttt/asdfasdf/pl_0010.1012.tiff').frame, 1012) self.assertEqual( DayuPath( '/Users/andyguo/Desktop/ttt/asdfasdf/pl_0010.1012.mov').frame, -1)