Example #1
0
def test_add_n():
    res = execute_solid(
        add_n, input_values={"x": 3}, run_config={"solids": {"add_n": {"config": 7}}}
    )
    assert res.output_value() == 10
def test_dict_return_solid():
    res = execute_solid(dict_return_solid)
    assert res.output_value() == {'foo': 'bar'}
Example #3
0
def test_cache_file_from_s3_overwrite():
    with get_temp_dir() as temp_dir:
        s3_session_one = mock.MagicMock()
        execute_solid(
            cache_file_from_s3,
            ModeDefinition(
                resource_defs={
                    'file_cache': fs_file_cache,
                    's3': ResourceDefinition.hardcoded_resource(
                        s3_session_one),
                }),
            environment_dict={
                'solids': {
                    'cache_file_from_s3': {
                        'inputs': {
                            's3_coordinate': {
                                'bucket': 'some-bucket',
                                'key': 'some-key'
                            }
                        }
                    }
                },
                'resources': {
                    'file_cache': {
                        'config': {
                            'target_folder': temp_dir,
                            'overwrite': True
                        }
                    }
                },
            },
        )

        # assert the download occurred
        assert s3_session_one.download_file.call_count == 1

        s3_session_two = mock.MagicMock()
        execute_solid(
            cache_file_from_s3,
            ModeDefinition(
                resource_defs={
                    'file_cache': fs_file_cache,
                    's3': ResourceDefinition.hardcoded_resource(
                        s3_session_two),
                }),
            environment_dict={
                'solids': {
                    'cache_file_from_s3': {
                        'inputs': {
                            's3_coordinate': {
                                'bucket': 'some-bucket',
                                'key': 'some-key'
                            }
                        }
                    }
                },
                'resources': {
                    'file_cache': {
                        'config': {
                            'target_folder': temp_dir,
                            'overwrite': True
                        }
                    }
                },
            },
        )

        # assert the download did not occur because file is already there
        assert s3_session_two.download_file.call_count == 0
def test_nullable_concat():
    res = execute_solid(nullable_concat, input_values={'x': 'foo', 'y': None})
    assert res.output_value() == 'foo'
def test_set_solid():
    res = execute_solid(set_solid,
                        input_values={'set_input': {'foo', 'bar', 'baz'}})
    assert res.output_value() == sorted(['foo', 'bar', 'baz'])
def test_add_3():
    res = execute_solid(add_3, input_values={'x': 3})
    assert res.output_value() == 6
def test_concat():
    res = execute_solid(concat, input_values={'x': 'foo', 'y': 'bar'})
    assert res.output_value() == 'foobar'
Example #8
0
def test_failure_metadata_solid():
    with pytest.raises(Failure):
        execute_solid(my_failure_metadata_solid)
Example #9
0
def test_two_list_types():
    @solid(
        input_defs=[],
        config={
            'list_one': [int],
            'list_two': [int]
        },
    )
    def two_list_type(context):
        return context.solid_config

    assert execute_solid(
        two_list_type,
        environment_dict={
            'solids': {
                'two_list_type': {
                    'config': {
                        'list_one': [1],
                        'list_two': [2]
                    }
                }
            }
        },
    ).output_value() == {
        'list_one': [1],
        'list_two': [2]
    }

    @solid(
        input_defs=[],
        config={
            'list_one': [Int],
            'list_two': [Int]
        },
    )
    def two_list_type_condensed_syntax(context):
        return context.solid_config

    assert execute_solid(
        two_list_type_condensed_syntax,
        environment_dict={
            'solids': {
                'two_list_type_condensed_syntax': {
                    'config': {
                        'list_one': [1],
                        'list_two': [2]
                    }
                }
            }
        },
    ).output_value() == {
        'list_one': [1],
        'list_two': [2]
    }

    @solid(
        input_defs=[],
        config={
            'list_one': [int],
            'list_two': [int]
        },
    )
    def two_list_type_condensed_syntax_primitives(context):
        return context.solid_config

    assert execute_solid(
        two_list_type_condensed_syntax_primitives,
        environment_dict={
            'solids': {
                'two_list_type_condensed_syntax_primitives': {
                    'config': {
                        'list_one': [1],
                        'list_two': [2]
                    }
                }
            }
        },
    ).output_value() == {
        'list_one': [1],
        'list_two': [2]
    }
