@@ -156,13 +156,18 @@ def test_normalize_references_and_dates_before_staging(self):
156156 before = DATED_PO .replace (b"\n " , newline )
157157 changed = before .replace (b"example.rst:10" , b"example.rst:200" )
158158 changed = changed .replace (b"2026-09-29" , b"2026-10-24" )
159- for name in ("unchanged.po" , "translated.po" , "deleted.po" ):
159+ for name in ("unchanged.po" , "translated.po" , "locations.po" , " deleted.po" ):
160160 (self .destination / name ).write_bytes (before )
161161 self .track ()
162162 (self .destination / "unchanged.po" ).write_bytes (changed )
163163 (self .destination / "translated.po" ).write_bytes (
164164 changed .replace ('翻訳' .encode (), '新しい訳' .encode ())
165165 )
166+ locations = changed .replace (
167+ b"#: example.rst:200" + newline ,
168+ b"#: example.rst:200 example.rst:300" + newline ,
169+ )
170+ (self .destination / "locations.po" ).write_bytes (locations )
166171 (self .destination / "deleted.po" ).unlink ()
167172 new = self .destination / ("new-crlf.po" if newline == b"\r \n " else "new-lf.po" )
168173 new .write_bytes (changed )
@@ -176,6 +181,10 @@ def test_normalize_references_and_dates_before_staging(self):
176181 expected = expected .replace (b"2026-09-29" , b"2026-10-24" )
177182 expected = expected .replace (b"#: example.rst:10" + newline , b"" )
178183 self .assertEqual ((self .destination / "translated.po" ).read_bytes (), expected )
184+ self .assertEqual (
185+ (self .destination / "locations.po" ).read_bytes (),
186+ locations .replace (b"#: example.rst:200 example.rst:300" + newline , b"" ),
187+ )
179188 self .assertEqual (new .read_bytes (), changed .replace (b"#: example.rst:200" + newline , b"" ))
180189 self .assertFalse ((self .destination / "deleted.po" ).exists ())
181190 self .track ()
@@ -189,8 +198,8 @@ def test_normalize_references_preserves_other_entry_changes(self):
189198 for old , new , action in [
190199 (b'msgid "example"' , b'msgid "new source"' , "drop" ),
191200 (b'msgid "example"' , b'msgctxt "new context"\n msgid "example"' , "drop" ),
192- (b"example.rst:200" , b"renamed.rst:200" , "keep " ),
193- (b"example.rst:200" , b"example.rst:200 other.rst:30" , "keep " ),
201+ (b"example.rst:200" , b"renamed.rst:200" , "drop " ),
202+ (b"example.rst:200" , b"example.rst:200 other.rst:30" , "drop " ),
194203 (b'#: example.rst:200\n ' , b'' , "keep" ),
195204 (b'msgid "example"' , b'#, fuzzy\n msgid "example"' , "restore" ),
196205 (b'msgid "example"' , b'#. new comment\n msgid "example"' , "restore" ),
@@ -200,12 +209,35 @@ def test_normalize_references_preserves_other_entry_changes(self):
200209 incoming = changed .replace (old , new )
201210 expected = incoming
202211 if action == "drop" :
203- expected = incoming .replace (b"#: example.rst:200\n " , b"" )
212+ expected = b"" .join (
213+ line for line in incoming .splitlines (keepends = True )
214+ if not line .startswith (b"#:" )
215+ )
204216 elif action == "restore" :
205217 expected = incoming .replace (b"example.rst:200" , b"example.rst:10" )
206218 self .assertEqual (translations .normalize_po_references (DATED_PO , incoming ),
207219 expected )
208220
221+ def test_changed_source_occurrence_counts_drop_all_reference_lines (self ):
222+ header = DATED_PO .split (b"#: example.rst:10" )[0 ]
223+ message = b'msgid "yes"\n msgstr "yes"\n '
224+ old_references = b"#: ../../c-api/buffer.rst:292 ../../c-api/buffer.rst:294\n "
225+ for new_references in [
226+ b"#: ../../c-api/buffer.rst:304\n " ,
227+ (b"#: ../../c-api/buffer.rst:304 ../../c-api/buffer.rst:305\n "
228+ b"#: ../../c-api/buffer.rst:308 ../../c-api/buffer.rst:309\n " ),
229+ ]:
230+ for newline in (b"\n " , b"\r \n " ):
231+ with self .subTest (references = new_references , newline = newline ):
232+ original = (header + old_references + message ).replace (b"\n " , newline )
233+ incoming = (header + new_references + message ).replace (b"\n " , newline )
234+ expected = (header + message ).replace (b"\n " , newline )
235+ normalized = translations .normalize_po_references (original , incoming )
236+ self .assertEqual (normalized , expected )
237+ self .assertEqual (
238+ translations .normalize_po_references (normalized , incoming ), expected
239+ )
240+
209241 def test_restore_line_numbers_matches_context_plural_and_reordered_entries (self ):
210242 header = DATED_PO .split (b"#: example.rst:10" )[0 ]
211243 first = (b'#: one.rst:10 two.rst:20\n msgctxt "first"\n '
0 commit comments