Commits

Guido Draheim committed 069cd0f

better unittest logging

Comments (0)

Files changed (2)

src/dvbcronrecording/computer.py

     if value is None: return default
     try: return int(value)
     except Exception: return default
+    
+def ustar(text):
+    if text is None:
+        return "*"
+    return u"%s" % text
 
 class ChainEntry:
     def __init__(self):
         item.adapter = self.adapter
         return item
     def __unicode__(self):
+        months = u",".join([unicode(month) for month in self.months])
         x = u"{ "
         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@%s" % (self.channelname, ustar(self.adapter))
+        x += u" (%s %s %s)" % (ustar(self.onlyday), ustar(months), ustar(self.weekday))
         x += u" '%s'" % (unicode(self.title))
         x += u" }"
         return x
     def recordinglist_to_recorderitems(self, entries, ahead = months_ahead):
         allowed_months = self.get_allowed_months(ahead)
         past_days = self.get_past_days_this_month()
-        self.logg.debug("allowed_months %s" % (str(allowed_months)))    
+        self.logg.debug("    allowed_months %s" % (str(allowed_months)))    
         for entry in entries:
             if entry.status == "no": 
-                self.logg.debug("status disabled for %s", entry.title) 
+                self.logg.debug("    status disabled for %s", entry.title) 
                 continue
             item = RecorderItem()
             item.channelname = entry.channelname
             item.title = entry.title
             if not item.title:
-                self.logg.debug("item had not title") 
+                self.logg.debug("    item had not title") 
                 continue            
             if not item.channelname: 
-                self.logg.debug("no channel name for '%s", item.title) 
+                self.logg.debug("    no channel name for '%s", item.title) 
                 continue            
             m = re.match("(\d+)[.](\d+)[.]", entry.onlydate)
             if m:
-                self.logg.debug("onlydate %s for %s", entry.onlydate, item.title)
+                self.logg.debug("    onlydate %s for %s", entry.onlydate, item.title)
                 try:
                     onlyday = intnull(m.group(1))
                     onlymonth = intnull(m.group(2))
                     if not onlyday: continue
                     if not onlymonth: continue
                     if onlymonth not in allowed_months:
-                        self.logg.debug("onlymonth not in allowed_months '%s'", item.title) 
+                        self.logg.debug("    onlymonth not in allowed_months '%s'", item.title) 
                         continue
                     if (onlyday, onlymonth) in past_days: 
-                        self.logg.debug("(onlyday, onlymonth) in past_days '%s'", item.title) 
+                        self.logg.debug("    (onlyday, onlymonth) in past_days '%s'", item.title) 
                         continue
                     item.onlyday = onlyday
                     item.months = [ onlymonth ]
-                    self.logg.debug("onlyday %s onlymonths %s for %s", item.onlyday, item.months, item.title)
+                    self.logg.debug("    onlyday %s onlymonths %s for %s", item.onlyday, item.months, item.title)
                 except Exception:
-                    self.logg.debug("conversion error %s '%s'", entry.onlydate, item.title)
+                    self.logg.debug("    conversion error %s '%s'", entry.onlydate, item.title)
                 item.weekday = intnull(entry.weekday)
             else: 
                 item.weekday = intnull(entry.weekday)
                 if item.weekday is None:
-                    self.logg.debug("item.weekday is None '%s'", item.title) 
+                    self.logg.debug("    item.weekday is None '%s'", item.title) 
                     continue
                 if item.weekday >= 7: item.weekday = item.weekday % 7
             item.newtimeMMM = self.zero(self.minutes(entry.newtime))
             except: pass
             if item.channelname in self.rankup_channels:
                 item.rank += self.rankup_value
-            self.logg.debug("originally %s-%s '%s'" % (entry.newtime, entry.endtime, item.title))
+            self.logg.debug("    originally %s-%s '%s'" % (entry.newtime, entry.endtime, item.title))
             yield item
     def recordinglist_to_recordergroups(self, entries, ahead = months_ahead):
         recorderitems = list(self.recordinglist_to_recorderitems(entries, ahead))
             for month in item.months: 
                 if month not in onlymonths:
                     onlymonths.append(month)
-        self.logg.debug("onlymonths %s", onlymonths)
+        self.logg.debug("    onlymonths %s", onlymonths)
         regularmonths = [ month for month in xrange(1,13) if month not in onlymonths ]
-        self.logg.debug("regularmonths %s", regularmonths)
+        self.logg.debug("    regularmonths %s", regularmonths)
         localtime = self.localtime()
         this_month = localtime.tm_mon
         this_year = localtime.tm_year
                     # no generate the recordings for that day
                     items = self.clone_filtered_for_date(recorderitems, date)
                     for group in self.recordergroups_from_filtered(items):
-                        self.logg.debug("onlydate group %s", unicode(group))
+                        self.logg.debug("    onlydate group %s", unicode(group))
                         yield group
                 except ValueError:
                     pass # expected
         self.logg.debug("=======================================================")
         items = list(items)
         for item in items:
