Skip to content
Open
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
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Development requirements
#

invoke==0.12.2
#rituals==0.3.0
# invoke==0.12.2
# rituals==0.3.0
-e git+https://github.com/jhermann/rituals.git#egg=rituals

Sphinx==1.3.4
Expand Down
8 changes: 8 additions & 0 deletions src/configobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,14 @@ def merge(self, indict, decoupled=False):
>>> c2
ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}})
"""
if hasattr(indict, "initial_comment") and indict.initial_comment:
self.initial_comment = indict.initial_comment
if hasattr(indict, "final_comment") and indict.final_comment:
self.final_comment = indict.final_comment
if hasattr(indict, "comments") and indict.comments:
for k, comment_lines in indict.comments.items():
if comment_lines:
self.comments[k] = comment_lines
for key, val in indict.items():
if decoupled:
val = copy.deepcopy(val)
Expand Down
30 changes: 30 additions & 0 deletions src/tests/test_configobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,36 @@ def test_merge_coupling(self, data):
c1['sect']['val'] = 42
assert c2['sect']['val'] == data[1]

@pytest.mark.parametrize(
"lines1,lines2,expected_lines",
[
(
# both c1 and c2 have comments
["# c1 before config", "[main]", "# c1 for foo", "foo = a", "# c1 after config"],
["# c2 before config", "[main]", "# c2 for foo", "foo = b", "# c2 after config"],
["# c2 before config", "[main]", "# c2 for foo", "foo = b", "# c2 after config"],
),
(
# c1 has comments, c2 does not
["# c1 before config", "[main]", "# c1 for foo", "foo = a", "# c1 after config"],
["[main]", "foo = b"],
["# c1 before config", "[main]", "# c1 for foo", "foo = b", "# c1 after config"],
),
(
# c2 has comments, c1 does not
["[main]", "foo = a"],
["# c2 before config", "[main]", "# c2 for foo", "foo = b", "# c2 after config"],
["# c2 before config", "[main]", "# c2 for foo", "foo = b", "# c2 after config"],
),
]
)
def test_merge_comments(self, lines1, lines2, expected_lines):
c1 = ConfigObj(lines1)
c2 = ConfigObj(lines2)
c1.merge(c2)
# comments and values from c2 should win
actual_lines = c1.write()
assert actual_lines == expected_lines

class TestErrorReporting(object):
MULTI_ERROR = [
Expand Down