Beispiel #1
0
 def test_fix_match_all(self, env, result):
     result.fix.match_all(
         values=[
             test_utils.FixMessage(
                 [(10914, "c1dec2c5"), (38, "500"), (44, "9")],
                 typed_values=True,
             ),
             test_utils.FixMessage(
                 [(10914, "f3ea6276"), (38, 501), (44, 9.1)],
                 typed_values=True,
             ),
         ],
         comparisons=[
             cmp.Expected(
                 test_utils.FixMessage(
                     [(10914, re.compile(".+")), (38, 501), (44, 9.10)],
                     typed_values=True,
                 )),
             cmp.Expected(
                 test_utils.FixMessage(
                     [(10914, "c1dec2c5"), (38, "500"), (44, 9.0)],
                     typed_values=True,
                 )),
         ],
         description="typed / unordered fix match all",
     )
Beispiel #2
0
    def test_mixed_fixmatch(self, fix_ns):
        """Test FIX matches between typed and untyped FIX messages."""
        expected = testing.FixMessage(
            ((35, "D"), (38, "1000000"), (44, "125.83")), typed_values=False)
        actual = testing.FixMessage(((35, "D"), (38, "1000000"), (44, 125.83)),
                                    typed_values=True)

        assert fix_ns.match(actual, expected, description="Mixed FIX match")
Beispiel #3
0
    def test_fix_match(self, env, result):
        result.fix.match(
            actual={
                "foo": 1,
                "bar": 2,
                "baz": 2
            },
            expected={
                "foo": 1,
                "bar": 2,
                "bat": 3
            },
            description="basic fix match",
            actual_description="description for actual",
            expected_description="description for expected",
            include_tags=["foo", "bar"],
            exclude_tags=["baz", "bat"],
        )

        result.fix.match(
            actual={
                "foo": 1,
                "bar": "hello"
            },
            expected={
                "foo": cmp.Equal(1),
                "bar": re.compile("he*")
            },
            description="match with regex & custom func",
        )

        result.fix.match(
            actual={
                "foo": 1,
                "bar": 1.54
            },
            expected={
                "foo": "1",
                "bar": "1.54"
            },
            description="default untyped fixmatch will stringify",
        )

        typed_fixmsg = test_utils.FixMessage((("foo", 1), ("bar", 1.54)),
                                             typed_values=True)
        result.fix.match(
            actual=typed_fixmsg,
            expected=typed_fixmsg.copy(),
            description="typed fixmatch will compare types",
        )

        untyped_fixmsg = test_utils.FixMessage((("foo", "1"), ("bar", "1.54")),
                                               typed_values=False)
        result.fix.match(
            actual=typed_fixmsg,
            expected=untyped_fixmsg,
            description="mixed fixmatch will compare string values",
        )
Beispiel #4
0
    def test_fix_match(self, env, result):
        result.fix.match(
            actual={'foo': 1, 'bar': 2, 'baz': 2},
            expected={'foo': 1, 'bar': 2, 'bat': 3},
            description='basic fix match',
            actual_description='description for actual',
            expected_description='description for expected',
            include_tags=['foo', 'bar'],
            exclude_tags=['baz', 'bat']
        )

        result.fix.match(
            actual={'foo': 1},
            expected={'foo': 5},
            description='simple failing match',
        )

        result.fix.match(
            actual={'foo': 1, 'bar': 'hello'},
            expected={
                'foo': cmp.Equal(1),
                'bar': re.compile('he*')
            },
            description='match with regex & custom func'
        )

        result.fix.match(
            actual={'foo': 'hello'},
            expected={
                'foo': re.compile('aaa*')
            },
            description='failing pattern match'
        )

        result.fix.match(
            actual={'foo': 1},
            expected={
                'foo': cmp.Equal(5)
            },
            description='failing comparator func'
        )

        result.fix.match(
            actual={'foo': 1},
            expected={
                'foo': error_func
            },
            description='error func'
        )

        typed_fixmsg_actual = test_utils.FixMessage(
            (('foo', 1), ('bar', 2.0)), typed_values=True)
        typed_fixmsg_ex = test_utils.FixMessage(
            (('foo', 1), ('bar', 2)), typed_values=True)
        result.fix.match(
            actual=typed_fixmsg_actual,
            expected=typed_fixmsg_ex,
            description='typed fixmsgs have different value types')
Beispiel #5
0
    def test_fix_match(self, env, result):
        result.fix.match(actual={
            'foo': 1,
            'bar': 2,
            'baz': 2
        },
                         expected={
                             'foo': 1,
                             'bar': 2,
                             'bat': 3
                         },
                         description='basic fix match',
                         actual_description='description for actual',
                         expected_description='description for expected',
                         include_tags=['foo', 'bar'],
                         exclude_tags=['baz', 'bat'])

        result.fix.match(actual={
            'foo': 1,
            'bar': 'hello'
        },
                         expected={
                             'foo': cmp.Equal(1),
                             'bar': re.compile('he*')
                         },
                         description='match with regex & custom func')

        result.fix.match(actual={
            'foo': 1,
            'bar': 1.54
        },
                         expected={
                             'foo': '1',
                             'bar': '1.54'
                         },
                         description='default untyped fixmatch will stringify')

        typed_fixmsg = test_utils.FixMessage((('foo', 1), ('bar', 1.54)),
                                             typed_values=True)
        result.fix.match(actual=typed_fixmsg,
                         expected=typed_fixmsg.copy(),
                         description='typed fixmatch will compare types')

        untyped_fixmsg = test_utils.FixMessage((('foo', '1'), ('bar', '1.54')),
                                               typed_values=False)
        result.fix.match(
            actual=typed_fixmsg,
            expected=untyped_fixmsg,
            description='mixed fixmatch will compare string values')
