Exemple #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
Exemple #2
0
    def test_build_question_free_text(self, gender):
        bm = NameManager(self.description, ['last_name'])
        am = AttributeManager('last_name', ['first_name'])

        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 last_name'):
            bm.build_question_with(am, multiple_choice=False)

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

        member, attr, correct = bm.build_question_with(am,
                                                       multiple_choice=False)
        data = bm.female_data if member.gender == Gender.FEMALE else bm.male_data
        assert attr in data
        assert member in am.available_members
        assert member in bm.available_members
        assert attr == '100'
        assert correct == am.get_members_attribute(member)
Exemple #3
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)
Exemple #4
0
 def test_init(self, member, dummy_am):
     am = AttributeManager(self.description, [dummy_am])
     member.last_name = 'test'
     assert am.description == self.description
     assert am.questionable_attributes == [dummy_am]
     assert am.data == {}
     assert am.get_members_attribute(member) == 'test'
Exemple #5
0
    def test_init_custom_gma(self, member, dummy_am):
        def gma(m: Member):
            return '5'

        am = AttributeManager(self.description, [dummy_am],
                              get_members_attribute=gma)
        member.last_name = 'test'
        assert am.description == self.description
        assert am.questionable_attributes == [dummy_am]
        assert am.data == {}
        assert am.get_members_attribute(member) == '5'
Exemple #6
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']
Exemple #7
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)