Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def test_double_register(self, member):
        member.first_name = 'test'
        member.gender = Gender.MALE
        am = NameManager(self.description, [])

        am.register_member(member)
        with pytest.raises(RuntimeError,
                           match='Member is already registered.'):
            am.register_member(Member(user_id=123456, first_name='test1'))
Ejemplo n.º 3
0
    def test_kick_member(self, member, gender):
        member.first_name = 'test'
        member.gender = gender
        am = NameManager(self.description, [])

        am.register_member(member)
        data = am.male_data if gender == Gender.MALE else am.female_data
        assert data == {'test': {member}}

        am.kick_member(member)
        assert data == {}

        am.kick_member(member)
        assert data == {}
Ejemplo n.º 4
0
    def test_unique_attributes_of(self, member):
        member.first_name = 'test'
        member.gender = Gender.MALE

        am = NameManager(self.description, [])
        am.register_member(member)
        am.register_member(Member(1, first_name='test', gender=Gender.MALE))
        assert am.unique_attributes_of(member) == []

        member = Member(2, first_name='test', gender=Gender.FEMALE)
        am.register_member(member)
        assert am.unique_attributes_of(member) == []

        member = Member(3, first_name='test1', gender=Gender.FEMALE)
        am.register_member(member)
        assert am.unique_attributes_of(member) == ['test1']
Ejemplo n.º 5
0
    def test_distinct_values_for_member_full_name(self, member, gender,
                                                  other_gender):
        am = NameManager('full_name', [])
        bm = AttributeManager('instruments', [], gendered_questions=True)

        for i in range(10):
            am.register_member(Member(i, last_name='a', instruments=[Tuba()]))

        for g in [None, gender, other_gender]:
            assert (am.distinct_values_for_member(
                bm, Member(100, last_name='a', instruments=[Tuba()],
                           gender=g)) == set())
            assert (am.distinct_values_for_member(
                bm, Member(100, last_name='c', instruments=[Tuba()],
                           gender=g)) == set())

        am.register_member(Member(200, last_name='A', instruments=[Trumpet()]))
        assert (am.distinct_values_for_member(
            bm,
            Member(200, last_name='A', instruments=[Trumpet()],
                   gender=gender)) == set())
        assert am.distinct_values_for_member(
            bm, Member(200, last_name='A', instruments=[Trumpet()])) == {'a'}
Ejemplo n.º 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']
Ejemplo n.º 7
0
    def test_distinct_values_for_member(self, member, gender, other_gender):
        am = NameManager(self.description, [])
        bm = AttributeManager('last_name', [], gendered_questions=True)

        for i in range(10):
            am.register_member(
                Member(i, last_name='a', first_name='b', gender=gender))

        for g in [None, gender, other_gender]:
            assert (am.distinct_values_for_member(
                bm, Member(100, last_name='a', first_name='b',
                           gender=g)) == set())
            assert (am.distinct_values_for_member(
                bm, Member(100, last_name='c', first_name='b',
                           gender=g)) == set())

        for i in range(5):
            am.register_member(
                Member(i + 10, last_name=str(i), first_name='b',
                       gender=gender))

        for g in [None, gender, other_gender]:
            assert (am.distinct_values_for_member(
                bm, Member(100, last_name='a', first_name='b',
                           gender=g)) == set())
            assert (am.distinct_values_for_member(
                bm, Member(100, last_name='c', first_name='b',
                           gender=g)) == set())

        for i in range(5):
            am.register_member(
                Member(i + 20, last_name='a', first_name=str(i),
                       gender=gender))

        assert (am.distinct_values_for_member(
            bm, Member(100, last_name='a', first_name='b',
                       gender=gender)) == set())
        assert am.distinct_values_for_member(
            bm, Member(100, last_name='c', first_name='b',
                       gender=gender)) == {'0', '1', '2', '3', '4'}
        assert (am.distinct_values_for_member(
            bm, Member(100, last_name='a', first_name='b',
                       gender=other_gender)) == set())
        assert (am.distinct_values_for_member(
            bm, Member(100, last_name='c', first_name='b',
                       gender=other_gender)) == set())
Ejemplo n.º 8
0
    def test_register_male_member(self, member):
        member.first_name = 'test1'
        member.gender = Gender.MALE
        am = NameManager(self.description, [])

        am.register_member(member)
        assert am.female_data == {}
        assert am.male_data == {'test1': {member}}
        assert all(member is not m for m in am.male_data['test1'])

        member2 = Member(2, first_name='test2', gender=Gender.MALE)
        am.register_member(member2)
        assert am.female_data == {}
        assert am.male_data == {'test1': {member}, 'test2': {member2}}
        assert (member2 is not m for m in am.male_data['test2'])

        member3 = Member(4, first_name='test1', gender=Gender.MALE)
        am.register_member(member3)
        assert am.female_data == {}
        assert am.male_data == {'test1': {member, member3}, 'test2': {member2}}
        assert all(member3 is not m for m in am.male_data['test1'])
Ejemplo n.º 9
0
 def test_register_member_without_gender(self, member):
     member.first_name = 'test'
     am = NameManager(self.description, [])
     am.register_member(member)
     assert am.male_data == {}
     assert am.female_data == {}
Ejemplo n.º 10
0
 def test_register_member_without_attribute(self, member):
     am = NameManager(self.description, [])
     am.register_member(member)
     assert am.male_data == {}
     assert am.female_data == {}