def test_computeAvailableRights_withNShares_multiplies(self):
     rights = RightsPerShare(self.db)
     remainders = RemainderProviderMockup([
         (1, isodate('2015-08-16'), 0),
         (2, isodate('2015-08-16'), 0),
         ])
     production = ProductionAggregatorMockUp(
             first=isodate('2015-08-16'),
             last=isodate('2015-08-16'),
             data=numpy.array(+10*[0]+[1]+14*[0]))
     plantShare = PlantShareCurverMockup(
             data=numpy.array(25*[1]))
     l = ProductionLoader(productionAggregator=production,
             plantShareCurver=plantShare,
             rightsPerShare=rights,
             remainders=remainders)
     l.computeAvailableRights()
     result = rights.rightsPerShare(2,
         isodate('2015-08-16'),
         isodate('2015-08-16'))
     self.assertEqual(list(result),
         +10*[0]+[2]+14*[0])
     self.assertEqual(remainders.lastRemainders(), [
         (1, isodate('2015-08-17'), 0),
         (2, isodate('2015-08-17'), 0),
         ])
 def assertStartPointEqual(self, firstProductionDate, remainders, expected):
     l = ProductionLoader()
     date = l.startPoint(isodate(firstProductionDate),[
         (shares, isodate(date), remainderwh)
         for shares, date, remainderwh in remainders
         ])
     self.assertEqual(str(date), expected)
 def test_getRecomputationInterval_withNoremainders_takesFirstMeassure(self):
     p = ProductionAggregatorMockUp(
             first=isodate('2000-01-01'),
             last=isodate('2006-01-01'),
             )
     l = ProductionLoader(productionAggregator=p)
     interval = l._recomputationInterval([])
     self.assertDatePairEqual( ('2000-01-01','2006-01-01'), interval)
 def test_getRecomputationInterval_withSingleRemainders_takesIt(self):
     p = ProductionAggregatorMockUp(
             first=isodate('2000-01-01'),
             last=isodate('2006-01-01'),
             )
     l = ProductionLoader(productionAggregator=p)
     interval = l._recomputationInterval([
         (1,isodate('2001-01-01'), 45),
         ])
     self.assertDatePairEqual( ('2001-01-01','2006-01-01'), interval)
 def test_appendRightsPerShare_crossedDates(self):
     rights = RightsPerShare(self.db)
     remainders = RemainderProviderMockup([])
     l = ProductionLoader(rightsPerShare=rights, remainders=remainders)
     with self.assertRaises(AssertionError) as ctx:
         l._appendRightsPerShare(
             nshares=1,
             firstDateToCompute=isodate('2015-08-16'),
             lastDateToCompute=isodate('2015-08-15'),
             lastRemainder=0,
             production=numpy.array(50*[1]),
             plantshares=numpy.array(50*[1]),
             )
     self.assertEqual(ctx.exception.args[0],
         "Empty interval starting at 2015-08-16 and ending at 2015-08-15")
 def test_appendRightsPerShare_tooSmallShareArray(self):
     rights = RightsPerShare(self.db)
     remainders = RemainderProviderMockup([])
     l = ProductionLoader(rightsPerShare=rights, remainders=remainders)
     with self.assertRaises(AssertionError) as ctx:
         l._appendRightsPerShare(
             nshares=1,
             firstDateToCompute=isodate('2015-08-16'),
             lastDateToCompute=isodate('2015-08-17'),
             lastRemainder=0,
             production=numpy.array(50*[1]),
             plantshares=numpy.array(49*[1]),
             )
     self.assertEqual(ctx.exception.args[0],
         "Not enough plant share data to compute such date interval")
 def test_appendRightsPerShare_lastDateToCompute_isProtected(self):
     l = ProductionLoader()
     with self.assertRaises(AssertionError) as ctx:
         l._appendRightsPerShare(
             nshares=1,
             firstDateToCompute=isodate('2015-08-16'),
             lastDateToCompute=localisodate('2015-08-16'), # here
             lastRemainder=0,
             production=numpy.array(25*[1]),
             plantshares=numpy.array(25*[1]),
             )
     # also non CEST/CET, and naive, using assertLocalDateTime
     self.assertEqual(ctx.exception.args[0],
         "lastDateToCompute should be a datetime.date but it is "
         "2015-08-16 00:00:00+02:00")
 def test_appendRightsPerShare_withAdvancedRemainder(self):
     rights = RightsPerShare(self.db)
     remainders = RemainderProviderMockup([])
     l = ProductionLoader(rightsPerShare=rights, remainders=remainders)
     l._appendRightsPerShare(
         nshares=1,
         firstDateToCompute=isodate('2015-08-16'),
         lastDateToCompute=isodate('2015-08-16'),
         lastRemainder=0,
         production=numpy.array(100*[0]+10*[0]+[1000]+14*[0]),
         plantshares=numpy.array(100*[0]+25*[1]),
         )
     result = rights.rightsPerShare(1,
         isodate('2015-08-16'),
         isodate('2015-08-16'))
     self.assertEqual(list(result),
         +10*[0]+[1000]+14*[0])
     self.assertEqual(remainders.lastRemainders(), [
         (1, isodate('2015-08-17'), 0),
         ])
 def test_endPoint_withHalfADay_justReturnsTheWholeOnes(self):
     l = ProductionLoader()
     date = l.endPoint(isodate('2000-01-01'), 27*[0])
     self.assertEqual('2000-01-02', str(date))
 def test_endPoint_withOneDay(self):
     l = ProductionLoader()
     date = l.endPoint(isodate('2000-01-01'), 25*[0])
     self.assertEqual('2000-01-02', str(date))
 def test_endPoint_withNoProduction(self):
     l = ProductionLoader()
     date = l.endPoint(isodate('2000-01-01'), [])
     self.assertEqual('2000-01-01', str(date))