async def test_index_fix(self, app: App, mocker: MockerFixture): mocked_height = mocker.patch.object(FilePane, "_get_height") mocked_height.return_value = 10 app._left_pane._width = 10 app._left_pane._selected_file_index = -1 app._left_pane._files = [ File( name="hello", type=FileType.dir, info="", hidden=False, raw=Path(), index=0, ) ] await app._left_pane.filter_files() assert app._left_pane.file_count == 1 assert app._left_pane._get_formatted_files() == [ ("[SetCursorPosition]", ""), ("class:filepane.current_line class:filepane.dir", " \uf413 "), ("class:filepane.current_line class:filepane.dir", "hello"), ("class:filepane.current_line class:filepane.dir", " "), ("class:filepane.current_line class:filepane.dir", ""), ] assert app._left_pane._selected_file_index == 0 app._left_pane._selected_file_index = 2 app._left_pane._get_formatted_files() assert app._left_pane._selected_file_index == 0
async def patched_app(app: App, mocker: MockerFixture): mocked_height = mocker.patch.object(FilePane, "_get_height") mocked_height.return_value = 5 app._left_pane._files = [ File(name="%s" % i, type=i, info="", hidden=False, raw=Path(), index=i) for i in range(6) ] await app._left_pane.filter_files() yield app
def test_dir(self, app: App): assert (app._left_pane._get_file_info( File( name="Downloads", type=FileType.file, info="", hidden=False, index=0, raw=None, )) == ("class:filepane.file", " \uf74c ", "Downloads", ""))
def test_file(self, app: App): assert (app._left_pane._get_file_info( File( name="Hello", type=FileType.file, info="", hidden=False, index=0, raw=None, )) == ("class:filepane.file", " \uf4a5 ", "Hello", "")) assert (app._left_pane._get_file_info( File( name="Hello.js", type=FileType.file, info="", hidden=False, index=0, raw=None, )) == ("class:filepane.file", " \ue60c ", "Hello.js", ""))
async def test_cd(self, fs: FS, test_dirs): cwd = fs.path assert await fs.cd(Path(test_dirs[0])) == [ File(name="..", type=FileType.dir, info="", hidden=False, index=0, raw=None) ] assert fs.path == cwd.joinpath(test_dirs[0]).resolve() assert len(await fs.cd()) == 7
async def test_get_paths(self, fs: FS, test_dirs, test_files): assert await fs.get_paths() == [ File(name="..", type=FileType.dir, info="", hidden=False, index=0, raw=ANY), File(name="4xx/", type=FileType.dir, info="", hidden=False, index=1, raw=ANY), File(name="5xx/", type=FileType.dir, info="", hidden=False, index=2, raw=ANY), File( name=".6.txt", type=FileType.file, info="0 B", hidden=True, index=3, raw=ANY, ), File( name="1.txt", type=FileType.file, info="0 B", hidden=False, index=4, raw=ANY, ), File( name="2.txt", type=FileType.file, info="0 B", hidden=False, index=5, raw=ANY, ), File( name="3.txt", type=FileType.file, info="0 B", hidden=False, index=6, raw=ANY, ), ]
async def test_get_objects(self, mocker: MockerFixture): with Path(__file__).resolve().parent.joinpath( "../data/s3_list_objects.json").open("r") as file: response = json.load(file) patched_s3 = mocker.patch.object(S3, "_list_objects") patched_s3.return_value = response s3 = S3() s3._bucket_name = "bucket1" assert await s3._get_objects() == [ File(name="dir1/", type=FileType.dir, info="", hidden=False, index=0, raw=ANY), File( name="dir2/", type=FileType.dir, info="", hidden=False, index=1, raw=None, ), File( name="dir3/", type=FileType.dir, info="", hidden=False, index=2, raw=None, ), File( name=".file1", type=FileType.file, info="6.0 K", hidden=True, index=3, raw=ANY, ), File( name="file2", type=FileType.file, info="151.9 K", hidden=False, index=4, raw=ANY, ), File( name="file3", type=FileType.file, info="3.5 K", hidden=False, index=5, raw=ANY, ), ]
async def test_fileter_files(app: App): app._left_pane._files = [ File(name="%s" % i, type=i, info="", hidden=bool(i % 2), raw=Path(), index=i) for i in range(6) ] await app._left_pane.filter_files() assert app._left_pane.file_count == 6 app._left_pane._display_hidden = False await app._left_pane.filter_files() assert app._left_pane.file_count == 3
async def test_s3_backword(self, app: App, mocker: MockerFixture): mocked_cd = mocker.patch("s3fm.api.fs.S3.cd") mocked_cd.return_value = [ File(name="%s" % i, type=i, info="", hidden=False, raw=Path(), index=i) for i in range(2) ] assert app._left_pane._mode == PaneMode.s3 assert app._left_pane.file_count == 0 await app._left_pane.backword() assert app._left_pane.file_count == 2 mocked_cd.assert_called_once_with()
def test_line_process_bug(self, app: App): @app._left_pane._linemode.register def _(file): return ("hello", ) with pytest.raises(ClientError): app._left_pane._get_file_info( File( name="Downloads", type=FileType.link, info="", hidden=False, index=0, raw=None, ))
def test_line_process(self, app: App): @app._left_pane._linemode.register def _(file): return None @app._left_pane._linemode.register def _(file): return ("class:filepane.file", " ", file.name, file.info) assert (app._left_pane._get_file_info( File( name="Downloads", type=FileType.file, info="", hidden=False, index=0, raw=None, )) == ("class:filepane.file", " ", "Downloads", ""))
async def test_fs_forward(self, patched_app: App, mocker: MockerFixture): mocked_cd = mocker.patch("s3fm.api.fs.FS.cd") mocked_cd.return_value = [ File(name="%s" % i, type=i, info="", hidden=False, raw=Path(), index=i) for i in range(2) ] patched_app._left_pane._mode = PaneMode.fs await patched_app._left_pane.forward() mocked_cd.assert_not_called() assert patched_app._left_pane.file_count == 6 patched_app._left_pane._selected_file_index = 1 await patched_app._left_pane.forward() mocked_cd.assert_called_once_with(Path("1")) assert patched_app._left_pane.file_count == 2
async def test_fs(self, app: App, mocker: MockerFixture): mocked_fs = mocker.patch("s3fm.api.fs.FS.get_paths") mocked_fs.return_value = [ File(name="%s" % i, type=i, info="", hidden=False, raw=Path(), index=i) for i in range(6) ] app._left_pane._mode = PaneMode.fs assert app._left_pane.file_count == 0 await app._left_pane.load_data() assert app._left_pane.file_count == 6 app._left_pane._fs.path = Path("hello") mocked_fs.side_effect = lambda: exec("raise(Exception)") with pytest.raises(Exception): await app._left_pane.load_data() assert app._left_pane._fs.path == Path("")
async def test_get_buckets(self, mocker: MockerFixture): with Path(__file__).resolve().parent.joinpath( "../data/s3_list_buckets.json").open("r") as file: response = json.load(file) curr_time = datetime.now() for bucket in response["Buckets"]: bucket["CreationDate"] = curr_time patched_s3 = mocker.patch.object(S3, "_list_buckets") patched_s3.return_value = response s3 = S3() assert await s3._get_buckets() == [ File( name="bucket1/", type=FileType.bucket, info=str(curr_time), hidden=False, index=0, raw={ "Name": "bucket1", "CreationDate": curr_time }, ), File( name="bucket2/", type=FileType.bucket, info=str(curr_time), hidden=False, index=1, raw={ "Name": "bucket2", "CreationDate": curr_time }, ), File( name="bucket3/", type=FileType.bucket, info=str(curr_time), hidden=False, index=2, raw={ "Name": "bucket3", "CreationDate": curr_time }, ), File( name="bucket4/", type=FileType.bucket, info=str(curr_time), hidden=False, index=3, raw={ "Name": "bucket4", "CreationDate": curr_time }, ), File( name="bucket5/", type=FileType.bucket, info=str(curr_time), hidden=False, index=4, raw={ "Name": "bucket5", "CreationDate": curr_time }, ), ]