def test_local(self): with tempfile.TemporaryDirectory() as tempdir: tmp_filename = os.path.join(tempdir, 'QKDQXVOOME') src_file = os.path.join('futsu', 'test', 'test_storage_0.txt') self.assertFalse(storage.is_blob_exist(tmp_filename)) storage.local_to_path(tmp_filename, src_file) self.assertTrue(storage.is_blob_exist(tmp_filename)) self.assertFalse(fs.diff(tmp_filename, src_file)) storage.rm(tmp_filename) self.assertFalse(storage.is_blob_exist(tmp_filename)) tmp_filename = os.path.join(tempdir, 'NKNVMMYPUI') bytes0 = b'YENLUMVECW' storage.bytes_to_path(tmp_filename, bytes0) bytes1 = storage.path_to_bytes(tmp_filename) self.assertEqual(bytes0, bytes1) tmp_root_path = os.path.join(tempdir, 'BDHYVQKO') fs.makedirs(tmp_root_path) tmp_path_list = [ os.path.join(tmp_root_path, '{0}'.format(i)) for i in range(10) ] for tmp_path in tmp_path_list: storage.bytes_to_path(tmp_path, b'') ret_path_list = storage.find(tmp_root_path) ret_path_list = sorted(list(ret_path_list)) self.assertEqual(ret_path_list, tmp_path_list)
def test_makedirs(self): with tempfile.TemporaryDirectory() as tempdir: tmp_dirname = os.path.join(tempdir, 'JBMLJUBDTQ', 'TJLQSLRTJL') self.assertFalse(os.path.isdir(tmp_dirname)) fs.makedirs(tmp_dirname) self.assertTrue(os.path.isdir(tmp_dirname)) fs.makedirs(tmp_dirname) # test run 2 times self.assertTrue(os.path.isdir(tmp_dirname))
def test_is_exist(self): with tempfile.TemporaryDirectory() as tempdir: tmp_path = os.path.join(tempdir, 'XWYPDSVT') self.assertFalse(fs.is_exist(tmp_path)) fs.makedirs(tmp_path) self.assertTrue(fs.is_exist(tmp_path)) tmp_path = os.path.join(tempdir, 'MRAMKBJC') self.assertFalse(fs.is_exist(tmp_path)) fs.bytes_to_file(tmp_path, b'') self.assertTrue(fs.is_exist(tmp_path))
def test_is_file(self): with tempfile.TemporaryDirectory() as tempdir: tmp_path = os.path.join(tempdir, 'AMBLRDNO') self.assertFalse(fs.is_file(tmp_path)) fs.makedirs(tmp_path) self.assertFalse(fs.is_file(tmp_path)) tmp_path = os.path.join(tempdir, 'XCYMJDNI') self.assertFalse(fs.is_file(tmp_path)) fs.bytes_to_file(tmp_path, b'') self.assertTrue(fs.is_file(tmp_path))
def test_is_dir(self): with tempfile.TemporaryDirectory() as tempdir: tmp_path = os.path.join(tempdir, 'ELCAWJBE') self.assertFalse(fs.is_dir(tmp_path)) fs.makedirs(tmp_path) self.assertTrue(fs.is_dir(tmp_path)) tmp_path = os.path.join(tempdir, 'MATKBCNT') self.assertFalse(fs.is_dir(tmp_path)) fs.bytes_to_file(tmp_path, b'') self.assertFalse(fs.is_dir(tmp_path))
def test_rm_file(self): with tempfile.TemporaryDirectory() as tempdir: # rm not exist tmp_path = os.path.join(tempdir, 'DBSJBLOD') fs.rm_file(tmp_path) # rm dir tmp_path = os.path.join(tempdir, 'TXZGCGFO') fs.makedirs(tmp_path) self.assertRaises(ValueError, fs.rm_file, tmp_path) # rm file tmp_path = os.path.join(tempdir, 'NUFIPTJA') fs.bytes_to_file(tmp_path, b'') fs.rm_file(tmp_path) self.assertFalse(fs.is_file(tmp_path))
def test_rm_dir(self): with tempfile.TemporaryDirectory() as tempdir: # rm not exist tmp_path = os.path.join(tempdir, 'HYVPLFZA') fs.rm_dir(tmp_path) # rm dir tmp_path = os.path.join(tempdir, 'RLZIEDFY') fs.makedirs(tmp_path) fs.rm_dir(tmp_path) self.assertFalse(fs.is_dir(tmp_path)) # rm file tmp_path = os.path.join(tempdir, 'KQDGCKDS') fs.bytes_to_file(tmp_path, b'') self.assertRaises(ValueError, fs.rm_dir, tmp_path)
def test_rm(self): with tempfile.TemporaryDirectory() as tempdir: # rm not exist tmp_path = os.path.join(tempdir, 'UFIUJLKN') fs.rm_file(tmp_path) # rm dir tmp_path = os.path.join(tempdir, 'JMGSKISO') fs.makedirs(tmp_path) fs.rm_dir(tmp_path) self.assertFalse(fs.is_dir(tmp_path)) # rm file tmp_path = os.path.join(tempdir, 'RNNUTMLB') fs.bytes_to_file(tmp_path, b'') fs.rm_file(tmp_path) self.assertFalse(fs.is_file(tmp_path))