Margin detection update
This commit is contained in:
1 parent
2c9dc65640
commit
b295f871a7
6 files changed
+292
-68
No files matched your search
@@ -90,6 +90,51 @@ class NameGridTests(unittest.TestCase):
|
||||
self.identify({'Copie01': []})
|
||||
self.assertEqual(self.client.models.generate_content.call_count, 2)
|
||||
|
||||
def test_name_box_is_saved_in_full_page_height_units(self):
|
||||
pdf = self.crop(1)
|
||||
self.client.models.generate_content.return_value = Mock(text=json.dumps({'cells': [
|
||||
{'cell': 1, 'name': 'Alice', 'box_2d': [100, 20, 800, 950]},
|
||||
]}))
|
||||
self.assertEqual(self.identify({'Copie01': []}), {'Copie01': 'Alice'})
|
||||
cached = read_json(self.directory / 'Copie01_result.json')
|
||||
self.assertEqual(cached['box_2d'], [100, 20, 800, 950])
|
||||
self.assertAlmostEqual(cached['name_bottom_height_fraction'], .8 * 584 / 2338)
|
||||
self.assertAlmostEqual(names.name_bottom_height_fraction(self.workspace, 'Copie01'),
|
||||
.8 * 584 / 2338)
|
||||
self.identify({'Copie01': []})
|
||||
self.assertEqual(self.client.models.generate_content.call_count, 1)
|
||||
pdf.write_bytes(b'changed')
|
||||
self.assertIsNone(names.name_bottom_height_fraction(self.workspace, 'Copie01'))
|
||||
|
||||
def test_invalid_or_unmatched_boxes_do_not_produce_a_height(self):
|
||||
self.crop(1)
|
||||
for name, box in [('Alice', [800, 20, 100, 950]),
|
||||
('Alice', [0, 0, 1001, 900]), ('Alice', [1, 2]),
|
||||
('Alice', ['bad', 0, 800, 900]), ('Alice', None),
|
||||
('Outsider', [100, 20, 800, 950]),
|
||||
('Missing', [100, 20, 800, 950])]:
|
||||
with self.subTest(name=name, box=box):
|
||||
self.client.models.generate_content.return_value = Mock(text=json.dumps({'cells': [
|
||||
{'cell': 1, 'name': name, 'box_2d': box},
|
||||
]}))
|
||||
self.assertEqual(self.identify({'Copie01': []}, overwrite=True),
|
||||
{'Copie01': 'Alice' if name == 'Alice' else 'Missing'})
|
||||
self.assertIsNone(names.name_bottom_height_fraction(self.workspace, 'Copie01'))
|
||||
|
||||
def test_legacy_name_cache_is_refreshed_to_request_position(self):
|
||||
self.crop(1)
|
||||
self.client.models.generate_content.return_value = Mock(text=json.dumps({'cells': [
|
||||
{'cell': 1, 'name': 'Alice', 'box_2d': [100, 20, 800, 950]},
|
||||
]}))
|
||||
self.identify({'Copie01': []})
|
||||
path = self.directory / 'Copie01_result.json'
|
||||
cached = read_json(path)
|
||||
del cached['name_bottom_height_fraction']
|
||||
path.write_text(json.dumps(cached))
|
||||
self.identify({'Copie01': []})
|
||||
self.assertEqual(self.client.models.generate_content.call_count, 2)
|
||||
self.assertIsNotNone(names.name_bottom_height_fraction(self.workspace, 'Copie01'))
|
||||
|
||||
def test_known_and_missing_names_choose_different_label_requests(self):
|
||||
for number in (1, 2):
|
||||
self.crop(number)
|
||||
|
||||
Reference in new issue
Block a user