Beispiel #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)
Beispiel #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)
Beispiel #3
0
  def setUp(self):
    if self.ATTRS is None:
      self.skipTest('Tests declared in abstract class')

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