def test_get_local_filesystem(tmp_path): filesystem = get_filesystem(tmp_path) assert isinstance(filesystem, OSFS) subfolder_path = os.path.join(tmp_path, "subfolder") with pytest.raises(CreateFailed): assert get_filesystem(subfolder_path, create=False) filesystem = get_filesystem(subfolder_path, create=True) assert isinstance(filesystem, OSFS)
def test_get_local_filesystem(self): with tempfile.TemporaryDirectory() as tmp_dir_name: filesystem = get_filesystem(tmp_dir_name) self.assertTrue(isinstance(filesystem, OSFS)) subfolder_path = fs.path.combine(tmp_dir_name, 'subfolder') with self.assertRaises(CreateFailed): get_filesystem(subfolder_path, create=False) filesystem = get_filesystem(subfolder_path, create=True) self.assertTrue(isinstance(filesystem, OSFS))
def test_s3_filesystem(self): folder_name = 'my_folder' s3_url = 's3://test-eo-bucket/{}'.format(folder_name) filesystem = get_filesystem(s3_url) self.assertTrue(isinstance(filesystem, S3FS)) self.assertEqual(filesystem.dir_path, folder_name) custom_config = SHConfig() custom_config.aws_access_key_id = 'fake-key' custom_config.aws_secret_access_key = 'fake-secret' filesystem1 = load_s3_filesystem(s3_url, strict=False, config=custom_config) filesystem2 = get_filesystem(s3_url, config=custom_config) for filesystem in [filesystem1, filesystem2]: self.assertTrue(isinstance(filesystem, S3FS)) self.assertEqual(filesystem.aws_access_key_id, custom_config.aws_access_key_id) self.assertEqual(filesystem.aws_secret_access_key, custom_config.aws_secret_access_key)
def test_s3_filesystem(aws_session_token): folder_name = "my_folder" s3_url = f"s3://test-eo-bucket/{folder_name}" filesystem = get_filesystem(s3_url) assert isinstance(filesystem, S3FS) assert filesystem.dir_path == folder_name custom_config = SHConfig() custom_config.aws_access_key_id = "fake-key" custom_config.aws_secret_access_key = "fake-secret" custom_config.aws_session_token = aws_session_token filesystem1 = load_s3_filesystem(s3_url, strict=False, config=custom_config) filesystem2 = get_filesystem(s3_url, config=custom_config) for filesystem in [filesystem1, filesystem2]: assert isinstance(filesystem, S3FS) assert filesystem.aws_access_key_id == custom_config.aws_access_key_id assert filesystem.aws_secret_access_key == custom_config.aws_secret_access_key assert filesystem.aws_session_token == aws_session_token
def test_pathlib_support(self): with tempfile.TemporaryDirectory() as tmp_dir_name: path = Path(tmp_dir_name) filesystem = get_filesystem(path) self.assertTrue(isinstance(filesystem, OSFS))
def test_pathlib_support(tmp_path): path = Path(tmp_path) filesystem = get_filesystem(path) assert isinstance(filesystem, OSFS)