Skip to content

Commit

Permalink
Issue 27: add stdoutflag and stderrflag (#28)
Browse files Browse the repository at this point in the history
* change info printouts to debug ones

* change default stdflag to false

* set default stderrflag

* bump the version and update tests
  • Loading branch information
jkotan authored Nov 30, 2021
1 parent aa6bdb0 commit d76eeca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-11-29 Jan Kotanski <jankotan@gmail.com>
* add stderrflag for error streams
* add stdoutflag for output streams
* tagged as v2.14.0

2020-04-22 Jan Kotanski <jankotan@gmail.com>
* add checks if selection is JSON
* add checks if xmlstring is XML
Expand Down
2 changes: 1 addition & 1 deletion nxsconfigserver/Release.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
""" release version module """

#: version number
__version__ = "2.13.2"
__version__ = "2.14.0"
17 changes: 12 additions & 5 deletions nxsconfigserver/StreamSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
import weakref


# (:obj:`bool`) write stream to stdout
stdoutflag = False

# (:obj:`bool`) write stream to stderrr
stderrflag = True


class StreamSet(object):

def __init__(self, streams):
Expand Down Expand Up @@ -59,7 +66,7 @@ def __init__(self, streams):
if hasattr(streams(), "log_debug"):
self.log_debug = streams().log_debug

def fatal(self, message, std=True):
def fatal(self, message, std=stderrflag):
""" writes fatal error message
:param message: error message
Expand All @@ -77,7 +84,7 @@ def fatal(self, message, std=True):
except Exception:
print(message)

def error(self, message, std=True):
def error(self, message, std=stderrflag):
""" writes error message
:param message: error message
Expand All @@ -95,7 +102,7 @@ def error(self, message, std=True):
except Exception:
print(message)

def warn(self, message, std=True):
def warn(self, message, std=stderrflag):
""" writes warning message
:param message: warning message
Expand All @@ -113,7 +120,7 @@ def warn(self, message, std=True):
except Exception:
print(message)

def info(self, message, std=True):
def info(self, message, std=stdoutflag):
""" writes info message
:param message: info message
Expand All @@ -131,7 +138,7 @@ def info(self, message, std=True):
except Exception:
print(message)

def debug(self, message, std=True):
def debug(self, message, std=stdoutflag):
""" writes debug message
:param message: debug message
Expand Down
20 changes: 10 additions & 10 deletions test/StreamSet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ def test_info(self):
name = self.getRandomString(100)
sys.stdout = self.mystdout = StringIO()
sys.stderr = self.mystderr = StringIO()
if i % 2:
self.streams.info(name)
else:
self.streams.info(name, std=True)
self.streams.info(name, std=True)
self.assertEqual(self.streams.log_fatal, None)
self.assertEqual(self.streams.log_error, None)
self.assertEqual(self.streams.log_warn, None)
Expand All @@ -353,7 +350,10 @@ def test_info_nostd(self):
name = self.getRandomString(100)
sys.stdout = self.mystdout = StringIO()
sys.stderr = self.mystderr = StringIO()
self.streams.info(name, std=False)
if i % 2 == 0:
self.streams.info(name)
else:
self.streams.info(name, std=False)
self.assertEqual(self.streams.log_fatal, None)
self.assertEqual(self.streams.log_error, None)
self.assertEqual(self.streams.log_warn, None)
Expand Down Expand Up @@ -401,10 +401,7 @@ def test_debug(self):
name = self.getRandomString(100)
sys.stdout = self.mystdout = StringIO()
sys.stderr = self.mystderr = StringIO()
if i % 2:
self.streams.debug(name)
else:
self.streams.debug(name, std=True)
self.streams.debug(name, std=True)
self.assertEqual(self.streams.log_fatal, None)
self.assertEqual(self.streams.log_error, None)
self.assertEqual(self.streams.log_warn, None)
Expand All @@ -422,7 +419,10 @@ def test_debug_nostd(self):
name = self.getRandomString(100)
sys.stdout = self.mystdout = StringIO()
sys.stderr = self.mystderr = StringIO()
self.streams.debug(name, std=False)
if i % 2:
self.streams.debug(name)
else:
self.streams.debug(name, std=False)
self.assertEqual(self.streams.log_fatal, None)
self.assertEqual(self.streams.log_error, None)
self.assertEqual(self.streams.log_warn, None)
Expand Down

0 comments on commit d76eeca

Please sign in to comment.