ignore flags in testing of follow; added comments
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 19 Oct 2015 07:22:56 +0000 (09:22 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 19 Oct 2015 07:22:56 +0000 (09:22 +0200)
follow.py

index 72f2007..c35a354 100644 (file)
--- a/follow.py
+++ b/follow.py
@@ -194,7 +194,8 @@ class Follower(object):
         output and are used in error messages
 
         Sources must be file handles, open pipes or open sockets (or anything
-        else that gives a reasonable fileno(), so help of the select module)
+        else that gives a reasonable fileno(), so help of the :py:mod:`select`
+        module)
 
         Sources are not closed!
 
@@ -287,6 +288,7 @@ class Follower(object):
                     warn('poll replied "invalid request" err during polling '
                          'for {0}'
                          .format(desc))
+
                 # read line from source
                 line = source.readline()
 
@@ -353,6 +355,9 @@ class FollowContextManager(object):
         :param proc_descs: None or list/tuple of same length as procs
         :param dict subprocess_args: dict or args that are merged with
                                      :py:data:`DEFAULT_SUBPROCESS_ARGS`
+
+        ..seealso:: could have tried to implement this as a nesting of many
+                    individual context managers, see :py:mod:`contextlib`
         """
         print('__init__')
 
@@ -530,6 +535,8 @@ def follow(*args, **kwargs):
 
 # #############################################################################
 # TESTING
+# (hard to create unittest -- would need separate threads to write to some
+#  file /pipe/socket so can test the interactivity...)
 # #############################################################################
 
 from datetime import date, datetime as dt, timedelta as td
@@ -579,6 +586,8 @@ def test_follower_syslog():
         flwr = Follower(file_handle, 'syslog file', proc.stdout, 'tail syslog',
                         proc.stderr, 'tail stderr')
         for n_lines, (source, desc, line, flags) in enumerate(flwr):
+            if flags:
+                print('received flags {0}'.format(flags_to_str(flags)))
             test_syslog_line(n_lines, source, desc, line,
                              today_str, start_time)
 
@@ -592,6 +601,8 @@ def test_follower_context():
     start_time = dt.now() - td(seconds=time_diff_seconds)
     with follow(syslog_file) as flwr:
         for n_lines, (source, desc, line, flags) in enumerate(flwr):
+            if flags:
+                print('received flags {0}'.format(flags_to_str(flags)))
             test_syslog_line(n_lines, source, desc, line,
                              today_str, start_time)
 
@@ -604,6 +615,8 @@ def test_context_proc():
     start_time = dt.now() - td(seconds=time_diff_seconds)
     with follow(procs=(['tail', '-f', syslog_file], )) as flwr:
         for n_lines, (source, desc, line, flags) in enumerate(flwr):
+            if flags:
+                print('received flags {0}'.format(flags_to_str(flags)))
             test_syslog_line(n_lines, source, desc, line,
                              today_str, start_time)