Beispiel #1
0
def test_dont_convert_remotes():
    @task
    def t1(in1: FlyteFile):
        print(in1)

    @dynamic
    def dyn(in1: FlyteFile):
        t1(in1=in1)

    fd = FlyteFile("s3://anything")

    with context_manager.FlyteContext.current_context(
    ).new_serialization_settings(
            serialization_settings=context_manager.SerializationSettings(
                project="test_proj",
                domain="test_domain",
                version="abc",
                image_config=ImageConfig(
                    Image(name="name", fqn="image", tag="name")),
                env={},
            )) as ctx:
        with ctx.new_execution_context(
                mode=ExecutionState.Mode.TASK_EXECUTION) as ctx:
            lit = TypeEngine.to_literal(
                ctx, fd, FlyteFile,
                BlobType("",
                         dimensionality=BlobType.BlobDimensionality.SINGLE))
            lm = LiteralMap(literals={"in1": lit})
            wf = dyn.dispatch_execute(ctx, lm)
            assert wf.nodes[0].inputs[
                0].binding.scalar.blob.uri == "s3://anything"
def test_filepath_equality():
    a = FlyteFile("/tmp")
    b = FlyteFile("/tmp")
    assert str(b) == "/tmp"
    assert a == b

    a = FlyteFile("/tmp")
    b = FlyteFile["pdf"]("/tmp")
    assert a != b

    a = FlyteFile("/tmp")
    b = FlyteFile("/tmp/c")
    assert a != b

    x = "jpg"
    y = ".jpg"
    a = FlyteFile[x]("/tmp")
    b = FlyteFile[y]("/tmp")
    assert a == b
Beispiel #3
0
def test_download_caching():
    mock_downloader = MagicMock()
    f = FlyteFile("test", mock_downloader)
    assert not f.downloaded
    os.fspath(f)
    assert f.downloaded
    assert mock_downloader.call_count == 1
    for _ in range(10):
        os.fspath(f)
    assert mock_downloader.call_count == 1
Beispiel #4
0
def test_dont_convert_remotes():
    @task
    def t1(in1: FlyteFile):
        print(in1)

    @dynamic
    def dyn(in1: FlyteFile):
        t1(in1=in1)

    fd = FlyteFile("s3://anything")

    with context_manager.FlyteContextManager.with_context(
        context_manager.FlyteContextManager.current_context().with_serialization_settings(
            flytekit.configuration.SerializationSettings(
                project="test_proj",
                domain="test_domain",
                version="abc",
                image_config=ImageConfig(Image(name="name", fqn="image", tag="name")),
                env={},
            )
        )
    ):
        ctx = context_manager.FlyteContextManager.current_context()
        with context_manager.FlyteContextManager.with_context(
            ctx.with_execution_state(ctx.new_execution_state().with_params(mode=ExecutionState.Mode.TASK_EXECUTION))
        ) as ctx:
            lit = TypeEngine.to_literal(
                ctx, fd, FlyteFile, BlobType("", dimensionality=BlobType.BlobDimensionality.SINGLE)
            )
            lm = LiteralMap(literals={"in1": lit})
            wf = dyn.dispatch_execute(ctx, lm)
            assert wf.nodes[0].inputs[0].binding.scalar.blob.uri == "s3://anything"

            with pytest.raises(TypeError, match="No automatic conversion found from type <class 'int'>"):
                TypeEngine.to_literal(
                    ctx, 3, FlyteFile, BlobType("", dimensionality=BlobType.BlobDimensionality.SINGLE)
                )
Beispiel #5
0
 def t1() -> FlyteFile:
     # Use this test file itself, since we know it exists.
     return FlyteFile(__file__, remote_path=False)
Beispiel #6
0
 def t1() -> FlyteFile:
     # Unlike the test above, this returns the remote path wrapped in a FlyteFile object
     return FlyteFile(SAMPLE_DATA)
Beispiel #7
0
 def t1(path: str) -> FlyteFile:
     return FlyteFile(path)
Beispiel #8
0
 def t1() -> os.PathLike:
     return FlyteFile(local_dummy_file)