@@ -57,8 +57,8 @@ def test_original_checksum_survives_temporary_po_update(self):
5757 self .catalog .write_text ('# temporary changes\n ' , encoding = 'utf-8' )
5858 result = self .prepare ()
5959 catalog = result ['catalogs' ]['tutorial/guide.po' ]
60- self .assertEqual (catalog ['source_sha256 ' ], original )
61- self .assertEqual (catalog ['scanned_sha256 ' ], 'temporary-po-digest' )
60+ self .assertEqual (catalog ['checkout_sha256 ' ], original )
61+ self .assertEqual (catalog ['source_sha256 ' ], 'temporary-po-digest' )
6262 self .assertEqual (catalog ['findings' ], [self .finding ])
6363 self .assertEqual (result ['language' ], 'pl' )
6464 self .assertEqual (result ['dictionaries' ], ['pl_PL' , 'pl_SJP' ])
@@ -144,3 +144,63 @@ def test_missing_pospell_report_cannot_become_a_clean_report(self):
144144 ):
145145 main ()
146146 self .assertFalse (output .exists ())
147+
148+ def test_snapshot_keeps_current_catalogs_and_sphinx_but_drops_orphans (self ):
149+ pots = self .root / 'pots'
150+ (pots / 'tutorial' ).mkdir (parents = True )
151+ (pots / 'tutorial' / 'guide.pot' ).write_text ('msgid "Source"\n msgstr ""\n ' )
152+ orphan = self .root / 'old.po'
153+ orphan .write_text ('msgid "Literal code"\n msgstr "Literal code"\n ' )
154+ sphinx = self .root / 'sphinx.po'
155+ sphinx .write_text ('msgid "Template"\n msgstr "Szablon"\n ' )
156+ output = self .root / 'snapshot.json'
157+ with (
158+ patch (
159+ 'spellcheck_report.revision' , side_effect = ['translations' , 'cpython' ]
160+ ),
161+ patch (
162+ 'sys.argv' ,
163+ [
164+ 'spellcheck_report.py' ,
165+ 'snapshot' ,
166+ '--translations' ,
167+ str (self .root ),
168+ '--cpython' ,
169+ str (self .root ),
170+ '--pot-dir' ,
171+ str (pots ),
172+ '--output' ,
173+ str (output ),
174+ ],
175+ ),
176+ ):
177+ main ()
178+ self .assertFalse (orphan .exists ())
179+ self .assertTrue (self .catalog .exists ())
180+ self .assertTrue (sphinx .exists ())
181+ self .assertEqual (
182+ set (json .loads (output .read_text ())['catalogs' ]),
183+ {'tutorial/guide.po' , 'sphinx.po' },
184+ )
185+
186+ def test_missing_pot_directory_does_not_remove_catalogs (self ):
187+ with (
188+ patch (
189+ 'sys.argv' ,
190+ [
191+ 'spellcheck_report.py' ,
192+ 'snapshot' ,
193+ '--translations' ,
194+ str (self .root ),
195+ '--cpython' ,
196+ str (self .root ),
197+ '--pot-dir' ,
198+ str (self .root / 'missing' ),
199+ '--output' ,
200+ str (self .root / 'snapshot.json' ),
201+ ],
202+ ),
203+ self .assertRaises (SystemExit ),
204+ ):
205+ main ()
206+ self .assertTrue (self .catalog .exists ())
0 commit comments