Beispiel #6
0
    def test_untyped_fixmatch(self, fix_ns):
        """Test FIX matches between untyped FIX messages."""
        expected = testing.FixMessage(
            ((35, "D"), (38, "1000000"), (44, "125.83")))
        actual = expected.copy()

        assert fix_ns.match(actual, expected, description="Basic FIX match")
Beispiel #7
0
 def test_fix_match_all(self, env, result):
     result.fix.match_all(
         values=[
             test_utils.FixMessage([(10914, 'c1dec2c5'), (38, '500'),
                                    (44, '9')],
                                   typed_values=True),
             test_utils.FixMessage([(10914, 'f3ea6276'), (38, 501),
                                    (44, 9.1)],
                                   typed_values=True),
         ],
         comparisons=[
             cmp.Expected(
                 test_utils.FixMessage([(10914, re.compile('.+')),
                                        (38, 501), (44, 9.10)],
                                       typed_values=True)),
             cmp.Expected(
                 test_utils.FixMessage([(10914, 'c1dec2c5'), (38, '500'),
                                        (44, 9.0)],
                                       typed_values=True)),
         ],
         description='typed / unordered fix match all')
Beispiel #8
0
    def test_report_modes(self, fix_ns):
        """Test controlling report modes for FIX match."""
        expected = testing.FixMessage((i, (25 * i) - 4) for i in range(10))
        actual = expected.copy()
        expected["wrong"] = "expected"
        actual["wrong"] = "actual"

        assert not fix_ns.match(
            actual, expected, description="Keep all comparisons by default")
        assert len(fix_ns.result.entries) == 1
        dict_assert = fix_ns.result.entries.popleft()
        assert len(dict_assert.comparison) == 11

        assert fix_ns.match(
            actual,
            expected,
            description="Keep ignored comparisons",
            include_tags=[0, 1, 2],
        )

        assert len(fix_ns.result.entries) == 1
        dict_assert = fix_ns.result.entries.popleft()
        assert len(dict_assert.comparison) == 11

        assert fix_ns.match(
            actual,
            expected,
            description="Discard ignored comparisons",
            include_tags=[0, 1, 2],
            report_mode=comparison.ReportOptions.NO_IGNORED,
        )

        assert len(fix_ns.result.entries) == 1
        dict_assert = fix_ns.result.entries.popleft()
        assert len(dict_assert.comparison) == 3

        assert not fix_ns.match(
            actual,
            expected,
            report_mode=comparison.ReportOptions.FAILS_ONLY,
            description="Discard passing comparisons",
        )
        assert len(fix_ns.result.entries) == 1
        dict_assert = fix_ns.result.entries.popleft()
        assert len(dict_assert.comparison) == 1
Beispiel #9
0
    def test_typed_fixmatch(self, fix_ns):
        """Test FIX matches between typed FIX messages."""
        expected = testing.FixMessage(((35, "D"), (38, 1000000), (44, 125.83)),
                                      typed_values=True)
        actual = expected.copy()

        assert fix_ns.match(actual, expected, description="Basic FIX match")

        # Now change the type of the actual 38 key's value to str. The assert
        # should fail since we are performing a typed match.
        actual[38] = "1000000"
        assert not fix_ns.match(
            actual, expected, description="Failing str/int comparison")

        # Change the type to a float. The match should still fail because of
        # the type difference, despite the numeric values being equal.
        actual[38] = 1000000.0
        assert not fix_ns.match(
            actual, expected, description="Failing float/int comparison")
Beispiel #10
0
    def test_fix_match(self, env, result):
        result.fix.match(
            actual={
                "foo": 1,
                "bar": 2,
                "baz": 2
            },
            expected={
                "foo": 1,
                "bar": 2,
                "bat": 3
            },
            description="basic fix match",
            actual_description="description for actual",
            expected_description="description for expected",
            include_tags=["foo", "bar"],
            exclude_tags=["baz", "bat"],
        )

        result.fix.match(
            actual={"foo": 1},
            expected={"foo": 5},
            description="simple failing match",
        )

        result.fix.match(
            actual={
                "foo": 1,
                "bar": "hello"
            },
            expected={
                "foo": cmp.Equal(1),
                "bar": re.compile("he*")
            },
            description="match with regex & custom func",
        )

        result.fix.match(
            actual={"foo": "hello"},
            expected={"foo": re.compile("aaa*")},
            description="failing pattern match",
        )

        result.fix.match(
            actual={"foo": 1},
            expected={"foo": cmp.Equal(5)},
            description="failing comparator func",
        )

        result.fix.match(
            actual={"foo": 1},
            expected={"foo": error_func},
            description="error func",
        )

        typed_fixmsg_actual = test_utils.FixMessage((("foo", 1), ("bar", 2.0)),
                                                    typed_values=True)
        typed_fixmsg_ex = test_utils.FixMessage((("foo", 1), ("bar", 2)),
                                                typed_values=True)
        result.fix.match(
            actual=typed_fixmsg_actual,
            expected=typed_fixmsg_ex,
            description="typed fixmsgs have different value types",
        )