Exemple #1
0
 def testGivenKeyFunctionAsPositionalAttributeGroupsByItsResult(self):
     self.assertEqual(
         {
             2: [(0, 2), (1, 1), (1, 1)],
             3: [(1, 2), (2, 1), (3, 0)]
         },
         groupBy([(1, 2), (2, 1), (0, 2), (3, 0), (1, 1), (1, 1)],
                 lambda x: x[0] + x[1]))
Exemple #2
0
 def testGivenKeyFunctionAsKeywordAttributeGroupsByItsResult(self):
     self.assertEqual(
         {
             1: [(1, 1), (2, 1, 8)],
             2: [(1, 2), (3, 2)],
             4: [(3, 4)]
         },
         groupBy([(1, 2), (3, 4), (3, 2), (1, 1), (2, 1, 8)],
                 getKey=operator.itemgetter(1)))
Exemple #3
0
 def testKeyFunctionDefaultsToIdentity(self):
   self.assertEqual({1: [1],
                     2: [2]},
                    groupBy([1, 2]))
Exemple #4
0
 def testGivenTupleOfNamesOfAttributesGroupsByTheirCombination(self):
   self.assertEqual({(1, 1): [(1, 1)],
                     (1, 2): [(1, 2)],
                     (2, 1): [(2, 1)]},
                    groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], ('a', 'b')))
Exemple #5
0
 def testGivenNameOfAttributeGroupsByTheAttribute(self):
   self.assertEqual({1: [(1, 2), (1, 1)],
                     2: [(2, 1)]},
                    groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], 'a'))
Exemple #6
0
 def testGivenNoObjectsReturnsEmptyDict(self):
   self.assertEqual({},
                    groupBy([], getKey=lambda x: x[0] + x[1]))
Exemple #7
0
 def testGivenTypeAsKeyFunctionGroupsByItsResult(self):
   self.assertEqual({'2': [2, 2],
                     '3': [3]},
                    groupBy([2, 3, 2],
                            getKey=str))
Exemple #8
0
 def testGivenKeyFunctionAsPositionalAttributeGroupsByItsResult(self):
   self.assertEqual({2: [(0, 2), (1, 1), (1, 1)],
                     3: [(1, 2), (2, 1), (3, 0)]},
                    groupBy([(1, 2), (2, 1), (0, 2), (3, 0), (1, 1), (1, 1)],
                            lambda x: x[0] + x[1]))
Exemple #9
0
 def testRequiredKeysDoNotConflictWithKeysDefinedByInput(self):
     self.assertEqual({1: [1]}, groupBy([1], requiredKeys=[1]))
Exemple #10
0
 def testOutputAlwaysContainsRequiredKeys(self):
     self.assertEqual({1: [1], 'a': []}, groupBy([1], requiredKeys=['a']))
Exemple #11
0
 def testKeyFunctionDefaultsToIdentity(self):
     self.assertEqual({1: [1], 2: [2]}, groupBy([1, 2]))
Exemple #12
0
 def testGivenTupleOfNamesOfAttributesGroupsByTheirCombination(self):
     self.assertEqual({
         (1, 1): [(1, 1)],
         (1, 2): [(1, 2)],
         (2, 1): [(2, 1)]
     }, groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], ('a', 'b')))
Exemple #13
0
 def testGivenNameOfAttributeGroupsByTheAttribute(self):
     self.assertEqual({
         1: [(1, 2), (1, 1)],
         2: [(2, 1)]
     }, groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], 'a'))
Exemple #14
0
 def testGivenNoObjectsReturnsEmptyDict(self):
     self.assertEqual({}, groupBy([], getKey=lambda x: x[0] + x[1]))
Exemple #15
0
 def testGivenTypeAsKeyFunctionGroupsByItsResult(self):
     self.assertEqual({
         '2': [2, 2],
         '3': [3]
     }, groupBy([2, 3, 2], getKey=str))
Exemple #16
0
 def testOutputAlwaysContainsRequiredKeys(self):
   self.assertEqual({1: [1],
                     'a': []},
                    groupBy([1], requiredKeys=['a']))
Exemple #17
0
 def testRequiredKeysDoNotConflictWithKeysDefinedByInput(self):
   self.assertEqual({1: [1]},
                    groupBy([1], requiredKeys=[1]))
Exemple #18
0
 def testGivenKeyFunctionAsKeywordAttributeGroupsByItsResult(self):
   self.assertEqual({1: [(1, 1), (2, 1, 8)],
                     2: [(1, 2), (3, 2)],
                     4: [(3, 4)]},
                    groupBy([(1, 2), (3, 4), (3, 2), (1, 1), (2, 1, 8)],
                            getKey=operator.itemgetter(1)))