Example #10
0
def test_repeat_config():
    res = execute_solid(
        repeat_config,
        run_config={"solids": {"repeat_config": {"config": {"word": "foo", "times": 3}}}},
    )
    assert res.output_value() == "foofoofoo"
Example #11
0
def test_selector_config():
    res = execute_solid(
        hello_world, run_config={"solids": {"hello_world": {"config": {"haw": {}}}}}
    )
    assert res.output_value() == "Aloha honua!"
Example #12
0
def test_concat_typeless_config():
    res = execute_solid(
        concat_typeless_list_config,
        run_config={"solids": {"concat_typeless_list_config": {"config": ["foo", "bar", "baz"]}}},
    )
    assert res.output_value() == "foobarbaz"
Example #13
0
def test_hello():
    res = execute_solid(hello, run_config={"solids": {"hello": {"config": "Max"}}})
    assert res.output_value() == "Hello, Max!"
Example #14
0
def test_div_y():
    res = execute_solid(
        div_y, input_values={"x": 3.0}, run_config={"solids": {"div_y": {"config": 2.0}}}
    )
    assert res.output_value() == 1.5
def test_boolean():
    res = execute_solid(boolean, input_values={'x': True})
    assert res.output_value() == 'true'

    res = execute_solid(boolean, input_values={'x': False})
    assert res.output_value() == 'false'
Example #16
0
def test_python_tuple_output():
    @lambda_solid
    def emit_tuple() -> tuple:
        return (4, 5)

    assert execute_solid(emit_tuple).output_value() == (4, 5)
def test_empty_string():
    res = execute_solid(empty_string, input_values={'x': ''})
    assert res.output_value() is True

    res = execute_solid(empty_string, input_values={'x': 'foo'})
    assert res.output_value() is False
Example #18
0
def test_open_typing_tuple_output():
    @lambda_solid(output_def=OutputDefinition(Tuple))
    def emit_tuple():
        return (1, 2)

    assert execute_solid(emit_tuple).output_value() == (1, 2)
def test_div_2():
    res = execute_solid(div_2, input_values={'x': 7.0})
    assert res.output_value() == 3.5
Example #20
0
def test_complicated_dictionary_typing_pass():
    @lambda_solid(output_def=OutputDefinition(typing.Dict[str, typing.List[typing.Dict[int, int]]]))
    def emit_dict():
        return {"foo": [{1: 1, 2: 2}]}

    assert execute_solid(emit_dict).output_value() == {"foo": [{1: 1, 2: 2}]}
def test_exists():
    res = execute_solid(exists, input_values={'path': 'garkjgh.dkjhfk'})
    assert res.output_value() is False
Example #22
0
def test_dagster_dictionary_output():
    @lambda_solid(output_def=OutputDefinition(dict))
    def emit_dict():
        return {"key": "value"}

    assert execute_solid(emit_dict).output_value() == {"key": "value"}
def test_concat_list():
    res = execute_solid(concat_list,
                        input_values={'xs': ['foo', 'bar', 'baz']})
    assert res.output_value() == 'foobarbaz'
Example #24
0
def test_basic_typing_dictionary_output():
    @lambda_solid(output_def=OutputDefinition(typing.Dict))
    def emit_dict():
        return {"key": "value"}

    assert execute_solid(emit_dict).output_value() == {"key": "value"}
def test_tuple_solid():
    res = execute_solid(tuple_solid,
                        input_values={'tuple_input': ('foo', 1, 3.1)})
    assert res.output_value() == ['foo', 1, 3.1]
