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 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 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_relative(self): path = Path(u'a/b/c') self.assert_(not path.is_absolute()) self.assert_(path.is_relative())