コード例 #1
0
ファイル: object_test.py プロジェクト: hypothesis/h-matchers
    def test_it_matches_with_attributes_correctly(self, attributes, matches):
        other = ValueObject(one="one", two="two")

        if matches:
            assert other == AnyObject.with_attrs(attributes)
        else:
            assert other != AnyObject.with_attrs(attributes)
コード例 #2
0
    def __init__(self, attributes):
        attributes["identities"] = [
            AnyObject(UserIdentity, identity)
            for identity in attributes["identities"]
        ]

        super().__init__(User, attributes)
コード例 #3
0
ファイル: object_test.py プロジェクト: hypothesis/h-matchers
    def test_it_mocks_attributes(self):
        matcher = AnyObject.with_attrs({"a": "A"})

        assert matcher.a == "A"

        with pytest.raises(AttributeError):
            matcher.b  # pylint: disable=pointless-statement
コード例 #4
0
ファイル: object_test.py プロジェクト: hypothesis/h-matchers
    def test_setting_magic_methods_as_attributes_does_not_set_attributes(
            self, magic_method):
        # There's no sensible reason to do it, but we should still be able to
        # function normally if you do.

        weird_matcher = AnyObject.with_attrs({magic_method: "test"})

        result = getattr(weird_matcher, magic_method)

        assert callable(result)
コード例 #5
0
    def assert_groups_match_commands(db_session, commands):
        groups = list(
            db_session.query(Group).filter(
                Group.authority == AUTHORITY).order_by(Group.name))

        expected_groups = sorted(
            [
                AnyObject.of_type(Group).with_attrs(command.body.attributes)
                for command in commands
            ],
            key=attrgetter("name"),
        )

        assert groups == expected_groups
コード例 #6
0
    def assert_membership_matches_commands(db_session, commands):
        # Sort by `group_id` as these tests always use the same `user_id`
        memberships = list(
            db_session.query(GroupMembership).order_by(
                GroupMembership.group_id))

        expected_memberships = sorted(
            [
                AnyObject.of_type(GroupMembership).with_attrs(
                    {
                        "user_id": command.body.member.id,
                        "group_id": command.body.group.id,
                    }) for command in commands
            ],
            key=attrgetter("group_id"),
        )

        assert memberships == expected_memberships
コード例 #7
0
    def instance_of(type_):
        """Specify that this item must be an instance of the provided type.

        :return: An instance of AnyObject configured with the given type.
        """
        return AnyObject.of_type(type_)
コード例 #8
0
ファイル: object_test.py プロジェクト: hypothesis/h-matchers
    def test_type_and_attributes_at_once(self):
        matcher = AnyObject.of_type(ValueObject).with_attrs({"one": "one"})

        assert ValueObject("one", "two") == matcher
        assert NotValueObject("one", "two") != matcher
        assert ValueObject("bad", "two") != matcher
コード例 #9
0
ファイル: object_test.py プロジェクト: hypothesis/h-matchers
 def test_it_raise_ValueError_if_attributes_does_not_support_items(
         self, bad_input):
     with pytest.raises(ValueError):
         AnyObject.with_attrs(bad_input)
コード例 #10
0
ファイル: object_test.py プロジェクト: hypothesis/h-matchers
 def test_it_matches_types_correctly(self, type_, instance, matches):
     if matches:
         assert instance == AnyObject(type_=type_)
     else:
         assert instance != AnyObject(type_=type_)
コード例 #11
0
ファイル: object_test.py プロジェクト: hypothesis/h-matchers
    def test_stringification(self, type_, attributes, string):
        matcher = AnyObject(type_=type_, attributes=attributes)

        assert str(matcher) == string