Example #26
0
def test_kitchen_sink():
    @solid(
        config_schema={
            "str_field":
            str,
            "int_field":
            int,
            "list_int": [int],
            "list_list_int": [[int]],
            "dict_field": {
                "a_string": str
            },
            "list_dict_field": [{
                "an_int": int
            }],
            "selector_of_things":
            Selector({
                "select_list_dict_field": [{
                    "an_int": int
                }],
                "select_int": int
            }),
            # this is a good argument to use () instead of [] for type parameterization in
            # the config system
            "optional_list_of_optional_string":
            Noneable([Noneable(str)]),
        })
    def kitchen_sink(context):
        return context.solid_config

    solid_config_one = {
        "str_field": "kjf",
        "int_field": 2,
        "list_int": [3],
        "list_list_int": [[1], [2, 3]],
        "dict_field": {
            "a_string": "kdjfkd"
        },
        "list_dict_field": [{
            "an_int": 2
        }, {
            "an_int": 4
        }],
        "selector_of_things": {
            "select_int": 3
        },
        "optional_list_of_optional_string": ["foo", None],
    }

    assert (execute_solid(
        kitchen_sink,
        run_config={
            "solids": {
                "kitchen_sink": {
                    "config": solid_config_one
                }
            }
        },
    ).output_value() == solid_config_one)

    solid_config_two = {
        "str_field": "kjf",
        "int_field": 2,
        "list_int": [3],
        "list_list_int": [[1], [2, 3]],
        "dict_field": {
            "a_string": "kdjfkd"
        },
        "list_dict_field": [{
            "an_int": 2
        }, {
            "an_int": 4
        }],
        "selector_of_things": {
            "select_list_dict_field": [{
                "an_int": 5
            }]
        },
        "optional_list_of_optional_string": None,
    }

    assert (execute_solid(
        kitchen_sink,
        run_config={
            "solids": {
                "kitchen_sink": {
                    "config": solid_config_two
                }
            }
        },
    ).output_value() == solid_config_two)
Example #27
0
def test_open_typing_set_output():
    @lambda_solid(output_def=OutputDefinition(typing.Set))
    def emit_set():
        return {1, 2}

    assert execute_solid(emit_set).output_value() == {1, 2}
def test_identity_imp():
    res = execute_solid(identity_imp, input_values={'x': 'foo'})
    assert res.output_value() == 'foo'
Example #29
0
def test_datadog_resource(
    event,
    gauge,
    increment,
    decrement,
    histogram,
    distribution,
    statsd_set,
    service_check,
    timed,
    timing,
):
    @solid
    def datadog_solid(context):
        assert context.resources.datadog

        # event
        context.resources.datadog.event('Man down!',
                                        'This server needs assistance.')
        event.assert_called_with('Man down!', 'This server needs assistance.')

        # gauge
        context.resources.datadog.gauge('users.online',
                                        1001,
                                        tags=["protocol:http"])
        gauge.assert_called_with('users.online', 1001, tags=["protocol:http"])

        # increment
        context.resources.datadog.increment('page.views')
        increment.assert_called_with('page.views')

        # decrement
        context.resources.datadog.decrement('page.views')
        decrement.assert_called_with('page.views')

        context.resources.datadog.histogram('album.photo.count',
                                            26,
                                            tags=["gender:female"])
        histogram.assert_called_with('album.photo.count',
                                     26,
                                     tags=["gender:female"])

        context.resources.datadog.distribution('album.photo.count',
                                               26,
                                               tags=["color:blue"])
        distribution.assert_called_with('album.photo.count',
                                        26,
                                        tags=["color:blue"])

        context.resources.datadog.set('visitors.uniques',
                                      999,
                                      tags=["browser:ie"])
        statsd_set.assert_called_with('visitors.uniques',
                                      999,
                                      tags=["browser:ie"])

        context.resources.datadog.service_check(
            'svc.check_name', context.resources.datadog.WARNING)
        service_check.assert_called_with('svc.check_name',
                                         context.resources.datadog.WARNING)

        context.resources.datadog.timing("query.response.time", 1234)
        timing.assert_called_with("query.response.time", 1234)

        @context.resources.datadog.timed('run_fn')
        def run_fn():
            pass

        run_fn()
        timed.assert_called_with('run_fn')

    result = execute_solid(
        datadog_solid,
        environment_dict={
            'resources': {
                'datadog': {
                    'config': {
                        'api_key': 'NOT_USED',
                        'app_key': 'NOT_USED'
                    }
                }
            }
        },
        mode_def=ModeDefinition(resource_defs={'datadog': datadog_resource}),
    )
    assert result.success
Example #30
0
def test_bool_config():
    res = execute_solid(bool_config, run_config={"solids": {"bool_config": {"config": True}}})
    assert res.output_value() == "true"

    res = execute_solid(bool_config, run_config={"solids": {"bool_config": {"config": False}}})
    assert res.output_value() == "false"