|
20 | 20 | from babel.messages.pofile import _enclose_filename_if_necessary, _extract_locations |
21 | 21 |
|
22 | 22 |
|
| 23 | +@pytest.mark.parametrize( |
| 24 | + ('prefix', 'attribute'), |
| 25 | + [('#.', 'auto_comments'), ('#', 'user_comments')], |
| 26 | +) |
| 27 | +@pytest.mark.parametrize('obsolete', [False, True]) |
| 28 | +def test_read_po_preserves_repeated_comment_lines(prefix, attribute, obsolete): |
| 29 | + comments = ['KEY:', 'first.long.key', 'KEY:', 'second.long.key'] |
| 30 | + source = '\n'.join(f'{prefix} {line}' for line in comments) + '\n' |
| 31 | + message_prefix = '#~ ' if obsolete else '' |
| 32 | + source += f'{message_prefix}msgid "Example"\n{message_prefix}msgstr ""\n' |
| 33 | + |
| 34 | + catalog = pofile.read_po(StringIO(source)) |
| 35 | + message = catalog.obsolete['Example'] if obsolete else catalog['Example'] |
| 36 | + assert getattr(message, attribute) == comments |
| 37 | + |
| 38 | + |
| 39 | +@pytest.mark.parametrize('attribute', ['auto_comments', 'user_comments']) |
| 40 | +def test_wrapped_comments_roundtrip(attribute): |
| 41 | + catalog = Catalog() |
| 42 | + comments = ['KEY: ' + 'foo.' * 20, 'KEY: ' + 'bar.' * 20] |
| 43 | + catalog.add('Example', **{attribute: comments}) |
| 44 | + first = BytesIO() |
| 45 | + pofile.write_po(first, catalog, omit_header=True) |
| 46 | + first.seek(0) |
| 47 | + |
| 48 | + restored = pofile.read_po(first) |
| 49 | + second = BytesIO() |
| 50 | + pofile.write_po(second, restored, omit_header=True) |
| 51 | + assert second.getvalue() == first.getvalue() |
| 52 | + |
| 53 | + |
23 | 54 | def test_enclosed_filenames_in_location_comment(): |
24 | 55 | catalog = Catalog() |
25 | 56 | catalog.add("foo", lineno=2, locations=[("main 1.py", 1)], string="") |
|
0 commit comments