path: root/selftest/log_test.py
diff options
Diffstat (limited to 'selftest/log_test.py')
1 files changed, 30 insertions, 40 deletions
diff --git a/selftest/log_test.py b/selftest/log_test.py
index 7670c8e..9136906 100755
--- a/selftest/log_test.py
+++ b/selftest/log_test.py
@@ -32,20 +32,20 @@ log.style_change(time=True, time_fmt=fake_time)
print('- Testing global log functions')
-log.log('<origin>', log.C_TST, 'from log.log()')
-log.dbg('<origin>', log.C_TST, 'from log.dbg(), not seen')
+log.log('from log.log()', _origin='<origin>', _category=log.C_TST)
+log.dbg('from log.dbg(), not seen', _origin='<origin>', _category=log.C_TST)
log.set_level(log.C_TST, log.L_DBG)
-log.dbg('<origin>', log.C_TST, 'from log.dbg()')
+log.dbg('from log.dbg()', _origin='<origin>', _category=log.C_TST)
log.set_level(log.C_TST, log.L_LOG)
-log.err('<origin>', log.C_TST, 'from log.err()')
+log.err('from log.err()', _origin='<origin>', _category=log.C_TST)
print('- Testing log.Origin functions')
class LogTest(log.Origin):
- pass
+ def __init__(self, *name_items, **detail_items):
+ super().__init__(log.C_TST, *name_items, **detail_items)
+t = LogTest('some', 'name', some="detail")
-t = LogTest()
-t.set_name('some', 'name', some="detail")
t.log("hello log")
t.err("hello err")
@@ -86,10 +86,10 @@ t.dbg("add src")
t.dbg("add origin")
+# some space to keep source line numbers identical to previous code
print('- Testing origin_width')
-t = LogTest()
+t = LogTest('shortname')
log.style(origin_width=23, time_fmt=fake_time)
t.log("origin str set to 23 chars")
t.set_name('very long name', some='details', and_some=(3, 'things', 'in a tuple'))
@@ -97,16 +97,16 @@ t.log("long origin str")
t.dbg("long origin str dbg")
t.err("long origin str err")
print('- Testing log.Origin with omitted info')
t = LogTest()
t.log("hello log, name implicit from class name")
-t = LogTest()
+t = LogTest('explicit_name')
t.log("hello log, no category set")
t = LogTest()
t.log("hello log, no category nor name set")
t.dbg("hello log, no category nor name set, not seen")
log.set_level(log.C_DEFAULT, log.L_DBG)
@@ -117,47 +117,37 @@ log.style(time_fmt=fake_time, origin_width=0)
class Thing(log.Origin):
def __init__(self, some_path):
- self.set_log_category(log.C_TST)
- self.set_name(some_path)
+ super().__init__(log.C_TST, some_path)
def say(self, msg):
-with Thing('print_redirected'):
- print("Not throwing an exception in 'with:' works.")
+ def l1(self):
+ level2 = Thing('level2')
+ level2.l2()
-def l1():
- level1 = Thing('level1')
- with level1:
- l2()
-def l2():
- level2 = Thing('level2')
- with level2:
- l3(level2)
+ def l2(self):
+ level3 = Thing('level3')
+ level3.l3(self)
-def l3(level2):
- level3 = Thing('level3')
- with level3:
+ def l3(self, level2):
print('nested print just prints')
- level3.log('nested log()')
+ self.log('nested log()')
level2.log('nested l2 log() from within l3 scope')
raise ValueError('bork')
- l1()
+ level1 = Thing('level1')
+ level1.l1()
except Exception:
-print('- Enter the same Origin context twice')
+print('- Disallow origin loops')
t = Thing('foo')
- with t:
- with t:
- raise RuntimeError('this should not be reached')
-except AssertionError:
+ t._set_parent(t)
+ raise RuntimeError('this should not be reached')
+except log.OriginLoopError:
print('disallowed successfully')