summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2014-02-13 13:02:00 +0100
committerMichal Minar <miminar@redhat.com>2014-02-13 14:41:33 +0100
commit378e5c184d3f14682a410767c56f56845e9f065f (patch)
tree1077b4a3d582e1ea078ab21e4b8d294482a85d65
parentdfcf21b3b6209f454158c9bc8702c682fed7e19b (diff)
downloadopenlmi-scripts-378e5c184d3f14682a410767c56f56845e9f065f.tar.gz
openlmi-scripts-378e5c184d3f14682a410767c56f56845e9f065f.tar.xz
openlmi-scripts-378e5c184d3f14682a410767c56f56845e9f065f.zip
tests: added tests for logging
-rw-r--r--test/cmd/help_foo.out2
-rw-r--r--test/cmd/help_test.out1
-rw-r--r--test/imode/cd_test.exp8
-rw-r--r--test/imode/completion.exp2
-rw-r--r--test/imode/eof.exp2
-rw-r--r--test/imode/help_foo.out2
-rw-r--r--test/imode/help_test.out1
-rw-r--r--test/imode/test_help.out1
-rw-r--r--test/imode/test_help_show.out1
-rw-r--r--test/imode/test_opt_help.out1
-rw-r--r--test/logging/defaults.conf1
-rw-r--r--test/logging/log_all_debug.file9
-rw-r--r--test/logging/log_all_debug.stderr9
-rw-r--r--test/logging/log_all_debug.stdout3
-rw-r--r--test/logging/log_all_debug_notrace.stdout2
-rw-r--r--test/logging/log_all_default.stdout0
-rw-r--r--test/logging/log_all_error.stderr2
-rw-r--r--test/logging/log_all_info.stderr5
-rw-r--r--test/logging/log_all_info.stdout2
-rw-r--r--test/logging/log_all_silent.stdout2
-rw-r--r--test/logging/log_all_warn.file4
-rw-r--r--test/logging/log_all_warn.stderr4
-rw-r--r--test/subcmd/lmi/scripts/cmdtest/__init__.py77
-rw-r--r--test/test_imode.sh23
-rw-r--r--test/test_logging.sh249
25 files changed, 402 insertions, 11 deletions
diff --git a/test/cmd/help_foo.out b/test/cmd/help_foo.out
index 52e3137..1584a91 100644
--- a/test/cmd/help_foo.out
+++ b/test/cmd/help_foo.out
@@ -1,4 +1,4 @@
-ERROR: no such command "foo"
+error : No such command "foo".
Commands:
help - Print the list of supported commands with short description.
diff --git a/test/cmd/help_test.out b/test/cmd/help_test.out
index 509b845..8ebe3a4 100644
--- a/test/cmd/help_test.out
+++ b/test/cmd/help_test.out
@@ -4,3 +4,4 @@ Usage:
lmi test list <cmd> [<args> ...]
lmi test show pkg <name>
lmi test show repo <name>
+ lmi test log <cmd> [<args> ...]
diff --git a/test/imode/cd_test.exp b/test/imode/cd_test.exp
index a575933..c241c89 100644
--- a/test/imode/cd_test.exp
+++ b/test/imode/cd_test.exp
@@ -55,10 +55,10 @@ send1l ":cd /lmi" "lmi> "
send1l ":cd /test/list" "list> "
send1l ":cd" "list> "
send1l ":cd /./test/../test/./list" ">>list> "
-send2l ":cd /foo" "no such subcommand \"foo\"" ">>list> "
-send2l ":cd pkgs" "ERROR: can not nest to subcommand \"pkgs\" which is not a multiplexer" ">>list> "
-send2l ":cd ../show" "ERROR: can not nest to subcommand \"../show\" which lacks any help message" ">>list> "
-send2l ":cd foo" "ERROR: no such subcommand \"foo\"" ">>list> "
+send2l ":cd /foo" "No such subcommand \"foo\"." ">>list> "
+send2l ":cd pkgs" "Can not nest to subcommand \"pkgs\" which is not a multiplexer." ">>list> "
+send2l ":cd ../show" "Can not nest to subcommand \"../show\" which lacks any help message." ">>list> "
+send2l ":cd foo" "No such subcommand \"foo\"." ">>list> "
send ""
expect ">test> "
send ""
diff --git a/test/imode/completion.exp b/test/imode/completion.exp
index fe871f5..b2d1aa1 100644
--- a/test/imode/completion.exp
+++ b/test/imode/completion.exp
@@ -38,7 +38,7 @@ expect "lmi> "
send ":cd test\r"
expect ">test> "
send " "
-expect "EOF exit help list show"
+expect "EOF exit help list log show"
send "l "
expect "ist"
send ""
diff --git a/test/imode/eof.exp b/test/imode/eof.exp
index a78cbef..56187ec 100644
--- a/test/imode/eof.exp
+++ b/test/imode/eof.exp
@@ -12,7 +12,7 @@ if {[llength $argv] > 0} {
send "[lindex $argv 0]\r"
expect {
timeout { exit -2 }
- -re "[lindex $argv 1]"
+ "[lindex $argv 1]"
}
expect "lmi> "
}
diff --git a/test/imode/help_foo.out b/test/imode/help_foo.out
index 80693ac..134c3f8 100644
--- a/test/imode/help_foo.out
+++ b/test/imode/help_foo.out
@@ -1,4 +1,4 @@
-ERROR: no such command "foo"
+error : No such command "foo".
Static commands
===============
diff --git a/test/imode/help_test.out b/test/imode/help_test.out
index e1e2510..4d69313 100644
--- a/test/imode/help_test.out
+++ b/test/imode/help_test.out
@@ -4,3 +4,4 @@ Usage:
test list <cmd> [<args> ...]
test show pkg <name>
test show repo <name>
+ test log <cmd> [<args> ...]
diff --git a/test/imode/test_help.out b/test/imode/test_help.out
index dd5489b..39176aa 100644
--- a/test/imode/test_help.out
+++ b/test/imode/test_help.out
@@ -4,6 +4,7 @@ Usage:
test list <cmd> [<args> ...]
test show pkg <name>
test show repo <name>
+ test log <cmd> [<args> ...]
To get help for built-in commands, type:
:help
diff --git a/test/imode/test_help_show.out b/test/imode/test_help_show.out
index e1e2510..4d69313 100644
--- a/test/imode/test_help_show.out
+++ b/test/imode/test_help_show.out
@@ -4,3 +4,4 @@ Usage:
test list <cmd> [<args> ...]
test show pkg <name>
test show repo <name>
+ test log <cmd> [<args> ...]
diff --git a/test/imode/test_opt_help.out b/test/imode/test_opt_help.out
index e1e2510..4d69313 100644
--- a/test/imode/test_opt_help.out
+++ b/test/imode/test_opt_help.out
@@ -4,3 +4,4 @@ Usage:
test list <cmd> [<args> ...]
test show pkg <name>
test show repo <name>
+ test log <cmd> [<args> ...]
diff --git a/test/logging/defaults.conf b/test/logging/defaults.conf
new file mode 100644
index 0000000..047572b
--- /dev/null
+++ b/test/logging/defaults.conf
@@ -0,0 +1 @@
+[Log]
diff --git a/test/logging/log_all_debug.file b/test/logging/log_all_debug.file
new file mode 100644
index 0000000..69326b5
--- /dev/null
+++ b/test/logging/log_all_debug.file
@@ -0,0 +1,9 @@
+DEBUG: Running command "test".
+DEBUG: Found registered command "test".
+WARNING: Command "lmi.scripts.cmdtest.Show" is missing usage string. It will be inherited from parent command.
+INFO: Connected to kvm-rhel7
+DEBUG: One Ring to rule them all.
+INFO: One Ring to find them.
+WARNING: One Ring to bring them all
+ERROR: and in the darkness bind them.
+CRITICAL: In the land of Mordor where the Shadows lie.
diff --git a/test/logging/log_all_debug.stderr b/test/logging/log_all_debug.stderr
new file mode 100644
index 0000000..31573aa
--- /dev/null
+++ b/test/logging/log_all_debug.stderr
@@ -0,0 +1,9 @@
+Running command "test".
+Found registered command "test".
+warning : Command "lmi.scripts.cmdtest.Show" is missing usage string. It will be inherited from parent command.
+Connected to kvm-rhel7
+One Ring to rule them all.
+One Ring to find them.
+warning : One Ring to bring them all
+error : and in the darkness bind them.
+critical: In the land of Mordor where the Shadows lie.
diff --git a/test/logging/log_all_debug.stdout b/test/logging/log_all_debug.stdout
new file mode 100644
index 0000000..98d7a80
--- /dev/null
+++ b/test/logging/log_all_debug.stdout
@@ -0,0 +1,3 @@
+Additional information.
+Enjoy tracebacks.
+I can not be more verbose than this!
diff --git a/test/logging/log_all_debug_notrace.stdout b/test/logging/log_all_debug_notrace.stdout
new file mode 100644
index 0000000..dfd2b72
--- /dev/null
+++ b/test/logging/log_all_debug_notrace.stdout
@@ -0,0 +1,2 @@
+Additional information.
+I can not be more verbose than this!
diff --git a/test/logging/log_all_default.stdout b/test/logging/log_all_default.stdout
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/logging/log_all_default.stdout
diff --git a/test/logging/log_all_error.stderr b/test/logging/log_all_error.stderr
new file mode 100644
index 0000000..f8f1c07
--- /dev/null
+++ b/test/logging/log_all_error.stderr
@@ -0,0 +1,2 @@
+error : and in the darkness bind them.
+critical: In the land of Mordor where the Shadows lie.
diff --git a/test/logging/log_all_info.stderr b/test/logging/log_all_info.stderr
new file mode 100644
index 0000000..2abec7e
--- /dev/null
+++ b/test/logging/log_all_info.stderr
@@ -0,0 +1,5 @@
+warning : Command "lmi.scripts.cmdtest.Show" is missing usage string. It will be inherited from parent command.
+One Ring to find them.
+warning : One Ring to bring them all
+error : and in the darkness bind them.
+critical: In the land of Mordor where the Shadows lie.
diff --git a/test/logging/log_all_info.stdout b/test/logging/log_all_info.stdout
new file mode 100644
index 0000000..17af42d
--- /dev/null
+++ b/test/logging/log_all_info.stdout
@@ -0,0 +1,2 @@
+Additional information.
+Enjoy tracebacks.
diff --git a/test/logging/log_all_silent.stdout b/test/logging/log_all_silent.stdout
new file mode 100644
index 0000000..73f7ea6
--- /dev/null
+++ b/test/logging/log_all_silent.stdout
@@ -0,0 +1,2 @@
+Let's be silent.
+Enjoy tracebacks.
diff --git a/test/logging/log_all_warn.file b/test/logging/log_all_warn.file
new file mode 100644
index 0000000..4eaadb9
--- /dev/null
+++ b/test/logging/log_all_warn.file
@@ -0,0 +1,4 @@
+WARNING: Command "lmi.scripts.cmdtest.Show" is missing usage string. It will be inherited from parent command.
+WARNING: One Ring to bring them all
+ERROR: and in the darkness bind them.
+CRITICAL: In the land of Mordor where the Shadows lie.
diff --git a/test/logging/log_all_warn.stderr b/test/logging/log_all_warn.stderr
new file mode 100644
index 0000000..eab784d
--- /dev/null
+++ b/test/logging/log_all_warn.stderr
@@ -0,0 +1,4 @@
+warning : Command "lmi.scripts.cmdtest.Show" is missing usage string. It will be inherited from parent command.
+warning : One Ring to bring them all
+error : and in the darkness bind them.
+critical: In the land of Mordor where the Shadows lie.
diff --git a/test/subcmd/lmi/scripts/cmdtest/__init__.py b/test/subcmd/lmi/scripts/cmdtest/__init__.py
index 9d3acf1..14ceeb6 100644
--- a/test/subcmd/lmi/scripts/cmdtest/__init__.py
+++ b/test/subcmd/lmi/scripts/cmdtest/__init__.py
@@ -34,10 +34,15 @@ Usage:
%(cmd)s list <cmd> [<args> ...]
%(cmd)s show pkg <name>
%(cmd)s show repo <name>
+ %(cmd)s log <cmd> [<args> ...]
"""
+from lmi.scripts.common import get_logger
from lmi.scripts.common import errors
from lmi.scripts.common import command
+from lmi.scripts.common import configuration
+
+LOG = get_logger(__name__)
class ListPackages(command.LmiLister):
OPT_NO_UNDERSCORES = True
@@ -87,7 +92,7 @@ class ShowPackage(command.LmiLister):
def execute(self, ns, name):
pkgd = { p[0] : p for p in PACKAGES }
if not name in pkgd:
- raise errors.LmiFailed('no such package "%s"' % name)
+ raise errors.LmiFailed('No such package "%s".' % name)
for n, v in zip(('Name', 'Architecture', 'Installed'), pkgd[name]):
yield n, v
@@ -97,7 +102,7 @@ class ShowRepository(command.LmiLister):
def execute(self, ns, name):
repod = { r[0] : r for r in REPOSITORIES }
if not name in repod:
- raise errors.LmiFailed('no such repository "%s"' % name)
+ raise errors.LmiFailed('No such repository "%s".' % name)
for n, v in zip(('Name', 'Enabled'), repod[name]):
yield n, v
@@ -107,10 +112,78 @@ class Show(command.LmiCommandMultiplexer):
'repo' : ShowRepository
}
+class LogLevel(command.LmiCheckResult):
+ EXPECT = None
+
+ def execute(self, ns, _debug, _info, _warn, _error, _critical,
+ message=None, args=None):
+ for level in ('debug', 'info', 'warn', 'error', 'critical'):
+ if locals()['_' + level]:
+ break
+ if not message:
+ message = "This is %s message." % level
+ if not args:
+ args = []
+ getattr(LOG(), level)(message, *args)
+
+class LogAll(command.LmiCheckResult):
+ EXPECT = None
+ POEM = (
+ 'One Ring to rule them all.',
+ 'One Ring to find them.',
+ 'One Ring to bring them all',
+ 'and in the darkness bind them.',
+ 'In the land of Mordor where the Shadows lie.')
+
+ def execute(self, ns, _with_traceback):
+ for verse, level in zip(LogAll.POEM,
+ ('debug', 'info', 'warn', 'error', 'critical')):
+ if _with_traceback:
+ try:
+ raise RuntimeError('S**t happens!')
+ except RuntimeError as err:
+ getattr(LOG(), level)(verse, exc_info=err)
+ else:
+ getattr(LOG(), level)(verse)
+ if self.app.config.verbose:
+ self.app.stdout.write('Additional information.\n')
+ if self.app.config.silent:
+ self.app.stdout.write("Let's be silent.\n")
+ if self.app.config.trace:
+ self.app.stdout.write('Enjoy tracebacks.\n')
+ if self.app.config.verbosity >= self.app.config.OUTPUT_DEBUG:
+ self.app.stdout.write('I can not be more verbose than this!\n')
+
+class LogRaise(command.LmiCheckResult):
+ EXPECT = None
+
+ def execute(self, ns, _lmi_failed=False):
+ if _lmi_failed:
+ raise errors.LmiFailed("You asked for it!")
+ raise RuntimeError("This shall make a nice traceback.")
+
+class Logger(command.LmiCommandMultiplexer):
+ """
+ Command for logging testing.
+
+ Usage:
+ %(cmd)s level (--debug | --info | --warn | --error | --critical)
+ [<message> <args>...]
+ %(cmd)s all [--with-traceback]
+ %(cmd)s raise [--lmi-failed]
+ """
+ COMMANDS = {
+ 'level' : LogLevel,
+ 'all' : LogAll,
+ 'raise' : LogRaise
+ }
+ OWN_USAGE = True
+
Test = command.register_subcommands(
'Test', __doc__,
{ 'list' : Lister,
'show' : Show,
+ 'log' : Logger,
},
)
diff --git a/test/test_imode.sh b/test/test_imode.sh
index 0718654..6cd2ab2 100644
--- a/test/test_imode.sh
+++ b/test/test_imode.sh
@@ -79,6 +79,26 @@ function run_test_command() {
done
}
+function make_error_message() {
+ # Args:
+ # level - one of debug, info, warn, error, critical
+ # message
+ level=$1
+ message="$2"
+ [ "$level" = 'warn' ] && level=warning
+ case "$level" in
+ warning) color='\x1b[38;5;11m'; ;;
+ error) color='\x1b[38;5;9m'; ;;
+ critical) color='\x1b[38;5;13m'; ;;
+ *) unset color; ;;
+ esac
+ if [[ -n "$color" ]]; then
+ printf "$color%-8s:\x1b[39m %s\n" $level "$message"
+ else
+ echo "$message"
+ fi
+}
+
rlJournalStart
rlPhaseStartSetup
@@ -110,7 +130,8 @@ rlPhaseStartTest
rlLogInfo "Test end of file"
rlRun "expect imode/eof.exp" 0
rlRun "expect imode/eof.exp ':pwd' '/lmi'" 0
- rlRun 'expect imode/eof.exp ":cd foo" "ERROR: no such subcommand \"foo\""' 0
+ errmsg=`make_error_message error 'No such subcommand \"foo\".'`
+ rlRun "expect imode/eof.exp ':cd foo' \"$errmsg\"" 0
rlRun "expect imode/empty_lines.exp" 0
run_and_compare_output "$LMI < imode/empty_lines.txt" empty_lines
rlPhaseEnd
diff --git a/test/test_logging.sh b/test/test_logging.sh
new file mode 100644
index 0000000..ef6060f
--- /dev/null
+++ b/test/test_logging.sh
@@ -0,0 +1,249 @@
+#!/bin/bash
+#
+# Copyright (c) 2014, Red Hat, Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# The views and conclusions contained in the software and documentation are
+# those of the authors and should not be interpreted as representing official
+# policies, either expressed or implied, of the FreeBSD Project.
+#
+# Authors: Michal Minar <miminar@redhat.com>
+
+. ./base.sh
+
+# Set the full test name
+TEST="openlmi-scripts/test/test_logging.sh"
+
+# Package being tested
+PACKAGE="openlmi-scripts"
+
+# array of supported log levels
+LEVELS=( critical error warn info debug )
+
+DEBUG_CONFIG_TEMPLATE="
+[Main]
+Trace = True
+Verbosity = 2
+
+[Log]
+Level = DEBUG
+LogToConsole = True
+FileFormat = %%(levelname)s: %%(message)s
+OutputFile = %s
+"
+
+rlJournalStart
+
+rlPhaseStartSetup
+ rlLogInfo "Creating temporary python sandbox"
+ sandbox=`mktemp -d`
+ export PYTHONPATH="$sandbox"
+ pushd ..
+ rlLogInfo "Installing lmi meta-command"
+ rlRun "python setup.py develop --install-dir=$sandbox" 0
+ popd
+ pushd subcmd
+ rlRun "python setup.py develop --install-dir=$sandbox" 0
+ popd
+ export PATH="$sandbox:$PATH"
+rlPhaseEnd
+
+rlPhaseStartTest
+ rlLogInfo "Test logging with default settings"
+
+ LMICMD="$LMI -c logging/defaults.conf"
+
+ stdout=`mktemp stdoutXXXX`
+ stderr=`mktemp stderrXXXX`
+ rlRun "$LMICMD test log all >$stdout 2>$stderr" 0
+ rlAssertNotDiffer logging/log_all_default.stdout $stdout
+ rlAssertNotDiffer logging/log_all_warn.stderr $stderr
+
+ rlRun "$LMICMD test log all --with-traceback >$stdout 2>$stderr" 0
+ rlAssertNotDiffer logging/log_all_default.stdout $stdout
+ tmpout=`mktemp tmpoutXXXX`
+ grep '^\(warning\|error\|critical\)' $stderr > $tmpout
+ rlAssertNotDiffer logging/log_all_warn.stderr $tmpout
+ rlAssertEquals "Correct number of exceptions were raised" 3 \
+ `grep '^RuntimeError: S\*\*t happens!' $stderr | wc -l`
+ rm $tmpout
+
+ expected_out=`mktemp expected_stdoutXXXX`
+ expected_err=`mktemp expected_stderrXXXX`
+ for verbosity in 0 1 2; do
+ if [[ $verbosity -gt 0 ]]; then
+ option=`printf -- "-v %.0s" $(seq $verbosity)`
+ else
+ option=''
+ fi
+ CMD="$LMICMD $option test log level"
+ for level in `seq 0 $((${#LEVELS[@]} - 1))`; do
+ rlRun "$CMD --${LEVELS[$level]} >$stdout 2>$stderr" 0
+ level_name=${LEVELS[$level]}
+ log_level_name=$level_name
+ [ $level_name = warn ] && log_level_name=warning
+ ( \
+ if [ $verbosity = 2 ]; then \
+ echo 'Running command "test".'; \
+ echo 'Found registered command "test".'; \
+ fi; \
+ echo -n 'warning : Command "lmi.scripts.cmdtest.Show"'; \
+ echo -n " is missing usage string. It will be"; \
+ echo " inherited from parent command."; \
+ if [ $verbosity = 2 ]; then \
+ for opt_name in '_with_traceback' '_lmi_failed'; do \
+ echo -n "Option \"$opt_name\" not handled in function"; \
+ echo ' "level", ignoring.'; \
+ done; \
+ echo "Connected to $HOSTNAME"; \
+ fi; \
+ if [ $(($verbosity + 2)) -ge $level ]; then \
+ if [ $level -lt 3 ]; then \
+ printf "%-8s: " $log_level_name; \
+ fi; \
+ echo "This is $level_name message."; \
+ fi \
+ ) >$expected_err
+ rlAssertNotDiffer $expected_err $stderr
+ rlAssertEquals "Nothing is written to stdout" 0 `cat $stdout | wc -c`
+ done
+ done
+
+ rm $stdout $stderr $expected_out $expected_err
+
+rlPhaseEnd
+
+rlPhaseStartTest
+ rlLogInfo "Test logging with debug settings"
+
+ config_file=`mktemp configXXXX`
+ log_file=`mktemp log_fileXXXX`
+ printf "$DEBUG_CONFIG_TEMPLATE" $log_file >$config_file
+
+ LMICMD="$LMI -c $config_file"
+
+ stdout=`mktemp stdoutXXXX`
+ stderr=`mktemp stderrXXXX`
+ filter_debug=" | grep -v '^Option' > $stderr"
+ rlRun "$LMICMD test log all 2>&1 >$stdout $filter_debug" 0
+ rlAssertNotDiffer logging/log_all_debug.stdout $stdout
+ rlAssertNotDiffer logging/log_all_debug.stderr $stderr
+ cat $log_file | grep -v '^DEBUG: Option' >${log_file}.tmp
+ mv ${log_file}{.tmp,}
+ rlAssertNotDiffer logging/log_all_debug.file $log_file
+ rm $log_file
+
+ rlRun "$LMICMD test log all --with-traceback 2>&1 >$stdout $filter_debug" 0
+ rlAssertNotDiffer logging/log_all_debug.stdout $stdout
+ tmpout=`mktemp tmpoutXXXX`
+ grep '^\(warning\|error\|critical\)' $stderr > $tmpout
+ rlAssertNotDiffer logging/log_all_warn.stderr $tmpout
+ rlAssertEquals "Correct number of exceptions were raised" 5 \
+ `grep '^RuntimeError: S\*\*t happens!' $stderr | wc -l`
+ rlAssertEquals "Correct number of exceptions were raised" 5 \
+ `grep '^RuntimeError: S\*\*t happens!' $log_file | wc -l`
+ rm $tmpout $log_file
+
+ rlLogInfo "Try override log-file"
+ new_log_file=`mktemp new_log_fileXXXX`
+ rlRun "$LMICMD --log-file $new_log_file test log all 2>&1 >$stdout $filter_debug" 0
+ rlAssertNotDiffer logging/log_all_debug.stdout $stdout
+ rlAssertNotDiffer logging/log_all_debug.stderr $stderr
+ cat $new_log_file | grep -v '^DEBUG: Option' >${new_log_file}.tmp
+ mv ${new_log_file}{.tmp,}
+ rlAssertNotDiffer logging/log_all_debug.file $new_log_file
+ rlRun "[ -e $log_file ]" 1 "Log file from config file shall not be written"
+
+ [ -e $new_log_file ] && rm $new_log_file
+ [ -e $log_file ] && rm $log_file
+
+ rlLogInfo "Try to disable logging to a file"
+ rlRun "$LMICMD --log-file '' test log all 2>&1 >$stdout $filter_debug" 0
+ rlAssertNotDiffer logging/log_all_debug.stdout $stdout
+ rlAssertNotDiffer logging/log_all_debug.stderr $stderr
+ rlRun "[ -e $log_file ]" 1 "Log file from config file shall not be written"
+ [ -e $log_file ] && rm $log_file
+
+ rlLogInfo "Try override verbosity"
+ rlRun "$LMICMD -q test log all 2>&1 >$stdout $filter_debug" 0
+ rlAssertNotDiffer logging/log_all_silent.stdout $stdout
+ rlAssertNotDiffer logging/log_all_error.stderr $stderr
+ cat $log_file | grep -v '^DEBUG: Option' >${log_file}.tmp
+ mv ${log_file}{.tmp,}
+ rlAssertNotDiffer logging/log_all_debug.file $log_file
+ rm $log_file
+
+ rlRun "$LMICMD -v test log all >$stdout 2>$stderr" 0
+ rlAssertNotDiffer logging/log_all_info.stdout $stdout
+ rlAssertNotDiffer logging/log_all_info.stderr $stderr
+ cat $log_file | grep -v '^DEBUG: Option' >${log_file}.tmp
+ mv ${log_file}{.tmp,}
+ rlAssertNotDiffer logging/log_all_debug.file $log_file
+ rm $log_file
+
+ rlLogInfo "Change file log level"
+ sed -i 's/DEBUG/WARNING/' $config_file
+ rlAssertGrep 'Level = WARNING' $config_file
+ rlRun "$LMICMD test log all 2>&1 >$stdout $filter_debug" 0
+ rlAssertNotDiffer logging/log_all_debug.stdout $stdout
+ rlAssertNotDiffer logging/log_all_debug.stderr $stderr
+ rlAssertNotDiffer logging/log_all_warn.file $log_file
+ [ -e $log_file ] && rm $log_file
+
+ rlLogInfo "Disable logging to console"
+ sed -i 's/\(LogToConsole.*\)True/\1False/' $config_file
+ rlAssertGrep 'LogToConsole = False' $config_file
+ rlRun "$LMICMD test log all >$stdout 2>$stderr" 0
+ rlAssertNotDiffer logging/log_all_debug.stdout $stdout
+ rlAssertEquals "Nothing is written to stderr" `cat $stderr | wc -c` 0
+ rlAssertNotDiffer logging/log_all_warn.file $log_file
+ [ -e $log_file ] && rm $log_file
+
+ rlLogInfo "Override tracing"
+ rlRun "$LMICMD --notrace test log all >$stdout 2>$stderr" 0
+ rlAssertNotDiffer logging/log_all_debug_notrace.stdout $stdout
+ rlAssertEquals "Nothing is written to stderr" `cat $stderr | wc -c` 0
+ rlAssertNotDiffer logging/log_all_warn.file $log_file
+
+ for f in $log_file $new_log_file $config_file $stdout $stderr; do
+ [ -e $f ] && rm $f
+ done
+
+rlPhaseEnd
+
+rlPhaseStartTest
+ rlLogInfo "Test logging with settings"
+
+ stdout=`mktemp stdoutXXXX`
+ stderr=`mktemp stderrXXXX`
+ rlRun "$LMI -c logging/defaults.conf test log all >$stdout 2>$stderr" 0
+ rlAssertNotDiffer $stdout logging/log_all_default.stdout
+ rlAssertNotDiffer $stderr logging/log_all_warn.stderr
+ rm $stdout $stderr
+rlPhaseEnd
+
+
+rlPhaseStartCleanup
+ rlLogInfo "Removing temporary python sandbox"
+ rm -rf "$sandbox"
+rlPhaseEnd