This is an automated email from the ASF dual-hosted git repository.

chug pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/main by this push:
     new 46a580e  DISPATCH-1985: Update Logger class in system_test
46a580e is described below

commit 46a580e7c9c309ee18dbd124ea8996d339138aa8
Author: Chuck Rolke <[email protected]>
AuthorDate: Tue Apr 6 10:23:33 2021 -0400

    DISPATCH-1985: Update Logger class in system_test
    
    Move new Logger out of tcp adaptor test and into system_test.
---
 tests/system_test.py              | 16 +++++++++---
 tests/system_tests_tcp_adaptor.py | 55 ++++++---------------------------------
 2 files changed, 21 insertions(+), 50 deletions(-)

diff --git a/tests/system_test.py b/tests/system_test.py
index 35d3860..bc317a8 100755
--- a/tests/system_test.py
+++ b/tests/system_test.py
@@ -1387,13 +1387,19 @@ class Logger(object):
     """
     Record an event log for a self test.
     May print per-event or save events to be printed later.
+    Optional file opened in 'append' mode to which each log line is written.
     """
 
-    def __init__(self, title="Logger", print_to_console=False, 
save_for_dump=True):
+    def __init__(self,
+                 title="Logger",
+                 print_to_console=False,
+                 save_for_dump=True,
+                 ofilename=None):
         self.title = title
         self.print_to_console = print_to_console
         self.save_for_dump = save_for_dump
         self.logs = []
+        self.ofilename = ofilename
 
     def log(self, msg):
         ts = Timestamp()
@@ -1402,14 +1408,18 @@ class Logger(object):
         if self.print_to_console:
             print("%s %s" % (ts, msg))
             sys.stdout.flush()
+        if self.ofilename is not None:
+            with open(self.ofilename, 'a') as f_out:
+                f_out.write("%s %s\n" % (ts, msg))
+                f_out.flush()
 
     def dump(self):
         print(self)
         sys.stdout.flush()
 
+    @property
     def __str__(self):
-        lines = []
-        lines.append(self.title)
+        lines = [self.title]
         for ts, msg in self.logs:
             lines.append("%s %s" % (ts, msg))
         res = str('\n'.join(lines))
diff --git a/tests/system_tests_tcp_adaptor.py 
b/tests/system_tests_tcp_adaptor.py
index 3fc27dd..277cbbe 100644
--- a/tests/system_tests_tcp_adaptor.py
+++ b/tests/system_tests_tcp_adaptor.py
@@ -28,11 +28,15 @@ import sys
 import time
 import traceback
 
-from system_test import TestCase, Qdrouterd, main_module, TIMEOUT
-from system_test import Timestamp
-from system_test import unittest
-from system_test import SkipIfNeeded
+from system_test import Logger
+from system_test import main_module
 from system_test import Process
+from system_test import Qdrouterd
+from system_test import SkipIfNeeded
+from system_test import TestCase
+from system_test import TIMEOUT
+from system_test import unittest
+
 from subprocess import PIPE
 
 # Tests in this file are organized by classes that inherit TestCase.
@@ -85,49 +89,6 @@ Q2_DELAY_SECONDS = 1.0
 Q2_TEST_MESSAGE_SIZE = 10000000
 
 
-class Logger():
-    """
-    Record event logs as existing Logger. Also add:
-    * ofile  - optional file opened in 'append' mode to which each log line is 
written
-    TODO: Replace system_test Logger with this after merging 
dev-protocol-adaptors branch
-    """
-
-    def __init__(self,
-                 title="Logger",
-                 print_to_console=False,
-                 save_for_dump=True,
-                 ofilename=None):
-        self.title = title
-        self.print_to_console = print_to_console
-        self.save_for_dump = save_for_dump
-        self.logs = []
-        self.ofilename = ofilename
-
-    def log(self, msg):
-        ts = Timestamp()
-        if self.save_for_dump:
-            self.logs.append((ts, msg))
-        if self.print_to_console:
-            print("%s %s" % (ts, msg))
-            sys.stdout.flush()
-        if self.ofilename is not None:
-            with open(self.ofilename, 'a') as f_out:
-                f_out.write("%s %s\n" % (ts, msg))
-                f_out.flush()
-
-    def dump(self):
-        print(self)
-        sys.stdout.flush()
-
-    @property
-    def __str__(self):
-        lines = [self.title]
-        for ts, msg in self.logs:
-            lines.append("%s %s" % (ts, msg))
-        res = str('\n'.join(lines))
-        return res
-
-
 class TcpAdaptor(TestCase):
     """
     6 edge routers connected via 3 interior routers.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to