Exemplo n.º 1
0
 def test_draw_question_attributes_error(self):
     am = AttributeManager(self.description, [])
     bm = AttributeManager(self.description, [])
     with pytest.raises(
             RuntimeError,
             match=f'Given member has no attribute {self.description}'):
         am.draw_question_attributes(bm, Member(1))
Exemplo n.º 2
0
    def test_draw_question_attributes(self):
        am = AttributeManager(self.description, [])
        bm = AttributeManager('first_name', [])

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

        for i, name in enumerate(['a', 'b', 'c', 'd', 'e']):
            with pytest.raises(RuntimeError,
                               match='is not hintable for attribute'):
                attrs, idx = am.draw_question_attributes(
                    bm, Member(1000, first_name=str(i + 1), last_name=name))
        for i, name in enumerate(['a', 'b', 'c', 'd', 'e']):
            attrs, idx = am.draw_question_attributes(
                bm, Member(1000, first_name=str(i + 10), last_name=name))
            assert len(set(attrs)) == 4
            assert attrs[idx] == name
            for a in attrs:
                assert a in ['a', 'b', 'c', 'd', 'e']