Exemple #1
0
 def test_materialization(self):
     block = RecBlock(self.layout, False, 0, 0, 8, 8)
     virtual = block._virtualize()
     self.assertEqual(
         set(RecBlock._materialize_virtual_block(0, 0, virtual)),
         {(w, self.layout._get_item_position(w, False))
          for w in self.ws})
Exemple #2
0
 def test_subset_virtualization(self):
     block = RecBlock(self.layout, False, 2, 4, 6, 4)
     self.assertEqual(block._virtualize(),
                      [(self.ws[3], self.ws[3], self.ws[3], self.ws[3]),
                       (self.ws[3], self.ws[3], self.ws[3], self.ws[3]),
                       (self.ws[3], self.ws[3], self.ws[3], self.ws[3]),
                       (self.ws[3], self.ws[3], self.ws[3], self.ws[3]),
                       (self.ws[5], self.ws[5], self.ws[5], self.ws[5]),
                       (self.ws[5], self.ws[5], self.ws[5], self.ws[5])])
Exemple #3
0
 def test_non_rectangular_blocks(self):
     with self.assertRaises(NonRectangularRecBlockException):
         RecBlock(self.layout, False, 2, 0, 6, 8)
     with self.assertRaises(NonRectangularRecBlockException):
         RecBlock(self.layout, False, 0, 0, 3, 3)
     with self.assertRaises(NonRectangularRecBlockException):
         RecBlock(self.layout, False, 0, 2, 3, 6)
     with self.assertRaises(NonRectangularRecBlockException):
         RecBlock(self.layout, False, 2, 3, 4, 5)
Exemple #4
0
 def test_virtualization(self):
     block = RecBlock(self.layout, False, 0, 0, 8, 8)
     l = self.ws
     self.assertEqual(block._virtualize(),
                      [(l[0], l[0], l[1], l[1], l[1], l[1], l[1], l[1]),
                       (l[0], l[0], l[1], l[1], l[1], l[1], l[1], l[1]),
                       (l[0], l[0], l[2], None, l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[5], l[5], l[5], l[5]),
                       (l[4], l[4], l[4], l[4], l[5], l[5], l[5], l[5])])
Exemple #5
0
 def test_displaced_materialization(self):
     block = RecBlock(self.layout, False, 0, 0, 8, 8)
     virtual = block._virtualize()
     offset = (1, 2)
     expected = [(w, self.layout._get_item_position(w, False))
                 for w in self.ws]
     for i in range(0, len(expected)):
         widget, pos = expected[i]
         expected[i] = (widget, (pos[0] + offset[0], pos[1] + offset[1],
                                 pos[2], pos[3]))
     self.assertEqual(
         set(RecBlock._materialize_virtual_block(*offset, virtual)),
         set(expected))
Exemple #6
0
 def test_find(self):
     self.assertEqual(
         EmptyBlock.find_in_block(RecBlock(self.layout, False, 0, 0, 5, 5)),
         EmptyBlock(self.layout, False, 1, 1, 1, 3))
     self.assertEqual(
         EmptyBlock.find_in_block(Block(self.layout, False, 1, 1, 3, 2)),
         EmptyBlock(self.layout, False, 1, 1, 2, 2))
     self.assertEqual(
         EmptyBlock.find_in_block(Block(self.layout, False, 3, 1, 3, 3)),
         EmptyBlock(self.layout, False, 3, 1, 2, 1))
Exemple #7
0
 def test_no_suitable_block(self):
     layout = QTilingLayout(max_span=3)
     widgets = [Widget(0), Widget(1), Widget(2), Widget(3), Widget(4)]
     layout.addWidget(widgets[0], 0, 0, 2, 1)
     layout.addWidget(widgets[1], 0, 1, 1, 2)
     layout.addWidget(widgets[2], 1, 2, 2, 1)
     layout.addWidget(widgets[3], 2, 0, 1, 1)
     layout.addWidget(widgets[4], 2, 1, 1, 1)
     with self.assertRaises(ImpossibleToBuildBlockException):
         layout._fill_spaces(RecBlock(layout, False, 0, 0, 3, 3))
