Beispiel #1
0
 def test_horizontal_container_basic(self):
     fill1 = Fill('1')
     horizontal_container = HorizontalContainer([fill1])
     self.assertEqual(horizontal_container.draw(3, 1), '111')
     fill2 = Fill('2')
     horizontal_container.add_element(fill2)
     self.assertEqual(horizontal_container.draw(5, 1), '11 22')
     fill3 = Fill('3')
     horizontal_container.add_element(fill3, weight=2)
     self.assertEqual(horizontal_container.draw(10, 1), '11 22 3333')
     horizontal_container.remove_element(fill2)
     self.assertEqual(horizontal_container.draw(4, 1), '1 33')
Beispiel #2
0
 def test_horizontal_container_size_calculation_on_demand(self):
     fill1 = Fill()
     horizontal_container = HorizontalContainer([fill1])
     original_recalc = horizontal_container._recalculate_element_sizes
     patcher = patch(
         'pyamp.ui.HorizontalContainer._recalculate_element_sizes')
     recalc_mock = patcher.start()
     self.addCleanup(patcher.stop)
     recalc_mock.side_effect = original_recalc
     horizontal_container.draw(3, 1)
     self.assertEqual(recalc_mock.call_count, 1)
     horizontal_container.draw(3, 1)
     self.assertEqual(recalc_mock.call_count, 1)
     horizontal_container.draw(4, 1)
     self.assertEqual(recalc_mock.call_count, 2)
     fill2 = Fill()
     horizontal_container.add_element(fill2)
     horizontal_container.draw(4, 1)
     self.assertEqual(recalc_mock.call_count, 3)
     horizontal_container.draw(4, 1)
     self.assertEqual(recalc_mock.call_count, 3)
Beispiel #3
0
 def test_horizontal_container_constraints(self):
     fill1 = Fill('1')
     fill2 = Fill('2')
     horizontal_container = HorizontalContainer([fill1, fill2])
     fill4 = Fill('4')
     fill4.max_width = 2
     horizontal_container.add_element(fill4)
     self.assertEqual(horizontal_container.draw(10, 1), '111 222 44')
     self.assertEqual(horizontal_container.draw(5, 1), '1 2 4')
     fill4.max_width = None
     fill4.min_width = 3
     self.assertEqual(horizontal_container.draw(7, 1), '1 2 444')
     self.assertEqual(horizontal_container.draw(14, 1), '1111 2222 4444')
     fill4.max_width = fill4.min_width = 5
     self.assertEqual(horizontal_container.draw(9, 1), '1 2 44444')
     self.assertEqual(
         horizontal_container.draw(19, 1), '111111 222222 44444')
     horizontal_container.remove_element(fill2)
     self.assertEqual(horizontal_container.draw(7, 1), '1 44444')
     self.assertEqual(horizontal_container.draw(14, 1), '11111111 44444')
     fill1.min_width = 3
     self.assertEqual(horizontal_container.draw(9, 1), '111 44444')