Commits

Guido Draheim committed abfd546

adjust timestamp for allowed_months / past_days in unittest

Comments (0)

Files changed (3)

 	   test $(CHECK)
 check:
 	PYTHONPATH=src \
-	python src/tests/computer_test.py -v $(CHECK)
+	python src/tests/computer_test.py -vv $(CHECK)
 test_%:
 	@ func=`grep "def $@" src/tests/computer_test.py \
 	    | sed -e "s/.*def  *//" -e "s/[(].*//" -e q` \

src/dvbcronrecording/computer.py

         return item
     def __unicode__(self):
         x = u"{ "
-        x += u" %s[%s-%s]" % (self.channelname, MMMtoHHMM(self.newtimeMMM), MMMtoHHMM(self.endtimeMMM))
-        x += u"%s@%s" % (self.extratimeM, self.adapter)
+        x += u" [%s-%s]+%s" % (MMMtoHHMM(self.newtimeMMM), MMMtoHHMM(self.endtimeMMM), self.extratimeM)
+        x += u" %s@%s" % (self.channelname, self.adapter)
         x += u" %s(%s)%s" % (self.onlyday, unicode(self.months), self.weekday)
         x += u" '%s'" % (unicode(self.title))
         x += u" }"
     def __init__(self):
         self._adapters = {}
         self._adapterlist = None
+        self._localtime = None
         self.logg = logging.getLogger(__name__)
-    
+    def localtime(self):
+        if self._localtime is not None:
+            return self._localtime # for unittests
+        return time.localtime()
     def adapters(self, channelname):
         if channelname in self._adapters:
             return self._adapters[channelname]
             if month < this_month: year += 1
             for day in xrange(1,32):
                 if (day, month) in past_days: continue
+                date = None
                 try:
                     # ValueError if invalid day-of-month
                     date = datetime.datetime(year, month, day)
+                except ValueError, e:
+                    pass
+                if date is None:
+                    continue
+                try:
+                    # self.logg.debug("%s datetime(%s,%s,%s)", len(recorderitems), year, month, day)
                     for item in recorderitems:
+                        self.logg.debug("ITEM %s", item)
                         if item.onlyday: 
                             if item.onlyday != date.day: continue
                             if date.month not in item.months: continue
                         elem.adapters = self.adapters(item.channelname)
                         # elem.message += " (([%s .. %s] from %s..%s))" % (elem.datetimeX, elem.datetimeY, newtimeMMM, endtimeMMM)
                         yield elem
+                except Exception, e:
+                    self.logg.error("ERROR %s", e)
                 except:
-                    pass
+                    self.logg.error("FATAL ERROR")
     def adjust_recordertimelist(self, req, recordertimelist, adapter = None):
         """ recordertimelist contains absolute X Y dates """
         _ = Translate(PACKAGE, req.locale)
     def plan4(self, req, entries):
         """ main entry point """
         self.logg.info("plan4")
+        for elem in entries:
+            self.logg.debug("=0: %s", elem)
         timelist = list(self.recordinglist_to_recordertimelist(entries))
+        for elem in timelist:
+            self.logg.debug("=1: %s", elem)
         self.assign_adapters_for_timelist(timelist)
         old_deleted = 0
         for round in xrange(2):
             if old_deleted < new_deleted:
                 old_deleted = new_deleted
                 continue
+        for elem in timelist:
+            self.logg.debug("=2: %s", elem)
         timelist = sorted(timelist, key = lambda x: x.datetimeX )
         plan = RecorderGroupPlan()
         for adapter in self.adapterlist():
             for group in self.timelist_groups(req, timelist, adapter):
                 plan.addgroup(group)
         self.logg.info("adapterlist = %s", self.adapterlist())
+        for elem in timelist:
+            self.logg.debug("=3: %s", elem)
         if True:
             plan.timelist_sort()
             return self.new_reduce_regular_groups(plan)

src/tests/computer_test.py

 import unittest
+import time
 
 import logging
 _logg = logging.getLogger("TESTS")
             self.env = ComponentManager() 
         self.computer = DvbCronRecordingPlanComputer(self.env)
         self.computer.logg = _logg
+        self.computer._localtime = time.localtime(1334887400)
     def test_01_options(self):
         self.assertEqual("plan4", self.computer.algorithm, )
         self.assertTrue("3sat" in self.computer.rankup_channels)
         req = Request(Locale("de"))
         res = self.computer.plan4(req, [a])
         self.logg.info("\n%s", res)
-        E = u"{[{  ard[22:30-23:30]0@0 None([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])6 'ard1' }]}"
+        E = u"{[{  [22:30-23:30]+0 ard@0 None([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])6 'ard1' }]}"
         self.assertEqual(unicode(res), E)
     def test_04_entries(self):
         a = Entry("ard","ard1","22:30","23:30","0", "", "22.04.", "ok")
         self.assertEqual(unicode(res), E)
 
 if __name__ == "__main__":
+    import sys
+    for arg in sys.argv:
+        if arg.startswith("-vv"):
+            print "log level DEBUG"
+            _logg.setLevel(logging.DEBUG)
     unittest.main()