def test_should_align_table_to_middle_center(self, mock_grid): align = TableAlign(HAlign.CENTER, VAlign.MIDDLE, top=10, bottom=50) Table(Canvas(), self.get_header(), 10, align) self.assertListEqual([ mock.call([ 42.51968503937, 170.07874015748024, 240.94488188976374, 325.9842519685039, 396.8503937007874, 481.8897637795275, 552.755905511811 ], [ 711.496062992126, 683.1496062992126, 654.8031496062991, 626.4566929133858, 598.1102362204724, 569.763779527559, 541.4173228346457, 513.0708661417323, 484.72440944881885, 456.3779527559055, 428.03149606299206, 399.6850393700787, 371.33858267716533, 342.9921259842519, 314.64566929133855, 286.29921259842513, 257.95275590551176, 229.60629921259837, 201.25984251968498, 172.9133858267716, 144.5669291338582, 116.22047244094482, 87.87401574803134 ]), mock.call([ 42.51968503937, 170.07874015748024, 240.94488188976374, 325.9842519685039, 396.8503937007874, 481.8897637795275, 552.755905511811 ], [754.0157480314962, 711.496062992126]) ], mock_grid.mock_calls)
def test_should_align_table_to_bottom_center(self, mock_grid): align = TableAlign(HAlign.CENTER, VAlign.BOTTOM, top=50, bottom=0.5) Table(Canvas(), self.get_header(), 10, align) self.assertListEqual([ mock.call([ 42.51968503937, 170.07874015748024, 240.94488188976374, 325.9842519685039, 396.8503937007874, 481.8897637795275, 552.755905511811 ], [ 653.5275590551182, 625.1811023622048, 596.8346456692914, 568.4881889763781, 540.1417322834646, 511.7952755905513, 483.44881889763786, 455.1023622047245, 426.7559055118111, 398.4094488188977, 370.0629921259843, 341.71653543307093, 313.37007874015757, 285.02362204724415, 256.6771653543308, 228.3307086614174, 199.984251968504, 171.6377952755906, 143.2913385826772, 114.94488188976382, 86.59842519685043, 58.25196850393704, 29.905511811023658, 1.5590551181102685 ]), mock.call([ 42.51968503937, 170.07874015748024, 240.94488188976374, 325.9842519685039, 396.8503937007874, 481.8897637795275, 552.755905511811 ], [696.0472440944883, 653.5275590551182]) ], mock_grid.mock_calls)
def test_should_align_table_to_top_right(self, mock_grid): align = TableAlign(HAlign.RIGHT, VAlign.TOP, right=0.5, top=0.5, bottom=50) Table(Canvas(), self.get_header(), 10, align) self.assertListEqual([ mock.call([ 83.19685039370064, 210.75590551181088, 281.62204724409435, 366.6614173228345, 437.527559055118, 522.5669291338581, 593.4330708661416 ], [ 797.5275590551181, 769.1811023622047, 740.8346456692913, 712.4881889763778, 684.1417322834644, 655.7952755905511, 627.4488188976377, 599.1023622047243, 570.7559055118109, 542.4094488188975, 514.0629921259841, 485.71653543307076, 457.37007874015734, 429.023622047244, 400.67716535433055, 372.3307086614172, 343.98425196850377, 315.6377952755904, 287.29133858267704, 258.9448818897636, 230.59842519685023, 202.25196850393687, 173.90551181102347, 145.55905511811008 ]), mock.call([ 83.19685039370064, 210.75590551181088, 281.62204724409435, 366.6614173228345, 437.527559055118, 522.5669291338581, 593.4330708661416 ], [840.0472440944882, 797.5275590551181]) ], mock_grid.mock_calls)
def test_should_align_table_to_top_center(self, mock_grid): align = TableAlign(HAlign.CENTER, VAlign.TOP, top=0.5, bottom=50) Table(Canvas(), self.get_header(), 10, align) self.assertListEqual([ mock.call([ 42.51968503937, 170.07874015748024, 240.94488188976374, 325.9842519685039, 396.8503937007874, 481.8897637795275, 552.755905511811 ], [ 797.5275590551181, 769.1811023622047, 740.8346456692913, 712.4881889763778, 684.1417322834644, 655.7952755905511, 627.4488188976377, 599.1023622047243, 570.7559055118109, 542.4094488188975, 514.0629921259841, 485.71653543307076, 457.37007874015734, 429.023622047244, 400.67716535433055, 372.3307086614172, 343.98425196850377, 315.6377952755904, 287.29133858267704, 258.9448818897636, 230.59842519685023, 202.25196850393687, 173.90551181102347, 145.55905511811008 ]), mock.call([ 42.51968503937, 170.07874015748024, 240.94488188976374, 325.9842519685039, 396.8503937007874, 481.8897637795275, 552.755905511811 ], [840.0472440944882, 797.5275590551181]) ], mock_grid.mock_calls)
def test_should_align_table_to_middle_right(self, mock_grid): align = TableAlign(HAlign.RIGHT, VAlign.MIDDLE, right=0.5, top=10, bottom=50) Table(Canvas(), self.get_header(), 10, align) self.assertListEqual([ mock.call([ 83.19685039370064, 210.75590551181088, 281.62204724409435, 366.6614173228345, 437.527559055118, 522.5669291338581, 593.4330708661416 ], [ 711.496062992126, 683.1496062992126, 654.8031496062991, 626.4566929133858, 598.1102362204724, 569.763779527559, 541.4173228346457, 513.0708661417323, 484.72440944881885, 456.3779527559055, 428.03149606299206, 399.6850393700787, 371.33858267716533, 342.9921259842519, 314.64566929133855, 286.29921259842513, 257.95275590551176, 229.60629921259837, 201.25984251968498, 172.9133858267716, 144.5669291338582, 116.22047244094482, 87.87401574803134 ]), mock.call([ 83.19685039370064, 210.75590551181088, 281.62204724409435, 366.6614173228345, 437.527559055118, 522.5669291338581, 593.4330708661416 ], [754.0157480314962, 711.496062992126]) ], mock_grid.mock_calls)
def test_should_align_table_to_middle_left(self, mock_grid): align = TableAlign(HAlign.LEFT, VAlign.MIDDLE, left=0.5, top=10, bottom=50) Table(Canvas(), self.get_header(), 10, align) self.assertListEqual([ mock.call([ 1.8425196850393704, 129.40157480314963, 200.2677165354331, 285.3070866141733, 356.17322834645677, 441.2125984251969, 512.0787401574804 ], [ 711.496062992126, 683.1496062992126, 654.8031496062991, 626.4566929133858, 598.1102362204724, 569.763779527559, 541.4173228346457, 513.0708661417323, 484.72440944881885, 456.3779527559055, 428.03149606299206, 399.6850393700787, 371.33858267716533, 342.9921259842519, 314.64566929133855, 286.29921259842513, 257.95275590551176, 229.60629921259837, 201.25984251968498, 172.9133858267716, 144.5669291338582, 116.22047244094482, 87.87401574803134 ]), mock.call([ 1.8425196850393704, 129.40157480314963, 200.2677165354331, 285.3070866141733, 356.17322834645677, 441.2125984251969, 512.0787401574804 ], [754.0157480314962, 711.496062992126]) ], mock_grid.mock_calls)
def test_set_margins(self): align = TableAlign(HAlign.LEFT, left=0.1, top=0.3, bottom=0.4) self.assertAlmostEqual(0.1, align.margins.left) self.assertAlmostEqual(0, align.margins.right) self.assertAlmostEqual(0.3, align.margins.top) self.assertAlmostEqual(0.4, align.margins.bottom)
def test_should_mirror_bottom_margin_for_middle_alignment(self): align = TableAlign(v=VAlign.MIDDLE, bottom=5.5) self.assertAlmostEqual(0, align.margins.left) self.assertAlmostEqual(0, align.margins.right) self.assertAlmostEqual(5.5, align.margins.top) self.assertAlmostEqual(5.5, align.margins.bottom)
def test_should_be_centered_in_both_directions_and_have_no_margins_by_default( self): align = TableAlign() self.assertEqual(HAlign.CENTER, align.horizontal) self.assertEqual(VAlign.MIDDLE, align.vertical) self.assertEqual((0, ) * 4, align.margins)
def test_should_reject_left_or_right_margin_for_opposite_alignment(self): for valign in VAlign: with self.assertRaises(AssertionError): TableAlign(HAlign.LEFT, valign, right=0.1) with self.assertRaises(AssertionError): TableAlign(HAlign.RIGHT, valign, left=0.1)
def test_should_reject_left_and_right_margin_for_center_alignment(self): for valign in VAlign: with self.assertRaises(AssertionError): TableAlign(HAlign.CENTER, valign, left=0.1) with self.assertRaises(AssertionError): TableAlign(HAlign.CENTER, valign, right=0.1)
def test_set_vertical_align(self): self.assertEqual(VAlign.BOTTOM, TableAlign(v=VAlign.BOTTOM).vertical)
def test_set_horizontal_align(self): self.assertEqual(HAlign.LEFT, TableAlign(h=HAlign.LEFT).horizontal)