Example #1
0
def test_single_transform_returning_result():
    solid_inst = single_output_transform(
        'test_return_result',
        inputs=[],
        transform_fn=lambda *_args, **_kwargs: Result(None),
        output=OutputDefinition()
    )

    with pytest.raises(DagsterInvariantViolationError):
        execute_single_solid(ExecutionContext(), solid_inst)
Example #2
0
def test_do_not_yield_result():
    solid_inst = SolidDefinition(
        name='do_not_yield_result',
        inputs=[],
        outputs=[OutputDefinition()],
        transform_fn=lambda *_args, **_kwargs: Result('foo')
    )

    with pytest.raises(
        DagsterInvariantViolationError,
        message='Tranform for solid do_not_yield_result return a Result',
    ):
        execute_single_solid(ExecutionContext(), solid_inst)
Example #3
0
def test_yield_non_result():
    def _tn(*_args, **_kwargs):
        yield 'foo'

    solid_inst = SolidDefinition(
        name='yield_wrong_thing',
        inputs=[],
        outputs=[OutputDefinition()],
        transform_fn=_tn,
    )

    with pytest.raises(
        DagsterInvariantViolationError,
        message="Tranform for solid yield_wrong_thing yielded 'foo'",
    ):
        execute_single_solid(ExecutionContext(), solid_inst)
Example #4
0
def test_dict_multiple_outputs():
    @solid(outputs=[
        OutputDefinition(name="left"),
        OutputDefinition(name="right")
    ])
    def hello_world(_info):
        return MultipleResults.from_dict({
            'left': {
                'foo': 'left'
            },
            'right': {
                'foo': 'right'
            },
        })

    result = execute_single_solid(
        create_test_context(),
        hello_world,
        environment=create_empty_test_env(),
    )

    assert result.success
    assert len(result.result_list) == 1
    solid_result = result.result_list[0]
    assert solid_result.transformed_value('left')['foo'] == 'left'
    assert solid_result.transformed_value('right')['foo'] == 'right'
def test_basic_isolated_sql_solid():
    context = in_mem_context()

    sql_text = '''CREATE TABLE sum_table AS SELECT num1, num2, num1 + num2 as sum FROM num_table'''

    basic_isolated_sql_solid = create_sql_statement_solid('basic_isolated_sql_solid', sql_text)

    result = execute_single_solid(context, basic_isolated_sql_solid)

    assert result.success

    results = context.resources.sa.engine.connect().execute('SELECT * from sum_table').fetchall()
    assert results == [(1, 2, 3), (3, 4, 7)]
Example #6
0
def test_solid():
    @solid(outputs=[OutputDefinition()])
    def hello_world(_info):
        return {'foo': 'bar'}

    result = execute_single_solid(
        create_test_context(),
        hello_world,
        environment=create_empty_test_env(),
    )

    assert result.success
    assert len(result.result_list) == 1
    assert result.result_list[0].transformed_value()['foo'] == 'bar'
Example #7
0
def test_empty_solid():
    called = {}

    @lambda_solid()
    def hello_world():
        called['yup'] = True

    result = execute_single_solid(
        create_test_context(),
        hello_world,
        environment=create_empty_test_env(),
    )

    assert called['yup']
Example #8
0
def test_lambda_solid_with_name():
    @lambda_solid(name="foobar")
    def hello_world():
        return {'foo': 'bar'}

    result = execute_single_solid(
        create_test_context(),
        hello_world,
        environment=create_empty_test_env(),
    )

    assert result.success
    assert len(result.result_list) == 1
    assert result.result_list[0].transformed_value()['foo'] == 'bar'
Example #9
0
def test_any_config_definition():
    called = {}
    conf_value = 234

    @solid(config_def=ConfigDefinition())
    def hello_world(info):
        assert info.config == conf_value
        called['yup'] = True

    result = execute_single_solid(
        create_test_context(),
        hello_world,
        environment=config.Environment(
            solids={'hello_world': config.Solid(conf_value)}))

    assert called['yup']