[pypy-svn] r68809 - in pypy/branch/logging/pypy/rlib: . test

arigo at codespeak.net arigo at codespeak.net
Wed Oct 28 12:01:36 CET 2009


Author: arigo
Date: Wed Oct 28 12:01:35 2009
New Revision: 68809

Modified:
   pypy/branch/logging/pypy/rlib/rlog.py
   pypy/branch/logging/pypy/rlib/rlog_parsing.py
   pypy/branch/logging/pypy/rlib/test/test_rlog.py
Log:
Avoid printing '(null)' even for empty strings.
Accept both high-level and low-level strings.


Modified: pypy/branch/logging/pypy/rlib/rlog.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog.py	(original)
+++ pypy/branch/logging/pypy/rlib/rlog.py	Wed Oct 28 12:01:35 2009
@@ -260,12 +260,19 @@
     def add_subentry_d(self, num):
         self.write_int(num)
 
-    def add_subentry_s(self, llstr):
-        if llstr:
-            s = hlstr(llstr)
+    def add_subentry_s(self, s):
+        if s is None:
+            s = '(null)'     # 's' is a high-level string -- but None right now
+        elif isinstance(s, str):
+            pass             # 's' is already a high-level string
         else:
-            s = '(null)'
+            # in this case, assume that 's' is a low-level string
+            if s:
+                s = hlstr(s)
+            else:
+                s = '(null)'
         self.write_str(s)
+    add_subentry_s._annspecialcase_ = 'specialize:argtype(1)'
 
     add_subentry_r = add_subentry_s
 

Modified: pypy/branch/logging/pypy/rlib/rlog_parsing.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog_parsing.py	(original)
+++ pypy/branch/logging/pypy/rlib/rlog_parsing.py	Wed Oct 28 12:01:35 2009
@@ -84,7 +84,7 @@
         try:
             printcode = cat.printcode
         except AttributeError:
-            code = cat.category + ' '
+            code = '[%s] ' % cat.category
             message = cat.message.replace('\n', '\n' + ' '*len(code))
             message = r_replace.sub("%", message)
             printcode = cat.printcode = code + message

Modified: pypy/branch/logging/pypy/rlib/test/test_rlog.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/test/test_rlog.py	(original)
+++ pypy/branch/logging/pypy/rlib/test/test_rlog.py	Wed Oct 28 12:01:35 2009
@@ -81,7 +81,7 @@
     logwriter = MyLogWriter()
     call = cat.gen_call(logwriter)
     call(515, llstr("hellooo"))
-    call(2873, llstr("woooooorld"))
+    call(2873, "woooooorld")
     #
     assert logwriter.content == [
         ord('R'), ord('L'), ord('o'), ord('g'), ord('\n'), -1, 1.0,
@@ -216,6 +216,8 @@
         rlog.debug_log("Aa", "hello %(foo)d %(bar)f", foo=x+1, bar=x+0.5)
         rlog.debug_log("Ab", "<<%(baz)s>>", baz="hi there")
         rlog.debug_log("Ac", "[%(foo)r]", foo="\x00")
+        rlog.debug_log("Ac", "[%(foo)r]", foo="")
+        rlog.debug_log("Ac", "[%(foo)r]", foo=None)
         assert rlog.has_log()
 
     def setup_method(self, _):
@@ -233,17 +235,17 @@
 
     def check_result(self):
         entries = list(rlog_parsing.parse_log(self.pypylog))
-        assert len(entries) == 4
+        assert len(entries) == 6
         #
-        assert isinstance(entries[0][0], float)
-        assert isinstance(entries[1][0], float)
-        assert isinstance(entries[2][0], float)
-        assert isinstance(entries[3][0], float)
+        for entry in entries:
+            assert isinstance(entry[0], float)
         #
         Aa = entries[0][1]
         Ab = entries[2][1]
         Ac = entries[3][1]
         assert entries[1][1] is Aa
+        assert entries[4][1] is Ac
+        assert entries[5][1] is Ac
         assert Aa.category == 'Aa'
         assert Aa.message == 'hello %(foo)d %(bar)f'
         assert Aa.entries == [('foo', 'd'), ('bar', 'f')]
@@ -258,6 +260,8 @@
         assert entries[1][2] == [133, 132.5]
         assert entries[2][2] == ['hi there']
         assert entries[3][2] == ['\x00']
+        assert entries[4][2] == ['']
+        assert entries[5][2] == ['(null)']
 
     def test_interpret_f(self):
         interpret(self.f.im_func, [132], malloc_check=False)



More information about the Pypy-commit mailing list