-            self.logg.debug("regular item %s", unicode(item))
+            self.logg.debug("    regular item %s", unicode(item))
         for group in self.recordergroups_from_filtered(items):
-            self.logg.debug("regular group %s", unicode(group))
+            self.logg.debug("    regular group %s", unicode(group))
             yield group
     def clone_filtered_for_date(self, recorderitems, date):
         for item in recorderitems:
             of newtime-endtime is the recording time interval. """
         yield self.adjust_recordergroup(group) 
     def adjust_recordergroup(self, group):
-        self.logg.debug("adjust group %s", unicode(group))
+        self.logg.debug("    adjust group %s", unicode(group))
         nextday = 0
         previous = None
         for item in group.items:
             nextday = 0
         return group
     def make_cronmonths(self, group):
-        self.logg.debug("adjust group %s", unicode(group))
+        self.logg.debug("    adjust group %s", unicode(group))
         for item in group.items:
             ranges = []
             months = item.months
                 if date is None:
                     continue
                 try:
-                    # self.logg.debug("%s datetime(%s,%s,%s)", len(recorderitems), year, month, day)
+                    # 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
                             if date.month not in item.months: continue
                         else:
                             if item.weekday != date.weekday(): continue
-                        self.logg.debug("* %s => [%s.%s.] w%s '%s'", date, item.onlyday, item.months, item.weekday, item.title)
+                        # self.logg.debug("    ITEM %s", item)
                         newtimeMMM = item.newtimeMMM
                         endtimeMMM = item.endtimeMMM
                         if endtimeMMM < newtimeMMM: endtimeMMM += 24 * 60
         predeletes = []
         seen = ""
         for elem in timelist:
-            self.logg.debug("timelist_groups: adapter '%s' -vs- '%s'",
+            self.logg.debug("    timelist_groups: adapter '%s' -vs- '%s'",
                       adapter, elem.adapter)            
             if adapter is not None and elem.adapter is not None:
                 if adapter != elem.adapter:
         """ main entry point """
         self.logg.info("plan4")
         for elem in entries:
-            self.logg.debug("=0: %s", elem)
+            self.logg.debug("[0] %s", elem)
         timelist = list(self.recordinglist_to_recordertimelist(entries))
         for elem in timelist:
-            self.logg.debug("=1: %s", elem)
+            self.logg.debug("[1] %s", elem)
         self.assign_adapters_for_timelist(timelist)
         old_deleted = 0
         for round in xrange(2):
                 old_deleted = new_deleted
                 continue
         for elem in timelist:
-            self.logg.debug("=2: %s", elem)
+            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())
+        self.logg.info(" - adapterlist = %s", self.adapterlist())
         for elem in timelist:
-            self.logg.debug("=3: %s", elem)
+            self.logg.debug("[3] %s", elem)
         if True:
             plan.timelist_sort()
             return self.new_reduce_regular_groups(plan)

src/tests/computer_test.py

         res = self.computer.plan4(req, [a])
         self.logg.info("RESULT:%s", res)
         E = u"""
-{[{  [22:30-23:30]+0 ard@0 None([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])6 'ard1' }]}"""
+{[{  [22:30-23:30]+0 ard@0 (* 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")
         res = self.computer.plan4(req, [a])
         self.logg.info("RESULT:%s", res)
         E = u"""
-{[{  [22:30-23:30]+0 ard@0 22([4])6 'ard1' }]}"""
+{[{  [22:30-23:30]+0 ard@0 (22 4 6) 'ard1' }]}"""
         self.assertEqual(unicode(res), E)
     def test_10_2entries_samegroupandcontinue(self):
         a = Entry("ard","ard1","22:30","23:30","0", "", "22.04.", "ok")
         res = self.computer.plan4(req, [a, b])
         self.logg.info("RESULT:%s", res)
         E = u"""
-{[{  [22:30-23:30]+0 ard@0 22([4])6 'ard1' },
-  {  [23:30-00:30]+0 ard@0 22([4])6 'ard1' }]}"""
+{[{  [22:30-23:30]+0 ard@0 (22 4 6) 'ard1' },
+  {  [23:30-00:30]+0 ard@0 (22 4 6) 'ard1' }]}"""
         self.assertEqual(unicode(res), E)
     def test_11_2entries_differentgroups(self):
         a = Entry("ard","ard1","22:30","23:30","0", "", "22.04.", "ok")
         res = self.computer.plan4(req, [a, b])
         self.logg.info("RESULT:%s", res)
         E = u"""
-{[{  [22:30-23:30]+0 ard@0 22([4])6 'ard1' }],
- [{  [23:33-00:33]+0 ard@0 22([4])6 'ard1' }]}"""
+{[{  [22:30-23:30]+0 ard@0 (22 4 6) 'ard1' }],
+ [{  [23:33-00:33]+0 ard@0 (22 4 6) 'ard1' }]}"""
         self.assertEqual(unicode(res), E)
 
 if __name__ == "__main__":
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.