예제 #1
0
 def test_if_operator_config(self):
     config_dict = {
         "cond": "{{ i }} == 5",
         "do": "It was True",
         "elseDo": "It was False",
     }
     config = IfConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict
     assert "It was True" == config.parse(Parser(), {"i": 5})
     assert "It was False" == config.parse(Parser(), {"i": 3})
예제 #2
0
    def test_for_operator_config(self):
        config_dict = {"len": 5, "do": "Value at {{ i }}", "index": "i"}
        config = ForConfig.from_dict(config_dict)
        assert config.to_dict() == config_dict

        expected = [
            "Value at 0",
            "Value at 1",
            "Value at 2",
            "Value at 3",
            "Value at 4",
        ]
        assert expected == config.parse(Parser(), {})

        config_dict = {
            "len": 5,
            "do": [
                {"Conv2D": {"strides": ["{{ i }}", "{{ i }}"]}},
                {"Pooling2D": {"strides": ["{{ i }}", "{{ i }}"]}},
            ],
            "index": "i",
        }
        config = ForConfig.from_dict(config_dict)
        assert config.to_dict() == config_dict

        # Lists get flattened
        expected = [
            {"Conv2D": {"strides": [0, 0]}},
            {"Pooling2D": {"strides": [0, 0]}},
            {"Conv2D": {"strides": [1, 1]}},
            {"Pooling2D": {"strides": [1, 1]}},
            {"Conv2D": {"strides": [2, 2]}},
            {"Pooling2D": {"strides": [2, 2]}},
            {"Conv2D": {"strides": [3, 3]}},
            {"Pooling2D": {"strides": [3, 3]}},
            {"Conv2D": {"strides": [4, 4]}},
            {"Pooling2D": {"strides": [4, 4]}},
        ]
        assert expected == config.parse(Parser(), {})
예제 #3
0
    def test_parse_base_expressions(self):
        data = [
            1,
            10.0,
            [1, 1],
            (1, 1),
            "string",
            ["str1", "str2"],
            {1: 2, "a": "a", "dict": {1: 1}},
        ]

        parser = Parser()
        for d in data:
            assert d == parser.parse_expression(d, {})
예제 #4
0
 def test_parse_context_expression(self):
     parser = Parser()
     assert parser.parse_expression("{{ something }}", {}) == ""
     assert parser.parse_expression("{{ something }}",
                                    {"something": 1}) == 1