Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ reporting, all input is greatly appreciated!

Code contributions:

- Alexandre Bertho (alexbertho)
- Alexandre Decan (AlexandreDecan)
- dhilipsiva (dhilipsiva)
- MAA (FooBarQuaxx)
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
Version 8.0.1
-------------

* Fix ConfigBox.merge_update consuming one-shot key/value pairs before merging them
* Fixing #349 BoxList item comments moving to the wrong items after a box_dots deletion, e.g. del bl["[0]"] (thanks to HocVoNgThai)
* Fixing #349 BoxList.sort() calling the key function twice when the list has comments (thanks to HocVoNgThai)

Expand Down
3 changes: 2 additions & 1 deletion box/config_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def merge_update(self, *args, **kwargs):
if hasattr(args[0], "keys"):
incoming = list(args[0].keys())
else:
args = (list(args[0]),) # may be a one-shot iterator, it is read twice
# Both the outer iterable and its pairs may be one-shot iterators.
args = ([tuple(pair) for pair in args[0]],)
incoming = [k for k, _ in args[0]]
else:
incoming = []
Expand Down
9 changes: 9 additions & 0 deletions test/test_config_box_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@


class TestConfigBoxCaseInsensitive:
@pytest.mark.parametrize("outer", [list, iter])
def test_merge_update_one_shot_pairs(self, outer):
cb = ConfigBox({"Host": {"port": 80}})
pairs = outer([iter(("host", {"name": "localhost"})), iter(("timeout", 30))])
cb.merge_update(pairs)
assert cb.to_dict() == {"host": {"port": 80, "name": "localhost"}, "timeout": 30}
assert list(cb) == ["host", "timeout"]
assert cb.HOST.port == 80

def test_lookup_any_case(self):
cb = ConfigBox({"HOST": "localhost", "ServerPort": 8080})
assert cb["host"] == cb["Host"] == cb.host == cb.HOST == "localhost"
Expand Down