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

    def setUp(self) -> None:
        self.app = MockApp()
        self.component = components.GridTracker(self.app)
        self.app.components.append(self.component)
        self.grid = self.app.grid_cluster[0]

    def test_grid_reception(self):
        self.assertIsNone(self.app.active_grid, "Active grid prematurely set")
        self.grid.hover(True)
        self.assertEqual(self.component.text, self.grid.text, "Improper grid reception")
        self.app.deactivate_grid()
        self.assertFalse(self.component.text, "Could not reset text")

    def test_grid_deactivation(self):
        self.grid.hover(True)
        self.app.deactivate_grid()
        self.assertFalse(self.component.text, "Could not reset text")

    def test_grid_persistence(self):
        other_grid = self.app.grid_cluster[1]
        self.grid.lock()
        other_grid.hover(True)
        self.assertEqual(self.component.text, other_grid.text, "Improper grid reception")
        self.app.deactivate_grid()
        self.assertEqual(self.component.text, self.grid.text, "Failed to persists locked grid")

    def test_text_format(self):
        self.grid.hover(True)
        # Text format for grid tracker
        for i in range(10, 0xffff, 1310):
            with self.subTest(code_point=i):
                self.grid.set(i)
                self.grid.hover(True)
                t_format = "{} : {}".format(chr(int(self.grid.text, 16)), self.grid.text.replace("0x", ""))
                self.assertEqual(t_format, self.component.info['text'], "Improper text format")
Beispiel #2
0
class GridTestCase(unittest.TestCase):

    def setUp(self) -> None:
        self.app = MockApp()
        self.grid = self.app.grid_cluster[0]

    def test_hover(self):
        self.grid.hover(True)
        self.assertEqual(self.grid["bg"], "#bbb", "Hovering failed")
        self.grid.hover(False)
        self.assertEqual(self.grid['bg'], "#f7f7f7", "Could not exit hovering")
        self.grid.set(None)
        self.app.deactivate_grid()
        self.grid.hover(True)
        self.assertEqual(self.grid['bg'], "#f7f7f7", "Illegal hovering. Text required constraint failed")

    def test_lock_system(self):
        self.grid.lock()
        self.assertTrue(self.grid.is_locked, "Failed to lock grid")
        other_grid = self.app.grid_cluster[1]
        other_grid.lock()
        self.assertFalse(self.grid.is_locked, "Could not unlock grid")
        self.grid.hover(True)
        self.grid.lock()
        self.grid.hover(False)
        self.assertEqual(self.grid['bg'], "#bbb", "Grid lost lock on hover exit")
        self.grid.unlock()
        self.grid.set(None)
        self.grid.lock()
        self.assertFalse(self.grid.is_locked, "Text required constraint failed")

    def test_font_handling(self):
        test_fonts = (
            (('Arial', 12), "Arial"),
            ('Arial 12', 'Arial'),
            ('Arial', 'Arial'),
            (('Arial Black', 12), 'Arial Black'),
            ('{Arial Black} 12', 'Arial Black')
        )
        for test_font in test_fonts:
            with self.subTest(font=test_font[0]):
                self.grid['font'] = test_font[0]
                self.assertEqual(self.grid.font, test_font[1])

    def test_copy_mechanism(self):
        self.grid.set(45000)
        self.grid.copy(0)
        self.assertEqual(self.grid.clipboard_get(), "\uafc8", "Failed to copy unicode")
        self.grid.copy(1)
        self.assertEqual(self.grid.clipboard_get(), "afc8", "Failed to copy hex scalar")
        self.grid.copy(2)
        self.assertEqual(self.grid.clipboard_get(), "45000", "Failed to copy code point")

    def test_text_set(self):
        self.grid.set(45000)
        self.assertEqual(self.grid.text, "0xafc8", "Text set incorrectly")
        self.assertEqual(self.grid['text'], chr(45000), "Text set incorrectly")
        self.grid.set(None)
        self.assertEqual(self.grid.text, "", "Text unset incorrectly")
        self.assertEqual(self.grid['text'], "", "Text unset incorrectly")

    def test_menu_request(self):
        self.grid.request_menu(MockEvent())
        self.assertTrue(self.grid.is_locked, "Lock not set on menu request")
        self.grid.set(None)
        self.grid.unlock()
        self.grid.request_menu(MockEvent())
        self.assertFalse(self.grid.is_locked, "Illegal menu request went through")

    def test_data_retrieval(self):
        self.grid['font'] = ('Arial Black', 12)
        self.grid.set(45000)
        data = self.grid.data
        self.assertEqual(data["Font family"], "Arial Black", "Incorrect font returned")
        self.assertEqual(data["Code point"], "45000", "Incorrect code point returned")
        self.assertEqual(data["Hexadecimal scalar"], "afc8", "Incorrect hex scalar returned")