def test__4_1(self): ''' Verify normalize() result when input is absolute path ''' self.assertEqual(utils_path.normalize('/foo/bar/../baz'), ''.join([os.sep, 'foo', os.sep, 'baz'])) self.assertEqual(utils_path.normalize('/foo/bar/../../baz'), ''.join([os.sep, 'baz'])) self.assertEqual(utils_path.normalize('/foo/bar/../../../baz'), ''.join([os.sep, 'baz'])) self.assertEqual(utils_path.normalize('/foo/bar/../../../../baz'), ''.join([os.sep, 'baz']))
def test__4_2__and__4_3(self): ''' Verify normalize() result when input is relative path ''' # 4.2 the starting node is the parent of foo self.assertEqual(utils_path.normalize('foo/bar/../baz'), os.sep.join(['foo', 'baz'])) self.assertEqual(utils_path.normalize('foo/bar/../../baz'), 'baz') # 4.3 the starting node is ABOVE the parent of foo self.assertEqual(utils_path.normalize('foo/bar/../../../baz'), os.sep.join(['..', 'baz'])) self.assertEqual(utils_path.normalize('foo/bar/../../../../baz'), os.sep.join(['..', '..', 'baz']))
def test__3(self): ''' Make sure that normalize() converts / to \\ on windows ''' if os.name == 'nt': self.assertEqual(utils_path.normalize('foo/bar'), r'foo\bar')
def test__2(self): ''' Make sure that normalize() simplifies redundant up-level refs ''' self.assertEqual(utils_path.normalize('/foo/bar/../baz'), os.sep.join(['', 'foo', 'baz']))
def test__1(self): ''' Make sure that normalize() collapses multiple slashes ''' self.assertEqual(utils_path.normalize('/foo////bar'), os.sep.join(['', 'foo', 'bar']))