def test_lyric_filename_search_special_characters(self): """test '<' and/or '>' in name (not parsed (transparent to test))""" with self.lyric_filename_test_setup(no_config=True) as ts: path_variants = ['<oldskool>'] \ if is_windows() else [r'\<artist\>', r'\<artist>', r'<artist\>'] for path_variant in path_variants: ts['artist'] = path_variant + " SpongeBob SquarePants" parts = [ ts.root, ts["artist"] + " - " + ts["title"] + ".lyric" ] rpf = RootPathFile(ts.root, os.path.sep.join(parts)) if not rpf.valid: rpf = RootPathFile(rpf.root, rpf.pathfile_escaped) self.assertTrue(rpf.valid, "even escaped target file is not valid") with io.open(rpf.pathfile, "w", encoding='utf-8') as f: f.write(u"") search = ts.lyric_filename os.remove(rpf.pathfile) fp = rpf.pathfile if is_windows(): # account for 'os.path.normcase' santisatation fp = fp.lower() search = search.lower() # compensate for the above self.assertEqual(search, fp)
def test_lyric_filename_search_special_characters(self): """test '<' and/or '>' in name (not parsed (transparent to test))""" with self.lyric_filename_test_setup(no_config=True) as ts: path_variants = ['<oldskool>'] \ if is_windows() else [r'\<artist\>', r'\<artist>', r'<artist\>'] for path_variant in path_variants: ts['artist'] = path_variant + " SpongeBob SquarePants" parts = [ts.root, ts["artist"] + " - " + ts["title"] + ".lyric"] rpf = RootPathFile(ts.root, os.path.sep.join(parts)) if not rpf.valid: rpf = RootPathFile(rpf.root, rpf.pathfile_escaped) self.assertTrue(rpf.valid, "even escaped target file is not valid") with io.open(rpf.pathfile, "w", encoding='utf-8') as f: f.write(u"") search = ts.lyric_filename os.remove(rpf.pathfile) fp = rpf.pathfile if is_windows(): # account for 'os.path.normcase' santisatation fp = fp.lower() search = search.lower() # compensate for the above self.assertEqual(search, fp)
def test_lyric_filename_search_builtin_default_local_path(self): """test built-in default local path""" with self.lyric_filename_test_setup(no_config=True) as ts: fp = os.path.join(ts.root, ts["artist"] + " - " + ts["title"] + ".lyric") with io.open(fp, "w", encoding='utf-8') as f: f.write(u"") search = ts.lyric_filename os.remove(fp) if is_windows(): fp = fp.lower() # account for 'os.path.normcase' santisatation search = search.lower() # compensate for the above self.assertEqual(search, fp)
def test_lyric_filename_search_special_characters_across_path(self): """test '<' and/or '>' in name across path separator (not parsed (transparent to test))""" with self.lyric_filename_test_setup(no_config=True) as ts: # test '<' and '>' in name across path # (not parsed (transparent to test)) ts['artist'] = "a < b" ts['title'] = "b > a" parts = [ts.root, ts["artist"], ts["title"] + ".lyric"] rpf = RootPathFile(ts.root, os.path.sep.join(parts)) rootp = ts.root rmdirs = [] # ensure valid dir existence for p in rpf.end.split(os.path.sep)[:-1]: rootp = os.path.sep.join([ts.root, p]) if not RootPathFile(ts.root, rootp).valid: rootp = os.path.sep.join([ts.root, escape_filename(p)]) self.assertTrue( RootPathFile(ts.root, rootp).valid, "even escaped target dir part is not valid!") if not os.path.exists(rootp): mkdir(rootp) rmdirs.append(rootp) if not rpf.valid: rpf = RootPathFile(rpf.root, rpf.pathfile_escaped) with io.open(rpf.pathfile, "w", encoding='utf-8') as f: f.write(u"") # search for lyric file search = ts.lyric_filename # clean up test lyric file / path os.remove(rpf.pathfile) for p in rmdirs: os.rmdir(p) # test whether the 'found' file is the test lyric file fp = rpf.pathfile if is_windows(): fp = fp.lower() # account for 'os.path.normcase' santisatation search = search.lower() # compensate for the above self.assertEqual(search, fp)
def test_lyric_filename_search_special_characters_across_path(self): """test '<' and/or '>' in name across path separator (not parsed (transparent to test))""" with self.lyric_filename_test_setup(no_config=True) as ts: # test '<' and '>' in name across path # (not parsed (transparent to test)) ts['artist'] = "a < b" ts['title'] = "b > a" parts = [ts.root, ts["artist"], ts["title"] + ".lyric"] rpf = RootPathFile(ts.root, os.path.sep.join(parts)) rootp = ts.root rmdirs = [] # ensure valid dir existence for p in rpf.end.split(os.path.sep)[:-1]: rootp = os.path.sep.join([ts.root, p]) if not RootPathFile(ts.root, rootp).valid: rootp = os.path.sep.join([ts.root, escape_filename(p)]) self.assertTrue(RootPathFile(ts.root, rootp).valid, "even escaped target dir part is not valid!") if not os.path.exists(rootp): mkdir(rootp) rmdirs.append(rootp) if not rpf.valid: rpf = RootPathFile(rpf.root, rpf.pathfile_escaped) with io.open(rpf.pathfile, "w", encoding='utf-8') as f: f.write(u"") # search for lyric file search = ts.lyric_filename # clean up test lyric file / path os.remove(rpf.pathfile) for p in rmdirs: os.rmdir(p) # test whether the 'found' file is the test lyric file fp = rpf.pathfile if is_windows(): fp = fp.lower() # account for 'os.path.normcase' santisatation search = search.lower() # compensate for the above self.assertEqual(search, fp)
def expand_pathfile(rpf): """Return the expanded RootPathFile""" expanded = [] root = expanduser(rpf.root) pathfile = expanduser(rpf.pathfile) if rx_params.search(pathfile): root = expand_patterns(root).format(self) pathfile = expand_patterns(pathfile).format(self) rpf = RootPathFile(root, pathfile) expanded.append(rpf) if not os.path.exists(pathfile) and is_windows(): # prioritise a special character encoded version # # most 'alien' chars are supported for 'nix fs paths, and we # only pass the proposed path through 'escape_filename' (which # apparently doesn't respect case) if we don't care about case! # # FIX: assumes 'nix build used on a case-sensitive fs, nt case # insensitive. clearly this is not biting anyone though (yet!) pathfile = os.path.sep.join([rpf.root, rpf.end_escaped]) rpf = RootPathFile(rpf.root, pathfile) expanded.insert(len(expanded) - 1, rpf) return expanded