Exemple #8
0
 def test_left_space(self):
     layout = QTilingLayout(max_span=3)
     widgets = [Widget(0), Widget(1)]
     layout.addWidget(widgets[0], 0, 2, 1, 1)
     layout.addWidget(widgets[1], 2, 0, 1, 2)
     layout._drop_hanging_widgets(RecBlock(layout, False, 0, 0, 3, 3))
     self.assertEqual(layout._get_item_position(widgets[0], False),
                      (2, 2, 1, 1))
     self.assertEqual(layout._get_item_position(widgets[1], False),
                      (2, 0, 1, 2))
Exemple #9
0
 def test_right_block(self):
     layout = QTilingLayout(max_span=3)
     widgets = [Widget(0), Widget(1), Widget(2)]
     layout.addWidget(widgets[0], 0, 0, 2, 1)
     layout.addWidget(widgets[1], 0, 1, 1, 2)
     layout.addWidget(widgets[2], 1, 2, 1, 1)
     layout._fill_spaces(RecBlock(layout, False, 0, 0, 3, 3))
     self.assertEqual(layout._get_item_position(widgets[0], False),
                      (0, 0, 3, 1))
     self.assertEqual(layout._get_item_position(widgets[1], False),
                      (0, 1, 2, 2))
     self.assertEqual(layout._get_item_position(widgets[2], False),
                      (2, 1, 1, 2))
Exemple #10
0
 def test_displace_and_resize(self):
     l = self.ws
     block = RecBlock(self.layout, False, 0, 0, 8, 8)
     block.displace_and_resize(4, -4)
     block = RecBlock(self.layout, False, 0, 0, 8, 8)
     self.assertEqual(block._virtualize(),
                      [(None, None, None, None, None, None, None, None),
                       (None, None, None, None, None, None, None, None),
                       (None, None, None, None, None, None, None, None),
                       (None, None, None, None, None, None, None, None),
                       (l[0], l[0], l[1], l[1], l[1], l[1], l[1], l[1]),
                       (l[0], l[0], l[2], None, l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[5], l[5], l[5], l[5])])
     block.displace_and_resize(-2, 2)
     block = RecBlock(self.layout, False, 0, 0, 8, 8)
     self.assertEqual(block._virtualize(),
                      [(None, None, None, None, None, None, None, None),
                       (None, None, None, None, None, None, None, None),
                       (l[0], l[0], l[1], l[1], l[1], l[1], l[1], l[1]),
                       (l[0], l[0], l[1], l[1], l[1], l[1], l[1], l[1]),
                       (l[0], l[0], l[2], None, l[3], l[3], l[3], l[3]),
                       (l[0], l[0], l[2], None, l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[3], l[3], l[3], l[3]),
                       (l[4], l[4], l[4], l[4], l[5], l[5], l[5], l[5])])
Exemple #11
0
 def test_shrink_failure(self):
     block = RecBlock(self.layout, False, 0, 0, 8, 8)
     with self.assertRaises(SplitLimitException):
         block.displace_and_resize(0, -5)
Exemple #12
0
 def test_get_widgets(self):
     self.assertEqual(
         list(RecBlock(self.layout, False, 0, 0, 8, 8).get_widgets()),
         [(self.ws[0], (0, 0, 3, 2)), (self.ws[1], (0, 2, 2, 6)),
          (self.ws[2], (2, 2, 1, 1)), (self.ws[3], (2, 4, 4, 4)),
          (self.ws[4], (3, 0, 5, 4)), (self.ws[5], (6, 4, 2, 4))])
Exemple #13
0
 def test_valid_block(self):
     p = (0, 0, 8, 8)
     block = RecBlock(self.layout, False, *p)
     self.assertEqual((block.i, block.j, block.rowspan, block.colspan), p)