Esempio n. 1
0
def test_inject_contexts_at_different_levels():
    c1 = {
        'messages': {
            'msg_var': 0
        },
        'plans': {
            'plans_var': 24
        },
        **config
    }
    c2 = {
        'messages': {
            'level': 1
        },
        **config
    }

    with td.TradingContext(c1):
        name = 'TensorTrade'
        value = 'the time and effort.'
        instance1 = WorthMessageComponent(name=name, value=value)
        win1 = WinPlanComponent()
        lose1 = LosePlanComponent()
        assert hasattr(instance1.context, 'msg_var')
        assert hasattr(win1.context, 'plans_var')
        assert hasattr(lose1.context, 'plans_var')

        with td.TradingContext(c2):
            name = 'TensorTrade'
            value = 'the time and effort.'
            instance2 = WorthMessageComponent(name=name, value=value)

            assert hasattr(instance2.context, 'level')
            assert instance2.context == {'level': 1, **config}
Esempio n. 2
0
def test_context_within_context():

    with td.TradingContext(**config) as tc1:
        assert get_context() == tc1

        with td.TradingContext(**config) as tc2:
            assert get_context() == tc2

        assert get_context() == tc1
Esempio n. 3
0
def test_context_creation():

    with td.TradingContext(**config) as tc1:
        assert tc1.data == config

        with td.TradingContext(**config) as tc2:
            assert TradingContext.get_context() == tc2

        assert TradingContext.get_context() == tc1
Esempio n. 4
0
def test_only_name_registered_component_space():
    c = {
        'actions': {
            'n_actions': 20
        },
        'messages': {
            'msg_var': 0,
            'valid': ['Hello', 'World']
        },
        'plans': {
            'future': 'looking good'
        },
        **config
    }

    with td.TradingContext(**c) as c:
        name = 'TensorTrade'
        value = 'the time and effort.'
        instance = WorthMessageComponent(name=name, value=value)

        assert instance.context == {
            'msg_var': 0,
            'valid': ['Hello', 'World'],
            **config
        }
Esempio n. 5
0
def test_injects_concrete_tensor_trade_component_with_context():

    with td.TradingContext(config):

        name = 'TensorTrade'
        value = 'the time and effort.'
        instance = WorthMessageComponent(name=name, value=value)
        assert instance.context == config
        assert instance.message() == 'TensorTrade is worth the time and effort.'
Esempio n. 6
0
def test_inject_multiple_components_with_context():

    with td.TradingContext(config):
        name = 'TensorTrade'
        value = 'the time and effort.'
        instance = WorthMessageComponent(name=name, value=value)
        win = WinPlanComponent()
        lose = LosePlanComponent()

        assert instance.context == win.context == lose.context

    assert instance.context == win.context == lose.context
Esempio n. 7
0
def test_injects_component_space():
    c = {'messages': {'msg_var': 0, 'valid': ['Hello', 'World']}, **config}

    with td.TradingContext(**c) as c:
        name = 'TensorTrade'
        value = 'the time and effort.'
        instance = WorthMessageComponent(name=name, value=value)

        assert hasattr(instance.context, 'msg_var')
        assert hasattr(instance.context, 'valid')

        assert instance.context.msg_var == 0
        assert instance.context.valid == ['Hello', 'World']
Esempio n. 8
0
def test_context_retains_data_outside_with():

    with td.TradingContext(**config) as tc:
        assert tc.data == config

    assert tc.data == config
Esempio n. 9
0
def test_get_context_from_tensor_trade_level():
    with td.TradingContext(**config) as tc:
        assert get_context() == tc