🐛 Fix a settings behaviour bug
This commit is contained in:
1 parent
d10780df54
commit
5e7ffd1b15
3 files changed
+82
-80
No files matched your search
@@ -633,11 +633,21 @@ class HierarchicalChainMap:
|
||||
# we do something a bit odd here: if merged is not true, we don't include the
|
||||
# full contents of the key. Instead, we only include the contents of the key on
|
||||
# the first level where we find the value.
|
||||
#
|
||||
# TODO 2.0.0 remove this weird & historic behaviour and make 'merged' the default
|
||||
if not merged and not only_local:
|
||||
# first check if we can find the exact key & if so use that layer
|
||||
for layer in current.maps:
|
||||
if key in layer:
|
||||
current = layer
|
||||
break
|
||||
else:
|
||||
# next, check if we can find the key as a prefix for a subtree & if so
|
||||
# use that layer
|
||||
for layer in current.maps:
|
||||
if any(k.startswith(key) for k in layer):
|
||||
current = layer
|
||||
break
|
||||
|
||||
if key not in current:
|
||||
# we might be trying to grab a dict, look for children
|
||||
|
||||
@@ -24,7 +24,7 @@ import octoprint.settings
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestSettings(unittest.TestCase):
|
||||
class SettingsTest(unittest.TestCase):
|
||||
def _load_yaml(self, fname):
|
||||
with open(fname, encoding="utf-8") as f:
|
||||
return yaml.safe_load(f)
|
||||
@@ -689,3 +689,74 @@ class TestSettings(unittest.TestCase):
|
||||
yield basedir, fresh_config_path
|
||||
finally:
|
||||
octoprint.settings.default_settings = orig_defaults
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class HelpersTest(unittest.TestCase):
|
||||
@ddt.data(
|
||||
(True, True),
|
||||
("true", True),
|
||||
("True", True),
|
||||
("tRuE", True),
|
||||
("yes", True),
|
||||
("YES", True),
|
||||
("y", True),
|
||||
("Y", True),
|
||||
("1", True),
|
||||
(1, True),
|
||||
(False, False),
|
||||
("Truuuuuuuuue", False),
|
||||
("Nope", False),
|
||||
(None, False),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_valid_boolean_trues(self, value, expected):
|
||||
self.assertEqual(expected, value in octoprint.settings.valid_boolean_trues)
|
||||
|
||||
|
||||
def _key(*path):
|
||||
return octoprint.settings._CHAINMAP_SEP.join(path)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class ChainmapTest(unittest.TestCase):
|
||||
@ddt.data(
|
||||
(
|
||||
{"a": 1},
|
||||
{_key("a"): 1},
|
||||
),
|
||||
({"a": {"b": "b"}}, {_key("a", "b"): "b"}),
|
||||
(
|
||||
{"a": {"b": "b", "c": "c", "d": {"e": "e"}}},
|
||||
{_key("a", "b"): "b", _key("a", "c"): "c", _key("a", "d", "e"): "e"},
|
||||
),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_flatten(self, value, expected):
|
||||
self.assertEqual(
|
||||
expected, octoprint.settings.HierarchicalChainMap._flatten(value)
|
||||
)
|
||||
|
||||
@ddt.data(
|
||||
(
|
||||
{_key("a"): 1},
|
||||
{"a": 1},
|
||||
),
|
||||
(
|
||||
{_key("a", "b"): "b"},
|
||||
{"a": {"b": "b"}},
|
||||
),
|
||||
(
|
||||
{_key("a", "b"): "b", _key("a", "c"): "c", _key("a", "d", "e"): "e"},
|
||||
{"a": {"b": "b", "c": "c", "d": {"e": "e"}}},
|
||||
),
|
||||
(
|
||||
{_key("a"): None, _key("a", "b"): "b"},
|
||||
{"a": {"b": "b"}},
|
||||
),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_unflatten(self, value, expected):
|
||||
self.assertEqual(
|
||||
expected, octoprint.settings.HierarchicalChainMap._unflatten(value)
|
||||
)
|
||||
@@ -1,79 +0,0 @@
|
||||
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
||||
__copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
|
||||
import octoprint.settings
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestHelpers(unittest.TestCase):
|
||||
@ddt.data(
|
||||
(True, True),
|
||||
("true", True),
|
||||
("True", True),
|
||||
("tRuE", True),
|
||||
("yes", True),
|
||||
("YES", True),
|
||||
("y", True),
|
||||
("Y", True),
|
||||
("1", True),
|
||||
(1, True),
|
||||
(False, False),
|
||||
("Truuuuuuuuue", False),
|
||||
("Nope", False),
|
||||
(None, False),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_valid_boolean_trues(self, value, expected):
|
||||
self.assertEqual(expected, value in octoprint.settings.valid_boolean_trues)
|
||||
|
||||
|
||||
def _key(*path):
|
||||
return octoprint.settings._CHAINMAP_SEP.join(path)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class ChainmapTest(unittest.TestCase):
|
||||
@ddt.data(
|
||||
(
|
||||
{"a": 1},
|
||||
{_key("a"): 1},
|
||||
),
|
||||
({"a": {"b": "b"}}, {_key("a", "b"): "b"}),
|
||||
(
|
||||
{"a": {"b": "b", "c": "c", "d": {"e": "e"}}},
|
||||
{_key("a", "b"): "b", _key("a", "c"): "c", _key("a", "d", "e"): "e"},
|
||||
),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_flatten(self, value, expected):
|
||||
self.assertEqual(
|
||||
expected, octoprint.settings.HierarchicalChainMap._flatten(value)
|
||||
)
|
||||
|
||||
@ddt.data(
|
||||
(
|
||||
{_key("a"): 1},
|
||||
{"a": 1},
|
||||
),
|
||||
(
|
||||
{_key("a", "b"): "b"},
|
||||
{"a": {"b": "b"}},
|
||||
),
|
||||
(
|
||||
{_key("a", "b"): "b", _key("a", "c"): "c", _key("a", "d", "e"): "e"},
|
||||
{"a": {"b": "b", "c": "c", "d": {"e": "e"}}},
|
||||
),
|
||||
(
|
||||
{_key("a"): None, _key("a", "b"): "b"},
|
||||
{"a": {"b": "b"}},
|
||||
),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_unflatten(self, value, expected):
|
||||
self.assertEqual(
|
||||
expected, octoprint.settings.HierarchicalChainMap._unflatten(value)
|
||||
)
|
||||
Reference in new issue
Block a user