From 9d7268dbda760522aaef21b6f40c9b3358a20ffb Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Thu, 15 Jun 2017 15:26:10 +0000 Subject: [PATCH] Coerce loglevel facet to int when updating Calling the set command always results in updating values to type str, which can result in failures when those values are later re-read. Explicitly coerce the loglevel value to int whenever it is updated to avoid a subsequent exception when calling the show log command. This points out a need for maintaining a schema so that values can be coerced to the appropriate type when needed, but for now the conditional adjustment can serve as a placeholder for a more thorough design. --- mudpy/misc.py | 2 ++ mudpy/tests/selftest.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/mudpy/misc.py b/mudpy/misc.py index 2923feb..6cb7804 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -154,6 +154,8 @@ class Element: def set(self, facet, value): """Set values.""" + if facet in ["loglevel"]: + value = int(value) if not self.has_facet(facet) or not self.get(facet) == value: if self.old_style: if self.key not in self.origin.data: diff --git a/mudpy/tests/selftest.py b/mudpy/tests/selftest.py index 27378e9..56814d4 100644 --- a/mudpy/tests/selftest.py +++ b/mudpy/tests/selftest.py @@ -167,6 +167,13 @@ test_show_log = ( "[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""), ) +test_custom_loglevel = ( + (2, "> ", "set account:admin loglevel 2"), + (2, "You have successfully .*> ", "show log"), + (2, "There are [0-9]+ log lines in memory and [0-9]+ at or above level " + "[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""), +) + test_log_no_errors = ( (2, "> ", "show log 7"), (2, "None of the [0-9]+ lines in memory matches your request\.", ""), @@ -189,6 +196,7 @@ dialogue = ( (test_admin_help, "admin help"), (test_show_element, "show element"), (test_show_log, "show log"), + (test_custom_loglevel, "show log"), (test_log_no_errors, "no errors logged"), ) -- 2.11.0