FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix Catalog.is_identical() for messages with msgctxt by abhijeet117 · Pull Request #1329 · python-babel/babel · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 5 additions & 2 deletions babel/messages/catalog.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,11 @@ def is_identical(self, other: Catalog) -> bool:
"""
assert isinstance(other, Catalog)
for key in self._messages.keys() | other._messages.keys():
message_1 = self.get(key)
message_2 = other.get(key)
# The keys are internal keys already (possibly ``(msgid,
# msgctxt)`` tuples), so they must not be passed through ``get()``,
# which would strip the context and miss the message entirely.
message_1 = self._messages.get(key)
message_2 = other._messages.get(key)
if message_1 is None or message_2 is None or not message_1.is_identical(message_2):
return False
return dict(self.mime_headers) == dict(other.mime_headers)
38 changes: 38 additions & 0 deletions tests/messages/test_catalog.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,44 @@ def test_catalog_add():
assert cat['foo'] is foo


def test_catalog_is_identical_with_context():
cat = catalog.Catalog()
cat.add('Guide', 'guide', context='navigation')

# A catalog is identical to itself even when it contains
# context-specific messages (issue #1307).
assert cat.is_identical(cat)

other = catalog.Catalog()
other.add('Guide', 'guide', context='navigation')
assert cat.is_identical(other)

# Same msgid, different context.
other = catalog.Catalog()
other.add('Guide', 'guide', context='menu')
assert not cat.is_identical(other)

# Same context, different string.
other = catalog.Catalog()
other.add('Guide', 'handbook', context='navigation')
assert not cat.is_identical(other)

# Context-specific vs context-free message with the same msgid.
other = catalog.Catalog()
other.add('Guide', 'guide')
assert not cat.is_identical(other)


def test_catalog_is_identical_without_context():
cat = catalog.Catalog()
cat.add('foo', 'bar')
other = catalog.Catalog()
other.add('foo', 'bar')
assert cat.is_identical(other)
other.add('baz', 'qux')
assert not cat.is_identical(other)


def test_catalog_update():
template = catalog.Catalog(header_comment="# A Custom Header")
template.add('green', locations=[('main.py', 99)])
Expand Down

Back | FazBrowse Home | New Git URL