def test_filepath (self): test_order = self.test_cases[0][1:] for test_case in self.test_cases[1:]: path, rest = test_case[0], test_case[1:] fp = fs.filepath (path) for n, test_item in enumerate (test_order): result = rest[n] if result.startswith ("x_"): exc = getattr (fs, result) try: getattr (fp, test_item) except exc: pass else: raise RuntimeError ( "Path: %s; Part: %s; expected exception %s" % (path, test_item, result) ) else: if result == "_": result = "" self.assertEquals ( result, getattr (fp, test_item), "Path: %s; Part %s; expected: %s; result: %s" % (path, test_item, result, getattr (fp, test_item)) )
def test_is_relative (self): for path, result in [ ("c:/", False), ("c:/temp/abc.txt", False), ("temp", True), ("c:temp", True), (r"\\server\share", False), (r"\\server\share\d1", False) ]: self.assertEquals (fs.filepath (path).is_relative (), result)
def test_filepath(self): test_order = self.test_cases[0][1:] for test_case in self.test_cases[1:]: path, rest = test_case[0], test_case[1:] fp = fs.filepath(path) for n, test_item in enumerate(test_order): result = rest[n] if result.startswith("x_"): exc = getattr(fs, result) try: getattr(fp, test_item) except exc: pass else: raise RuntimeError( "Path: %s; Part: %s; expected exception %s" % (path, test_item, result)) else: if result == "_": result = "" self.assertEquals( result, getattr(fp, test_item), "Path: %s; Part %s; expected: %s; result: %s" % (path, test_item, result, getattr(fp, test_item)))
def test_dump_absolute(self): with utils.fake_stdout(): fs.filepath(__file__).dump()
def test_radd (self): for l in self.left: for r in self.right: self.assertEquals (l + fs.filepath (r), os.path.join (l, r))
def test_changed_filename(self): self.assertEquals( fs.filepath("c:\\temp\\abc.txt").changed(filename="def.ghi"), "c:\\temp\\def.ghi")
def test_changed_infix(self): self.assertEquals( fs.filepath("c:\\temp\\abc.txt").changed(infix=".infix"), "c:\\temp\\abc.infix.txt")
def test_changed_filename_and_ext(self): with self.assertRaises(fs.x_fs): fs.filepath(".").changed(filename="test.txt", ext=".txt")
def test_changed_root(self): self.assertEquals( fs.filepath("c:\\temp\\abc.txt").changed(root="d:\\"), "d:\\temp\\abc.txt")
def test_add(self): for l in self.left: for r in self.right: self.assertEquals(fs.filepath(l) + r, os.path.join(l, r))
def test_changed_filename_and_ext (self): with self.assertRaises (fs.x_fs): fs.filepath (".").changed (filename="test.txt", ext=".txt")
def test_changed_filename (self): self.assertEquals (fs.filepath ("c:\\temp\\abc.txt").changed (filename="def.ghi"), "c:\\temp\\def.ghi")
def test_changed_base (self): self.assertEquals (fs.filepath ("c:\\temp\\abc.txt").changed (base="def"), "c:\\temp\\def.txt")
def test_changed_dirname (self): self.assertEquals (fs.filepath ("c:\\temp\\abc.txt").changed (dirname="temp2"), "c:\\temp2\\abc.txt")
def test_changed_root (self): self.assertEquals (fs.filepath ("c:\\temp\\abc.txt").changed (root="d:\\"), "d:\\temp\\abc.txt")
def test_changed_filename_and_infix (self): with self.assertRaises (fs.x_fs): fs.filepath (".").changed (filename="test.txt", infix="-test-")
def test_dump_relative(): fs.filepath("@@").dump()
def test_is_relative(self): for path, result in [("c:/", False), ("c:/temp/abc.txt", False), ("temp", True), ("c:temp", True), (r"\\server\share", False), (r"\\server\share\d1", False)]: self.assertEquals(fs.filepath(path).is_relative(), result)
def test_changed_infix (self): self.assertEquals (fs.filepath ("c:\\temp\\abc.txt").changed (infix=".infix"), "c:\\temp\\abc.infix.txt")
def test_absolute (self): for path in ["c:/temp", "temp", "c:temp", r"\\server\share\d1"]: self.assertEquals (fs.filepath (path).absolute ().lower (), os.path.abspath (path).lower ())
def test_radd(self): for l in self.left: for r in self.right: self.assertEquals(l + fs.filepath(r), os.path.join(l, r))
def test_changed_ext (self): self.assertEquals (fs.filepath ("c:\\temp\\abc.txt").changed (ext=".ext"), "c:\\temp\\abc.ext")
def test_absolute(self): for path in ["c:/temp", "temp", "c:temp", r"\\server\share\d1"]: self.assertEquals( fs.filepath(path).absolute().lower(), os.path.abspath(path).lower())
def test_dump_absolute (self): with utils.fake_stdout (): fs.filepath (__file__).dump ()
def test_changed_filename_and_infix(self): with self.assertRaises(fs.x_fs): fs.filepath(".").changed(filename="test.txt", infix="-test-")
def test_dump_relative (self): with utils.fake_stdout (): fs.filepath ("@@").dump ()
def test_changed_dirname(self): self.assertEquals( fs.filepath("c:\\temp\\abc.txt").changed(dirname="temp2"), "c:\\temp2\\abc.txt")
def test_changed_base(self): self.assertEquals( fs.filepath("c:\\temp\\abc.txt").changed(base="def"), "c:\\temp\\def.txt")
def test_dump_absolute(): fs.filepath(__file__).dump()
def test_changed_ext(self): self.assertEquals( fs.filepath("c:\\temp\\abc.txt").changed(ext=".ext"), "c:\\temp\\abc.ext")
def test_dump_relative(self): with utils.fake_stdout(): fs.filepath("@@").dump()
def test_add (self): for l in self.left: for r in self.right: self.assertEquals (fs.filepath (l) + r, os.path.join (l, r))