Coerce loglevel facet to int when updating
authorJeremy Stanley <fungi@yuggoth.org>
Thu, 15 Jun 2017 15:26:10 +0000 (15:26 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Thu, 15 Jun 2017 15:26:10 +0000 (15:26 +0000)
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
mudpy/tests/selftest.py

index 2923feb..6cb7804 100644 (file)
@@ -154,6 +154,8 @@ class Element:
 
     def set(self, facet, value):
         """Set values."""
 
     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:
         if not self.has_facet(facet) or not self.get(facet) == value:
             if self.old_style:
                 if self.key not in self.origin.data:
index 27378e9..56814d4 100644 (file)
@@ -167,6 +167,13 @@ test_show_log = (
         "[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
 )
 
         "[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\.", ""),
 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_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"),
 )
 
     (test_log_no_errors, "no errors logged"),
 )