Example #1
0
    def test_values(self):
        s0 = create_strategy(lambda universe: [])
        s1 = create_strategy(lambda universe: [])
        container = StrategyContainer(s0=s0, s1=s1)

        for i, strategy in enumerate(container.values()):
            assert strategy == [s0, s1][i]
Example #2
0
    def test_key(self):
        s0 = create_strategy(lambda universe: [])
        s1 = create_strategy(lambda universe: [])
        container = StrategyContainer(s0=s0, s1=s1)

        for i, name in enumerate(container.keys()):
            assert name == ["s0", "s1"][i]
Example #3
0
    def test_logic(self):
        s0 = create_strategy(lambda universe: [trade("A")])
        s1 = create_strategy(lambda universe: [trade("B"), trade("C")])
        container = StrategyContainer(s0=s0, s1=s1)
        universe = ...

        result = container(universe)
        assert container(universe) == s0(universe) + s1(universe)
Example #4
0
 def test_add_strategy_typeerror(self):
     s = create_strategy(lambda universe: [])
     container = StrategyContainer()
     with pytest.raises(TypeError):
         container.add_strategy(0, s)
     with pytest.raises(TypeError):
         container.add_strategy("name", None)
Example #5
0
    def test_items(self):
        s0 = create_strategy(lambda universe: [])
        s1 = create_strategy(lambda universe: [])
        container = StrategyContainer(s0=s0, s1=s1)

        for (k1), (k2, _) in zip(container.keys(), container.items()):
            assert k1 == k2
        for (v1), (_, v2) in zip(container.values(), container.items()):
            assert v1 == v2
Example #6
0
 def test_len(self):
     s0 = create_strategy(lambda universe: [])
     s1 = create_strategy(lambda universe: [])
     container = StrategyContainer()
     assert len(container) == 0
     container.add_strategy("s0", s0)
     assert len(container) == 1
     container.add_strategy("s1", s1)
     assert len(container) == 2
Example #7
0
    def test_add_strategy(self):
        s0 = create_strategy(lambda universe: [])
        s1 = create_strategy(lambda universe: [])

        container = StrategyContainer()
        assert container._strategies == OrderedDict()
        container.add_strategy("s0", s0)
        assert container._strategies == OrderedDict({"s0": s0})
        container.add_strategy("s1", s1)
        assert container._strategies == OrderedDict({"s0": s0, "s1": s1})