def test_pathto_w_slash(self): before = Path('/a/b/') after = Path('/a/b/c') self.assertEqual(before.get_pathto(after), 'c') before = Path('u/a/\u03A0/') after = Path('u/a/\u03A0/c') self.assertEqual(before.get_pathto(after), u'c')
class PathComparisonTestCase(unittest.TestCase): def setUp(self): self.path_wo_slash = Path('/a/b/c') self.path_w_slash = Path('/a/b/c/') self.wo_to_w = self.path_wo_slash.get_pathto(self.path_w_slash) self.conversion = str ######################################################################### # Comparing Path objects def test_with_eq_without_trailing_slash(self): """A path is not the same with a trailing slash.""" self.assertNotEqual(self.path_wo_slash, self.path_w_slash) def test_wo_to_w_eq_path_dot(self): """The path to the same with a trailing slash returns Path('.').""" self.assertEqual(self.wo_to_w, Path('.')) ######################################################################### # Comparing with string conversions. def test_path_wo_slash_eq_string(self): """A path without trailing slash equals its string conversion.""" self.assertEqual(self.path_wo_slash, self.conversion(self.path_wo_slash)) def test_path_w_slash_eq_string(self): """A path with trailing slash equals its string conversion.""" self.assertEqual(self.path_w_slash, self.conversion(self.path_w_slash)) def test_path_to_similar_eq_string_dot(self): """The path to the same with a trailing slash equals '.'.""" self.assertEqual(self.wo_to_w, '.') def test_absolute(self): self.assert_(self.path_w_slash.is_absolute()) self.assert_(self.path_wo_slash.is_absolute())
def test1(self): a = Path('/a/b/c') b = Path('/a/b/d/e') self.assertEqual(a.get_prefix(b), '/a/b') a = Path(u'/a/\u03A0/c') b = Path(u'/a/\u03A0/d/e') self.assertEqual(a.get_prefix(b), u'/a/\u03A0')
def test_resolve2_w_slash(self): before = Path('/a/b/') after = Path('/a/b/c') self.assertEqual(before.resolve2('c'), after) before = Path(u'/a/b/') after = Path(u'/a/b/\u03A0') self.assertEqual(before.resolve2(u'\u03A0'), after)
def test_resolve_wo_slash(self): before = Path('/a/b') after = Path('/a/c') self.assertEqual(before.resolve('c'), after) before = Path(u'/a/b') after = Path(u'/a/\u03A0') self.assertEqual(before.resolve(u'\u03A0'), after)
def test_absnorm(self): """ Test the normalization '/..' = '/' """ path = Path('/../../a/b/c') self.assertEqual(str(path), '/a/b/c') self.assert_(path.is_absolute()) path = Path(u'/../../a/b/c') self.assertEqual(unicode(path), u'/a/b/c') self.assert_(path.is_absolute())
def test_backnorm(self): """ Test the normalization 'a/../b' = 'b' """ path = Path('a/b/c/../d') self.assertEqual(str(path), 'a/b/d') self.assert_(path.is_relative()) path = Path(u'a/b/c/../d') self.assertEqual(unicode(path), u'a/b/d') self.assert_(path.is_relative())
def test_relnorm(self): """ Check that '../' = '../' """ path = Path('../../a//.//b/c') self.assertEqual(str(path), '../../a/b/c') self.assert_(path.is_relative()) path = Path(u'../../a//.//b\u03A0\u03A3\u03A9/c') self.assertEqual(path, u'../../a/b\u03A0\u03A3\u03A9/c') self.assert_(path.is_relative())
def test_simplenorm(self): """ Test the simple path normalization: - 'a/./b' = 'a/b' - 'a//b' = 'a/b' - './a' = 'a' - 'a/' = 'a' """ path = Path('./a/./b//c/') self.assertEqual(str(path), 'a/b/c/') self.assert_(path.is_relative()) path = Path(u'./a/./b//c/') self.assertEqual(unicode(path), u'a/b/c/') self.assert_(path.is_relative())
class UnicodePathComparisonTestCase(PathComparisonTestCase): def setUp(self): self.path_wo_slash = Path(u'/a/\u03A0/c') self.path_w_slash = Path(u'/a/\u03A0/c/') self.wo_to_w = self.path_wo_slash.get_pathto(self.path_w_slash) self.conversion = unicode
def test_windows_absolute(self): # Note that there is no such thing as a windows relative path when a # drive letter is also specified. path = Path(u'c:/a/b/c') self.assert_(path.is_absolute()) self.assert_(not path.is_relative()) path = Path(u'c:a/b/c') self.assert_(path.is_absolute()) self.assert_(not path.is_relative())
def setUp(self): self.path_wo_slash = Path('/a/b/c') self.path_w_slash = Path('/a/b/c/') self.wo_to_w = self.path_wo_slash.get_pathto(self.path_w_slash) self.conversion = str
def test3(self): a = Path('/a/b') self.assertEqual(a.get_pathtoroot(), '../') a = Path(u'/a/b') self.assertEqual(a.get_pathtoroot(), u'../')
def test5(self): a = Path('/a/very/long/path') self.assertEqual(a.get_pathtoroot(), '../../../') a = Path(u'/a/very/long/path') self.assertEqual(a.get_pathtoroot(), u'../../../')
def test7(self): a = Path('a/b/') self.assertEqual(a.get_pathtoroot(), '../') a = Path(u'a/b/') self.assertEqual(a.get_pathtoroot(), u'../')
def setUp(self): self.path_wo_slash = Path(u'/a/\u03A0/c') self.path_w_slash = Path(u'/a/\u03A0/c/') self.wo_to_w = self.path_wo_slash.get_pathto(self.path_w_slash) self.conversion = unicode
def test2(self): a = Path('/a/') self.assertEqual(a.get_pathtoroot(), '') a = Path(u'/a/') self.assertEqual(a.get_pathtoroot(), u'')
def test_relative(self): path = Path(u'a/b/c') self.assert_(not path.is_absolute()) self.assert_(path.is_relative())
def test_wo_to_w_eq_path_dot(self): """The path to the same with a trailing slash returns Path('.').""" self.assertEqual(self.wo_to_w, Path('.'))