def test_move(self): # Moves to another folder self._fm.move(self._get_temp_path('f1.txt'), self._get_temp_path('subdir/')) self.assertEqual( sorted(self._fm.ls(self._get_temp_path('subdir')), key=lambda file: file.path), sorted([ File(path=self._get_temp_path('subdir/s1.txt'), size=self._S1_SIZE, mtime=self._S1_MTIME), File(path=self._get_temp_path('subdir/f1.txt'), size=self._F1_SIZE, mtime=self._F1_MTIME), ], key=lambda file: file.path)) # Renames self._fm.move(self._get_temp_path('f2.txt'), self._get_temp_path('f3.txt')) self.assertEqual(self._fm.ls(self._get_temp_path('f2.txt')), []) self.assertEqual(self._fm.ls(self._get_temp_path('f3.txt')), [ File(path=self._get_temp_path('f3.txt'), size=self._F2_SIZE, mtime=self._F2_MTIME) ])
def test_copy(self): self._fm.copy(self._get_temp_path('f1.txt'), self._get_temp_path('subdir')) self.assertEqual( self._fm.ls(self._get_temp_path('f1.txt')), [File(path=self._get_temp_path('f1.txt'), size=self.FILE_SIZE)]) self.assertEqual(self._fm.ls(self._get_temp_path('subdir/f1.txt')), [ File(path=self._get_temp_path('subdir/f1.txt'), size=self.FILE_SIZE) ])
def test_remove(self): self._fm.remove(self._get_temp_path('f1.txt')) self._fm.remove(self._get_temp_path('subdir')) self.assertEqual( self._fm.ls(self._get_temp_path(), recursive=True), [File(path=self._get_temp_path('f2.txt'), size=self.FILE_SIZE)])
def test_ls(self): mock_ls = MagicMock() self._mock_client.ls = mock_ls mock_ls.return_value = [ {'file_type': 'f', 'path': '/data/abc', 'length': 1024}, {'file_type': 'd', 'path': '/data', 'length': 1024} ] self.assertEqual( self._fm.ls('/data', recursive=True), [File(path='/data/abc', size=1024)] ) mock_ls.assert_called_once_with(['/data'], recurse=True)
def test_ls(self): # List file self.assertEqual( self._fm.ls(self._get_temp_path('f1.txt')), [File(path=self._get_temp_path('f1.txt'), size=self.FILE_SIZE)]) # List folder self.assertEqual( sorted(self._fm.ls(self._get_temp_path()), key=lambda file: file.path), sorted([ File(path=self._get_temp_path('f1.txt'), size=self.FILE_SIZE), File(path=self._get_temp_path('f2.txt'), size=self.FILE_SIZE) ], key=lambda file: file.path)) # List folder recursively self.assertEqual( sorted(self._fm.ls(self._get_temp_path(), recursive=True), key=lambda file: file.path), sorted([ File(path=self._get_temp_path('f1.txt'), size=self.FILE_SIZE), File(path=self._get_temp_path('f2.txt'), size=self.FILE_SIZE), File(path=self._get_temp_path('subdir/s1.txt'), size=self.FILE_SIZE), ], key=lambda file: file.path))
def test_ls(self): mock_ls = MagicMock() self._mock_client.get_file_info = mock_ls mock_ls.return_value = [ fs.FileInfo(type=fs.FileType.File, path='/data/abc', size=1024, mtime_ns=1367317325346000000), fs.FileInfo(type=fs.FileType.Directory, path='/data', size=1024, mtime_ns=1367317325346000000), ] self.assertEqual( self._fm.ls('hdfs:///data', recursive=True), [File(path='hdfs:///data/abc', size=1024, mtime=1367317325)]) mock_ls.assert_called_once()
def test_ls(self): mock_ls = MagicMock() self._mock_client.ls = mock_ls mock_ls.return_value = [{ 'file_type': 'f', 'path': '/data/abc', 'length': 1024, 'modification_time': 1367317325346 }, { 'file_type': 'd', 'path': '/data', 'length': 1024, 'modification_time': 1367317325346 }] self.assertEqual( self._fm.ls('hdfs:///data', recursive=True), [File(path='hdfs:///data/abc', size=1024, mtime=1367317325)]) mock_ls.assert_called_once_with(['/data'], recurse=True)