Beispiel #1
0
class InputBoxTestCase(unittest.TestCase):

    def setUp(self) -> None:
        self.app = MockApp()
        self.component = components.RenderRangeControl(self.app)
        self.app.components.append(self.component)

    def tearDown(self) -> None:
        self.app.destroy()

    def test_hex_int_input(self):
        # Test data in the form (input_value, expected_value)
        test_data = (
            ("2345", 2345),
            ("234555", 2345),
            ("ffff", int("ffff", 16)),
            ("fffff", int("ffff", 16)),
            ("50000", 50000)
        )
        for datum in test_data:
            self.component.input.set(datum[0])
            with self.subTest(test_data=datum):
                self.assertEqual(self.component.input.get(), datum[1], "Validation failed!")

    def test_range_rendering(self):
        self.component.input.set("50000")
        self.component.render_range()
        self.assertEqual(self.app._from, 50000, "Range not rendered correctly")

    def test_receives_range(self):
        self.app.render(40000)
        self.assertEqual(self.component.input.get(), 40000, "Could not receive range.")
Beispiel #2
0
class SwipeTestCase(unittest.TestCase):

    def setUp(self) -> None:
        self.app = MockApp()
        self.component = components.Swipe(self.app)
        self.app.components.append(self.component)

    def test_render_next(self):
        self.app.render(40000)
        self.component.next_render()
        size = self.app.size[0] * self.app.size[1]
        self.assertEqual(self.component.range[0], 40000 + size, "Failed to render next batch")
        self.app.size = (15, 8)
        self.assertTupleEqual(self.app.size, (15, 8), "Could not change render size.")
        self.app.render(40000)
        self.component.next_render()
        self.assertEqual(self.component.range[0], 40000 + 15 * 8, "Failed to render next batch at different size")

    def test_render_prev(self):
        self.app.render(40000)
        self.component.prev_render()
        size = self.app.size[0] * self.app.size[1]
        self.assertEqual(self.component.range[0], 40000 - size, "Failed to render previous batch")
        self.app.size = (15, 8)
        self.assertTupleEqual(self.app.size, (15, 8), "Could not change render size.")
        self.app.render(40000)
        self.component.prev_render()
        self.assertEqual(self.component.range[0], 40000 - 15 * 8, "Failed to render previous batch at different size")
Beispiel #3
0
class AppGridHandlingTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.app = MockApp()

    def test_init_grids(self):
        # init_grids runs on initialization so just go ahead and assert
        self.assertEqual(len(self.app.body.winfo_children()), MAX_GRID_SIZE,
                         "Grid initialization failed")
        self.assertEqual(len(self.app.grids), MAX_GRID_WIDTH,
                         "Wrong column arrangement")
        for column in self.app.grids:
            with self.subTest(column=column):
                self.assertEqual(len(column), MAX_GRID_HEIGHT,
                                 "column loaded incorrectly")

    def test_size_handling(self):
        size_control = components.RenderSizeControl(self.app)
        self.app.components.append(size_control)
        with self.assertRaises(ValueError, msg="Illegal width size value set"):
            self.app.size = (MAX_GRID_WIDTH + 1, MAX_GRID_HEIGHT)
        with self.assertRaises(ValueError,
                               msg="Illegal height size value set"):
            self.app.size = (MAX_GRID_WIDTH, MAX_GRID_HEIGHT + 1)
        self.app.size = (10, 8)
        self.assertEqual(len(self.app.grid_cluster), 80, "Incorrect size")
        self.assertEqual(size_control.width.get(), 10,
                         "Wrong width value propagated")
        self.assertEqual(size_control.height.get(), 8,
                         "Wrong height value propagated")

    def test_clear_grids(self):
        self.app.clear_grids()
        for grid in self.app.flattened_grids:
            with self.subTest(grid=self.app.flattened_grids.index(grid)):
                self.assertEqual(grid.text, "", "Some grids not cleared")

    def test_rendering(self):
        self.app.size = (10, 8)
        sample_grid = self.app.grid_cluster[0]
        sample_grid.set(45000)
        sample_grid.lock()
        self.app.render(65455)
        for grid in self.app.grid_cluster:
            with self.subTest(grid=grid):
                self.assertNotEqual(grid.text, "", "Incomplete rendering")
        self.assertFalse(sample_grid.is_locked,
                         "Locked not removed by rendering as expected")
        self.app.render(65475)
        # This causes a fracture at 60 grids because then the range is beyond 0xffff
        for grid in self.app.grid_cluster[60:]:
            with self.subTest(grid=grid):
                self.assertEqual(grid.text, "",
                                 "Fracture failed. Illegal grid rendering")
        self.app.grid_cluster[0].lock()
        self.app.render(0xffff + 10)
        self.assertTrue(sample_grid.is_locked,
                        "Illegal rendering of a range beyond limit")