Пример #1
0
    def test_make_adapter_path(self, mock_abspath):

        mock_abspath.side_effect = lambda path: os.path.normpath(os.path.join('C:\\dir1\\dir2', path))  # Copied from ntpath.abspath.

        # Absolute root path.
        adapter = LocalAdapter(root='C:\\dir3\\dir4')
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), 'C:\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('local:dir5/dir6/file.json'), 'C:\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('local:file.json'), 'C:\\dir3\\dir4\\file.json')
        self.assertEqual(adapter.create_adapter_path('/dir5/dir6/file.json'), 'C:\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('file.json'), 'C:\\dir3\\dir4\\file.json')

        # Non-absolute root path.
        adapter = LocalAdapter(root='dir3/dir4')
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), 'C:\\dir1\\dir2\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('file.json'), 'C:\\dir1\\dir2\\dir3\\dir4\\file.json')

        # No root path.
        adapter = LocalAdapter()
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), 'C:\\dir1\\dir2\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('file.json'), 'C:\\dir1\\dir2\\file.json')
Пример #2
0
    def test_make_adapter_path(self, mock_abspath):

        mock_abspath.side_effect = lambda path: os.path.normpath(os.path.join('C:\\dir1\\dir2', path))  # Copied from ntpath.abspath.

        # Absolute root path.
        adapter = LocalAdapter(root='C:\\dir3\\dir4')
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), 'C:\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('local:dir5/dir6/file.json'), 'C:\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('local:file.json'), 'C:\\dir3\\dir4\\file.json')
        self.assertEqual(adapter.create_adapter_path('/dir5/dir6/file.json'), 'C:\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('file.json'), 'C:\\dir3\\dir4\\file.json')

        # Non-absolute root path.
        adapter = LocalAdapter(root='dir3/dir4')
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), 'C:\\dir1\\dir2\\dir3\\dir4\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('file.json'), 'C:\\dir1\\dir2\\dir3\\dir4\\file.json')

        # No root path.
        adapter = LocalAdapter()
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), 'C:\\dir1\\dir2\\dir5\\dir6\\file.json')
        self.assertEqual(adapter.create_adapter_path('file.json'), 'C:\\dir1\\dir2\\file.json')

        # Test that path with or without a leading slash returns the same result.
        adapter = LocalAdapter(root='C:/some/dir')
        path_with_leading_slash = adapter.create_adapter_path('/folder')
        path_without_leading_slash = adapter.create_adapter_path('folder')
        self.assertEqual(path_with_leading_slash, 'C:\\some\\dir\\folder')
        self.assertEqual(path_with_leading_slash, path_without_leading_slash)
Пример #3
0
    def test_make_adapter_path(self, mock_abspath):

        mock_abspath.side_effect = lambda path: os.path.normpath(os.path.join('/dir1', 'dir2', path))  # Copied from ntpath.abspath.

        # Absolute root path.
        adapter = LocalAdapter(root=os.path.join('/dir3', 'dir4'))
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), os.path.normpath(os.path.join('/dir3', 'dir4', 'dir5', 'dir6', 'file.json')))
        self.assertEqual(adapter.create_adapter_path('local:/file.json'), os.path.normpath(os.path.join('/dir3', 'dir4', 'file.json')))
        self.assertEqual(adapter.create_adapter_path('/dir5/dir6/file.json'), os.path.normpath(os.path.join('/dir3', 'dir4', 'dir5', 'dir6', 'file.json')))
        self.assertEqual(adapter.create_adapter_path('file.json'), os.path.normpath(os.path.join('/dir3', 'dir4', 'file.json')))

        # Non-absolute root path.
        adapter = LocalAdapter(root=os.path.join('dir3', 'dir4'))
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), os.path.normpath(os.path.join('/dir1', 'dir2', 'dir3', 'dir4', 'dir5', 'dir6', 'file.json')))
        self.assertEqual(adapter.create_adapter_path('file.json'), os.path.normpath(os.path.join('/dir1', 'dir2', 'dir3', 'dir4', 'file.json')))

        # No root path.
        adapter = LocalAdapter()
        self.assertEqual(adapter.create_adapter_path('local:/dir5/dir6/file.json'), os.path.normpath(os.path.join('/dir1', 'dir2', 'dir5', 'dir6', 'file.json')))
        self.assertEqual(adapter.create_adapter_path('file.json'), os.path.normpath(os.path.join('/dir1', 'dir2', 'file.json')))

        # Test that path with or without a leading slash returns the same result.
        adapter = LocalAdapter(root=os.path.join('/some', 'dir'))
        path_with_leading_slash = adapter.create_adapter_path('/folder')
        path_without_leading_slash = adapter.create_adapter_path('folder')
        self.assertEqual(path_with_leading_slash, os.path.normpath(os.path.join('/some', 'dir', 'folder')))
        self.assertEqual(path_with_leading_slash, path_without_leading_slash)

        # A null corpus path should return a null adapter path
        self.assertIsNone(adapter.create_adapter_path(None))