def test_converter(self): converter = dispatch._create_path_to_resource_converter('/a/b') # Python built by MSC inserts a drive name like 'C:\' via realpath(). # Converter Generator expands provided path using realpath() and uses # the path including a drive name to verify the prefix. os_root = os.path.realpath('/') self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py')) self.assertEqual('/c/h', converter(os_root + 'a/b/c/h_wsh.py')) self.assertEqual(None, converter(os_root + 'a/b/h.py')) self.assertEqual(None, converter('a/b/h_wsh.py')) converter = dispatch._create_path_to_resource_converter('a/b') self.assertEqual('/h', converter(dispatch._normalize_path('a/b/h_wsh.py'))) converter = dispatch._create_path_to_resource_converter('/a/b///') self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py')) self.assertEqual( '/h', converter(dispatch._normalize_path('/a/b/../b/h_wsh.py'))) converter = dispatch._create_path_to_resource_converter( '/a/../a/b/../b/') self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py')) converter = dispatch._create_path_to_resource_converter(r'\a\b') self.assertEqual('/h', converter(os_root + r'a\b\h_wsh.py')) self.assertEqual('/h', converter(os_root + r'a/b/h_wsh.py'))
def test_converter(self): converter = dispatch._create_path_to_resource_converter('/a/b') # Python built by MSC inserts a drive name like 'C:\' via realpath(). # Converter Generator expands provided path using realpath() and uses # the path including a drive name to verify the prefix. os_root = os.path.realpath('/') self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py')) self.assertEqual('/c/h', converter(os_root + 'a/b/c/h_wsh.py')) self.assertEqual(None, converter(os_root + 'a/b/h.py')) self.assertEqual(None, converter('a/b/h_wsh.py')) converter = dispatch._create_path_to_resource_converter('a/b') self.assertEqual('/h', converter(dispatch._normalize_path( 'a/b/h_wsh.py'))) converter = dispatch._create_path_to_resource_converter('/a/b///') self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py')) self.assertEqual('/h', converter(dispatch._normalize_path( '/a/b/../b/h_wsh.py'))) converter = dispatch._create_path_to_resource_converter( '/a/../a/b/../b/') self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py')) converter = dispatch._create_path_to_resource_converter(r'\a\b') self.assertEqual('/h', converter(os_root + r'a\b\h_wsh.py')) self.assertEqual('/h', converter(os_root + r'a/b/h_wsh.py'))
def test_normalize_path(self): self.assertEqual(os.path.abspath('/a/b').replace('\\', '/'), dispatch._normalize_path('/a/b')) self.assertEqual(os.path.abspath('/a/b').replace('\\', '/'), dispatch._normalize_path('\\a\\b')) self.assertEqual(os.path.abspath('/a/b').replace('\\', '/'), dispatch._normalize_path('/a/c/../b')) self.assertEqual(os.path.abspath('abc').replace('\\', '/'), dispatch._normalize_path('abc'))