Example #1
0
 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')
Example #2
0
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())
Example #3
0
 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')
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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())
Example #7
0
 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())
Example #8
0
 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())
Example #9
0
 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)
Example #10
0
 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')
Example #11
0
 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')
Example #12
0
 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)
Example #13
0
    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())
Example #14
0
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
Example #15
0
 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())
Example #16
0
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())
Example #17
0
 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())
Example #18
0
 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())
Example #19
0
 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())
Example #20
0
 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())
Example #21
0
    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())
Example #22
0
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
Example #23
0
 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
Example #24
0
 def test3(self):
     a = Path('/a/b')
     self.assertEqual(a.get_pathtoroot(), '../')
     a = Path(u'/a/b')
     self.assertEqual(a.get_pathtoroot(), u'../')
Example #25
0
 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'../../../')
Example #26
0
 def test7(self):
     a = Path('a/b/')
     self.assertEqual(a.get_pathtoroot(), '../')
     a = Path(u'a/b/')
     self.assertEqual(a.get_pathtoroot(), u'../')
Example #27
0
 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
Example #28
0
 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
Example #29
0
 def test2(self):
     a = Path('/a/')
     self.assertEqual(a.get_pathtoroot(), '')
     a = Path(u'/a/')
     self.assertEqual(a.get_pathtoroot(), u'')
Example #30
0
 def test_relative(self):
     path = Path(u'a/b/c')
     self.assert_(not path.is_absolute())
     self.assert_(path.is_relative())
Example #31
0
 def test3(self):
     a = Path('/a/b')
     self.assertEqual(a.get_pathtoroot(), '../')
     a = Path(u'/a/b')
     self.assertEqual(a.get_pathtoroot(), u'../')
Example #32
0
 def test2(self):
     a = Path('/a/')
     self.assertEqual(a.get_pathtoroot(), '')
     a = Path(u'/a/')
     self.assertEqual(a.get_pathtoroot(), u'')
Example #33
0
 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'../../../')
Example #34
0
 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('.'))
Example #35
0
 def test7(self):
     a = Path('a/b/')
     self.assertEqual(a.get_pathtoroot(), '../')
     a = Path(u'a/b/')
     self.assertEqual(a.get_pathtoroot(), u'../')
Example #36
0
 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
Example #37
0
 def test_relative(self):
     path = Path(u'a/b/c')
     self.assert_(not path.is_absolute())
     self.assert_(path.is_relative())