コード例 #1
0
 def test_json_serialization_fail_type_missing(self):
     with pytest.raises(ValueError,
                        match="Missing type value for condition"):
         Conjunction.from_jsonarray([{}])
コード例 #2
0
 def test_json_serialization_fail_no_cond_dict(self):
     with pytest.raises(TypeError,
                        match="Condition in jsonarray must be a dict"):
         Conjunction.from_jsonarray([1])
コード例 #3
0
 def test_json_serialization_fail_type(self, array):
     with pytest.raises(TypeError, match="Unknown condition class"):
         Conjunction.from_jsonarray(array)
コード例 #4
0
 def test_json_serialization_fail_no_list(self):
     with pytest.raises(TypeError, match="jsonarray must be a list"):
         Conjunction.from_jsonarray({})
コード例 #5
0
    def test_json_serialization_ok(self):
        conj = Conjunction([
            EqualityCondition(column="foö", value=1.2),
            GreaterEqualCondition(column="foö", value=1.2),
            GreaterThanCondition(column="foö", value=1.2),
            InequalityCondition(column="foö", value=1.2),
            LessEqualCondition(column="foö", value=1.2),
            LessThanCondition(column="foö", value=1.2),
            InIntervalCondition(column="foö", start=1.2, stop=2.3),
            IsInCondition(column="foö", value=[1.2, 1.3]),
        ])

        array_actual = conj.to_jsonarray()
        array_expected = [
            {
                "type": "EqualityCondition",
                "column": "foö",
                "value": 1.2
            },
            {
                "type": "GreaterEqualCondition",
                "column": "foö",
                "value": 1.2
            },
            {
                "type": "GreaterThanCondition",
                "column": "foö",
                "value": 1.2
            },
            {
                "type": "InequalityCondition",
                "column": "foö",
                "value": 1.2
            },
            {
                "type": "LessEqualCondition",
                "column": "foö",
                "value": 1.2
            },
            {
                "type": "LessThanCondition",
                "column": "foö",
                "value": 1.2
            },
            {
                "type": "InIntervalCondition",
                "column": "foö",
                "start": 1.2,
                "stop": 2.3
            },
            {
                "type": "IsInCondition",
                "column": "foö",
                "value": [1.2, 1.3]
            },
        ]
        assert array_actual == array_expected

        conj2 = Conjunction.from_jsonarray(array_actual)
        assert conj2 == conj

        # input not altered
        assert array_actual == array_expected