Exemple #1
0
class GivenAggregatorExtendedWithDecoratorGetKey(GivenEmptyAggregatorAsClassAttribute):
  aggregator = Aggregator()
  NUMBER_SEQUENCE_RESULT = Ens({'1': [1], '2': [2, 2]})

  toStr = str

  @aggregator.getKey
  def getKey(self, obj):
    return self.toStr(obj)
Exemple #2
0
class GivenAggregatorExtendedWithDecoratorAggregateFunction(GivenEmptyAggregatorAsClassAttribute):
  aggregator = Aggregator()
  NUMBER_SEQUENCE_RESULT = Ens({1: 1, 2: 4})

  process = sum

  @aggregator.aggregateFunction
  def aggregateFunction(self, obj):
    return self.process(obj)
Exemple #3
0
  def setUp(self):
    if self.ATTRS is None:
      self.skipTest('Tests declared in abstract class')

    self.ens = Ens(**self.ATTRS)
Exemple #4
0
class GivenEmptyAggregatorAsClassAttribute(TestAggregatorBase):
  aggregator = Aggregator()
  EMPTY_SEQUENCE_RESULT = Ens()
  NUMBER_SEQUENCE_RESULT = Ens({1: [1], 2: [2, 2]})
Exemple #5
0
class GivenAggregateWithAggregateFunction(GivenAggregateWithNoArguments):
  AGGREGATOR_PARAMETERS = {'aggregateFunction': sum}
  NUMBER_SEQUENCE_RESULT = Ens({1: 1, 2: 4})
Exemple #6
0
 def testEqualEnsOfSameMembers(self):
   other = Ens(self.ATTRS)
   self.assertTrue(self.ens == other)
   self.assertFalse(self.ens != other)
Exemple #7
0
 def testMapOverMultipleEnsReturnsAggregatedEns(self):
   self.checkEnsEqual({'x': 4},
                      Ens.map(max, Ens(x=1), Ens(x=4)))
Exemple #8
0
class GivenAggregateWithCallableGetKey(GivenAggregateWithNoArguments):
  AGGREGATOR_PARAMETERS = {'getKey': str}
  NUMBER_SEQUENCE_RESULT = Ens({'1': [1], '2': [2, 2]})
Exemple #9
0
 def testHasAttributeWhenInitializedWithEns(self):
   self.assertEqual(123,
                    Ens(Ens(attr=123)).attr)
Exemple #10
0
 def testRaisesAmbiguousInitializationErrorWhenInitializedAmbiguously(self):
   with self.assertRaises(Ens.AmbiguousInitializationError):
     Ens({'attr': 123}, attr=42)
Exemple #11
0
 def testHasAttributeWhenInitializedWithDict(self):
   self.assertEqual(123,
                    Ens({'attr': 123}).attr)
Exemple #12
0
 def setUp(self):
   self.ens = Ens(self.ATTRS)
Exemple #13
0
 def testNotEqualEnsOfDifferentMembers(self):
   other = Ens(self.ens, otherMember='a')
   self.assertTrue(self.ens != other)
   self.assertFalse(self.ens == other)
Exemple #14
0
class GivenAggregatorWithRequiredKeysAsClassAttribute(TestAggregatorBase):
  aggregator = Aggregator(requiredKeys=['a', 'b'])
  EMPTY_SEQUENCE_RESULT = Ens(a=[], b=[])
  NUMBER_SEQUENCE_RESULT = Ens({1: [1], 2: [2, 2], 'a': [], 'b': []})
Exemple #15
0
 def testMapOverMultipleEnsWithMissingValuesReturnsAggregatedEns(self):
   self.checkEnsEqual({'x': (None, 4)},
                      Ens.map(lambda a, b: (a, b), Ens(), Ens(x=4)))
Exemple #16
0
class GivenAggregateWithNoArguments(TestGivenAggregator):
  AGGREGATOR_PARAMETERS = {}
  EMPTY_SEQUENCE_RESULT = Ens()
  NUMBER_SEQUENCE_RESULT = Ens({1: [1], 2: [2, 2]})
Exemple #17
0
 def testMapAcceptsDictsAsInput(self):
   self.checkEnsEqual({'x': '42'},
                      Ens.map(str, {'x': 42}))
Exemple #18
0
class GivenAggregateWithStringGetKey(GivenAggregateWithNoArguments):
  AGGREGATOR_PARAMETERS = {'getKey': '__class__.__name__'}
  NUMBER_SEQUENCE_RESULT = Ens({'int': [2, 1, 2]})
Exemple #19
0
 def setUp(self):
   self.mapping = Ens.asMapping(Ens(self.ATTRS))
Exemple #20
0
class GivenAggregateWithRequiredKeys(TestGivenAggregator):
  AGGREGATOR_PARAMETERS = {'requiredKeys': ['a', 'b']}
  EMPTY_SEQUENCE_RESULT = Ens(a=[], b=[])
  NUMBER_SEQUENCE_RESULT = Ens({1: [1], 2: [2, 2], 'a': [], 'b': []})
Exemple #21
0
 def testMappedChangesAttributes(self):
   self.checkEnsEqual(dict((k, str(v)) for (k, v) in self.ATTRS.items()),
                      Ens.map(str, self.ens))