@@ -216,3 +216,52 @@ def test_zinogre(games, built, ports):
216216def test_brute (built ):
217217 table = C .pac_clip_table (built ("brute_tigrex" ))
218218 assert len (table ) == 77 and table [61 ] == (382 , False ) and 24 not in table
219+
220+
221+ @pytest .fixture
222+ def parses (monkeypatch ):
223+ """The PACs `pac_clip_table` parsed, with a table that says which."""
224+ seen : list [bytes ] = []
225+ monkeypatch .setattr (slots , "anim_of" , lambda pac : seen .append (pac ) or pac )
226+ monkeypatch .setattr (C , "clip_table" , lambda pack : {1 : (len (pack ), True )})
227+ C .pac_clip_table .cache_clear ()
228+ yield seen
229+ C .pac_clip_table .cache_clear ()
230+
231+
232+ def test_a_pac_is_parsed_once_whoever_asks (parses ):
233+ pac = b"a pac"
234+ first = C .pac_clip_table (pac )
235+ assert C .pac_clip_table (pac ) is first and C .pac_clip_table (bytes (bytearray (pac ))) is first
236+ assert parses == [pac ]
237+
238+
239+ def test_other_bytes_are_another_table (parses ):
240+ one , two = C .pac_clip_table (b"one" ), C .pac_clip_table (b"three" )
241+ assert one is not two and dict (one ) == {1 : (3 , True )} and dict (two ) == {1 : (5 , True )}
242+ assert parses == [b"one" , b"three" ]
243+
244+
245+ def test_the_table_is_shared_so_no_caller_can_change_it (parses ):
246+ table = C .pac_clip_table (b"pac" )
247+ with pytest .raises (TypeError ):
248+ table [2 ] = (1 , False )
249+ with pytest .raises (TypeError ):
250+ del table [1 ]
251+ assert dict (C .pac_clip_table (b"pac" )) == {1 : (3 , True )}
252+
253+
254+ def test_an_unreadable_pac_is_not_remembered (monkeypatch ):
255+ tries = []
256+
257+ def broken (pac ):
258+ tries .append (pac )
259+ raise ValueError ("no clips" )
260+
261+ monkeypatch .setattr (slots , "anim_of" , broken )
262+ C .pac_clip_table .cache_clear ()
263+ for _ in range (2 ):
264+ with pytest .raises (ValueError , match = "no clips" ):
265+ C .pac_clip_table (b"bad" )
266+ assert len (tries ) == 2
267+ C .pac_clip_table .cache_clear ()
0 commit comments