import unittest from importlib.util import spec_from_file_location, module_from_spec from pathlib import Path spec = spec_from_file_location('baseline_math', Path(__file__).with_name('baseline-math.py')) module = module_from_spec(spec); spec.loader.exec_module(module) class BaselineMathTests(unittest.TestCase): def test_metric_offset_is_not_a_baseline_shift(self): result = module.compare(56, 92, 92, 67, 100/3, -250) self.assertGreater(result['oldCellDeltaMm'], 2) self.assertEqual(result['baselineDeltaMm'], 0) self.assertAlmostEqual(result['cellFormulaResidualPx'], 0) def test_actual_render_shift_still_exceeds_same_two_mm_bound(self): result = module.compare(56, 92, 112, 87, 100/3, -250) self.assertGreater(result['baselineDeltaMm'], 2) def test_descriptor_sign_is_normalised_like_installed_pdfminer(self): self.assertEqual(module.compare(56,92,92,67,100/3,250), module.compare(56,92,92,67,100/3,-250)) def test_wrong_font_cell_metadata_is_detected(self): self.assertGreater(module.compare(56,92,92,60,100/3,-250)['cellFormulaResidualPx'], 1) def test_exact_physical_unit_conversion(self): self.assertAlmostEqual(module.MM_PER_PIXEL * 96, 25.4) if __name__ == '__main__': unittest.main(verbosity=2)