"""Reprinting some items (Marcus, 2026-11-26, #105): back in the queue after a print, only the items whose final changed go to the machine again. Run from the repository root: python3 -m unittest tests.test_reprint -v. """ import unittest from decimal import Decimal from app.hotfolder import reprint_default from app.machine_log import film_metres class ReprintTests(unittest.TestCase): def test_only_the_item_with_a_new_final_goes_again(self): finals = [(0, 'a'), (1, 'b-new'), (2, 'c')] self.assertEqual(reprint_default(finals, {'a', 'b-old', 'c'}, 3), [1]) def test_never_printed_or_nothing_new_or_all_new_is_every_item(self): finals = [(0, 'a'), (1, 'b')] self.assertIsNone(reprint_default(finals, None, 2)) # never printed self.assertIsNone(reprint_default(finals, {'a', 'b'}, 2)) # printed again as it was self.assertIsNone(reprint_default(finals, {'x', 'y'}, 2)) # every file new def test_a_film_in_parts_goes_again_when_one_part_is_new(self): finals = [(0, 'p1'), (0, 'p2-new'), (1, 'q'), (2, 'r')] self.assertEqual(reprint_default(finals, {'p1', 'p2', 'q', 'r'}, 3), [0]) def test_the_machine_counts_only_the_items_printed_again(self): snapshot = {'items': [{'billed_metres': '2.0'}, {'billed_metres': '3.5'}]} self.assertEqual(film_metres(snapshot), Decimal('5.5')) self.assertEqual(film_metres(snapshot, [1]), Decimal('3.5')) class ProofFilmTests(unittest.TestCase): # A proof sheet is centimetres of film, counted in metres: it once counted # 15 m per proof, enough for the machine's 10 m cleaning alert. proof = {'proof_of': 81, 'items': [{'billed_metres': '0'}, {'billed_metres': '0'}]} def test_a_proof_with_colour_samples_counts_its_real_length(self): # Marcus, 2026-11-26: the finest stroke's 15 cm and two 5 cm samples, # 1 cm of clear film between them: 27 cm. windows = {'0': [['10', '25'], ['40', '45'], ['80', '85']]} self.assertEqual(film_metres(self.proof, [0], windows), Decimal('0.27')) def test_a_proof_made_before_the_samples_counts_15_cm(self): self.assertEqual(film_metres(self.proof), Decimal('0.30')) self.assertEqual(film_metres(self.proof, None, {'1': [['0', '15']]}), Decimal('0.30')) if __name__ == '__main__': unittest.main()