Example #1
0
    def test_build_question(self, runs):
        am = AttributeManager(self.description, ['first_name'])
        bm = AttributeManager('first_name', [])

        for i in range(4):
            member = Member(i, first_name='A', last_name='B')
            am.register_member(member)
            bm.register_member(member)

        with pytest.raises(RuntimeError,
                           match='currently not hintable for first_name'):
            am.build_question_with(bm)

        for i in range(250):
            member = Member(
                i + 10,
                first_name=random.choice(['1', '2', '3', '4', '5']),
                last_name=random.choice(['a', 'b', 'c', 'd', 'e']),
            )
            am.register_member(member)
            bm.register_member(member)

        member, attr, opts, idx = am.build_question_with(
            bm, exclude_members=[Member(0)])
        assert member != Member(0)
        assert attr in am.data
        assert member in am.available_members
        assert member in bm.available_members
        for first_name in set(opts).difference({opts[idx]}):
            assert not any(
                am.get_members_attribute(m) == attr
                and bm.get_members_attribute(m) == first_name
                for m in bm.available_members)
        assert attr == 'B'
        assert len(set(opts)) == 4
Example #2
0
    def test_build_question_free_text(self):
        am = AttributeManager(self.description, ['first_name'])
        bm = AttributeManager('first_name', [])

        for i in range(4):
            member = Member(i, first_name='A', last_name='B')
            am.register_member(member)
            bm.register_member(member)

        with pytest.raises(RuntimeError,
                           match='currently not hintable for first_name'):
            am.build_question_with(bm, multiple_choice=False)

        member = Member(100, first_name='100', last_name='200')
        am.register_member(member)
        bm.register_member(member)

        member, attr, correct = am.build_question_with(bm,
                                                       multiple_choice=False)
        assert attr in am.data
        assert member in am.available_members
        assert member in bm.available_members
        assert len(am.data[attr]) == 1
        assert attr == '200'
        assert correct == bm.get_members_attribute(member)
Example #3
0
    def test_build_question_with_errors(self, dummy_am):
        am = AttributeManager(self.description, [])
        with pytest.raises(
                ValueError,
                match=f'is not a valid question for {self.description}'):
            am.build_question_with(dummy_am)

        am = AttributeManager(self.description, [dummy_am])
        with pytest.raises(RuntimeError,
                           match='currently not hintable for dummy'):
            am.build_question_with(dummy_am)
Example #4
0
    def test_build_question(self, gender):
        bm = NameManager(self.description, ['last_name'])
        am = AttributeManager('last_name', ['first_name'],
                              gendered_questions=True)

        for i in range(4):
            member = Member(i, last_name='A', first_name='B', gender=gender)
            am.register_member(member)
            bm.register_member(member)

        with pytest.raises(RuntimeError,
                           match='currently not hintable for first_name'):
            am.build_question_with(bm)

        for i in range(100):
            member = Member(
                i + 10,
                first_name=random.choice(['1', '2', '3', '4', '5']),
                last_name=random.choice(['a', 'b', 'c', 'd', 'e']),
                gender=Gender.MALE,
            )
            am.register_member(member)
            bm.register_member(member)
        for i in range(100):
            member = Member(
                i + 120,
                first_name=random.choice(['6', '7', '8', '9', '10']),
                last_name=random.choice(['f', 'g', 'h', 'i', 'j']),
                gender=Gender.FEMALE,
            )
            am.register_member(member)
            bm.register_member(member)

        member, attr, opts, idx = am.build_question_with(bm)
        assert attr in am.data
        assert member in am.available_members
        assert member in bm.available_members
        for last_name in set(opts).difference({opts[idx]}):
            assert not any(
                am.get_members_attribute(m) == attr
                and bm.get_members_attribute(m) == last_name
                for m in bm.available_members)
        assert attr == 'A'
        assert len(set(opts)) == 4
        for o in opts:
            if gender == Gender.MALE:
                assert o in ['1', '2', '3', '4', '5', 'B']
            else:
                assert o in ['6', '7', '8', '9', '10', 'B']
Example #5
0
    def test_build_question_list_as_question(self):
        am = AttributeManager('first_name', ['instruments'])
        bm = AttributeManager('instruments', [])

        allowed = [Trumpet(), Drums(), Bassoon(), Clarinet(), Horn(), Flute()]

        for i in range(4):
            member = Member(i,
                            first_name='A',
                            instruments=[Tuba(), Trombone()])
            am.register_member(member)
            bm.register_member(member)

        with pytest.raises(RuntimeError,
                           match='currently not hintable for instruments'):
            am.build_question_with(bm)

        for i in range(100):
            member = Member(
                i + 10,
                first_name=random.choice(['1', '2', '3', '4', '5']),
                instruments=random.sample(allowed, random.randint(1, 4)),
            )
            am.register_member(member)
            bm.register_member(member)

        member, attr, opts, idx = am.build_question_with(bm)
        assert attr in am.data
        assert attr == 'A'
        assert len(set(opts)) == 4
        assert member in am.available_members
        assert member in bm.available_members
        for instrument in set(opts).difference({opts[idx]}):
            assert not any(attr == am.get_members_attribute(m)
                           and instrument in bm.get_members_attribute(m)
                           for m in bm.available_members)