main
John Lauer Publish 0.1.26 0b71841
import importlib.util,unittest
from pathlib import Path
from shapely.geometry import box,GeometryCollection
s=importlib.util.spec_from_file_location('sections',Path(__file__).with_name('silkscreen-sections.py'));m=importlib.util.module_from_spec(s);s.loader.exec_module(m)
class Sections(unittest.TestCase):
 def test_rows_stay_ordered_and_bottom_reading_edge_aligns(self):
  labels=[dict(text=t,role='service-key') for t in ['Heading','a longer row','short']]
  bounds=lambda i,z,a:[-len(labels[i]['text'])*z/3,-z/2,len(labels[i]['text'])*z/3,z/2]
  section=dict(id='test',rows=[[0],[1],[2]],anchor=[10,10],sizeFactors={'0':1.5})
  for side in ['F.SilkS','B.SilkS']:
   p,missing,_,r=m.place_sections([section],labels,bounds,box(0,0,20,20),box(8,8,9,9),GeometryCollection(),side)
   self.assertEqual(missing,[]);self.assertEqual([x['index'] for x in p],[0,1,2]);self.assertTrue(p[0]['y']<p[1]['y']<p[2]['y']);self.assertGreater(p[0]['size'],p[1]['size'])
   edge=2 if side=='B.SilkS' else 0
   self.assertAlmostEqual(p[0]['box'][edge],p[1]['box'][edge]);self.assertAlmostEqual(p[1]['box'][edge],p[2]['box'][edge])
 def test_impossible_section_is_not_scattered(self):
  p,missing,_,_=m.place_sections([dict(id='blocked',rows=[[0],[1]],anchor=[1,1])],[dict(text='a',role='note')]*2,lambda i,z,a:[-z,-z,z,z],box(0,0,2,2),box(0,0,2,2),GeometryCollection(),'F.SilkS')
  self.assertEqual(p,[]);self.assertEqual(missing,[0,1])
if __name__=='__main__':unittest.main()