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_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_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_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),
         ])