From 3a1b1918fb1ce008325e41550a0b9f659498a6e2 Mon Sep 17 00:00:00 2001 From: pryce-turner Date: Tue, 18 Jun 2024 15:12:57 -0700 Subject: [PATCH 1/2] Made FlyteFile.new_remote_file use name arg Signed-off-by: pryce-turner --- flytekit/types/file/file.py | 2 +- tests/flytekit/unit/core/test_flyte_file.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/flytekit/types/file/file.py b/flytekit/types/file/file.py index 8561ec0157..15113f8f01 100644 --- a/flytekit/types/file/file.py +++ b/flytekit/types/file/file.py @@ -153,7 +153,7 @@ def new_remote_file(cls, name: typing.Optional[str] = None) -> FlyteFile: Create a new FlyteFile object with a remote path. """ ctx = FlyteContextManager.current_context() - r = ctx.file_access.get_random_string() + r = name or ctx.file_access.get_random_string() remote_path = ctx.file_access.join(ctx.file_access.raw_output_prefix, r) return cls(path=remote_path) diff --git a/tests/flytekit/unit/core/test_flyte_file.py b/tests/flytekit/unit/core/test_flyte_file.py index 33a796b875..da0eeba35f 100644 --- a/tests/flytekit/unit/core/test_flyte_file.py +++ b/tests/flytekit/unit/core/test_flyte_file.py @@ -678,3 +678,9 @@ def test_join(): def test_headers(): assert FlyteFilePathTransformer.get_additional_headers("xyz") == {} assert len(FlyteFilePathTransformer.get_additional_headers(".gz")) == 1 + + +def test_new_remote_file(): + nf = FlyteFile.new_remote_file(name="foo") + assert isinstance(nf, FlyteFile) + assert nf.path.endswith('foo') From a0e05577f27deac5d6032cc2898b3d03b4836243 Mon Sep 17 00:00:00 2001 From: pryce-turner Date: Tue, 18 Jun 2024 15:41:33 -0700 Subject: [PATCH 2/2] Added fname extension to better match real world Signed-off-by: pryce-turner --- tests/flytekit/unit/core/test_flyte_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/flytekit/unit/core/test_flyte_file.py b/tests/flytekit/unit/core/test_flyte_file.py index da0eeba35f..ff038c164b 100644 --- a/tests/flytekit/unit/core/test_flyte_file.py +++ b/tests/flytekit/unit/core/test_flyte_file.py @@ -681,6 +681,6 @@ def test_headers(): def test_new_remote_file(): - nf = FlyteFile.new_remote_file(name="foo") + nf = FlyteFile.new_remote_file(name="foo.txt") assert isinstance(nf, FlyteFile) - assert nf.path.endswith('foo') + assert nf.path.endswith('foo.txt')