Ejemplo n.º 1
0
 def testWithRemainder(self):
     participants = self.participant_ids
     assignments = GroupAssigner(participants, self.group_ids,
                                 DO_RANDOMIZE).assign()
     expected = {
         'group1': ['p1', 'p2', 'p7'],
         'group2': ['p3', 'p4', 'p8'],
         'group3': ['p5', 'p6']
     }
     self.assertDictEquivalent(expected, assignments, participants)
Ejemplo n.º 2
0
    def testPrintOnlyOneGroup(self):

        input_assignments = [('p1', 'group1'), ('p2', 'group1'),
                             ('p7', 'group1'), ('p3', 'group2'),
                             ('p4', 'group2'), ('p8', 'group2'),
                             ('p5', 'group3'), ('p6', 'group3')]
        grouper = GroupAssigner(
            input_assignments,
            ['group1', 'group2', 'group3'],  # group IDs 
            False,  # randomize is irrelevant
            only_group='group1')

        expected = ['p1', 'p2', 'p7']
        with self.captured_output() as (out, err):  # @UnusedVariable
            grouper.run()

        # This can go inside or outside the `with` block
        output = out.getvalue().strip()
        self.assertEqual(output, expected)
Ejemplo n.º 3
0
    def testParticipantsFromFile(self):
        participants = self.participant_ids
        try:
            participant_file_fd = tempfile.NamedTemporaryFile(dir='/tmp')
            participant_file_fd.write('\n'.join(
                str(participant_id) for participant_id in participants))
            participant_file_fd.write('\n')
            participant_file_fd.flush()

            assignments = GroupAssigner(participant_file_fd.name,
                                        self.group_ids, DO_RANDOMIZE).assign()
            expected = {
                'group1': ['p1', 'p2', 'p7'],
                'group2': ['p3', 'p4', 'p8'],
                'group3': ['p5', 'p6']
            }
            self.assertDictEquivalent(expected, assignments, participants)
        finally:
            participant_file_fd.close()
Ejemplo n.º 4
0
 def testCreateDictFromTuples(self):
     '''
     Given an array of tuples, is a proper
     assignment dict constructed?
     '''
     input_assignments = [('p1', 'group1'), ('p2', 'group1'),
                          ('p7', 'group1'), ('p3', 'group2'),
                          ('p4', 'group2'), ('p8', 'group2'),
                          ('p5', 'group3'), ('p6', 'group3')]
     assignments = GroupAssigner(
         input_assignments,
         ['group1'],  # group IDs 
         False,  # randomize is irrelevant
         only_group='All').build_dict_from_tuples(input_assignments)
     expected = {
         'group1': ['p1', 'p2', 'p7'],
         'group2': ['p3', 'p4', 'p8'],
         'group3': ['p5', 'p6']
     }
     self.assertDictEquivalent(expected, assignments, self.participant_ids)
Ejemplo n.º 5
0
 def testSameNumMembersAsGroups(self):
     participants = self.participant_ids[0:3]
     assignments = GroupAssigner(participants, self.group_ids,
                                 DO_RANDOMIZE).assign()
     expected = {'group1': ['p1'], 'group2': ['p2'], 'group3': ['p3']}
     self.assertDictEquivalent(expected, assignments, participants)