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.")
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")
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")
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")
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 setUp(self) -> None: self.app = MockApp() self.component = components.Swipe(self.app) self.app.components.append(self.component)
def setUp(self) -> None: self.app = MockApp() self.component = components.FontSelector(self.app) self.app.components.append(self.component) self.font = random.choice(self.component._get_fonts())
def setUp(self) -> None: self.app = MockApp() self.component = components.RenderRangeControl(self.app) self.app.components.append(self.component)
def setUp(self) -> None: self.app = MockApp() self.grid = self.app.grid_cluster[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")
def setUp(self) -> None: self.widget = widgets.KeyValueLabel(MockApp(), "key", "value")
def setUp(self) -> None: self.app = MockApp() self.prev_fav = self.app.favourites_as_list()
class AppFavouritesHandlingTestCase(unittest.TestCase): def setUp(self) -> None: self.app = MockApp() self.prev_fav = self.app.favourites_as_list() def tearDown(self) -> None: self.app.set_favourites(self.prev_fav) def test_key_safety(self): self.app.remove_favourites() with self.app.get_favourites() as data: self.assertIn("favourites", data, "Key safety failed") def test_set_favourites(self): self.app.set_favourites([(45000, "Arial")]) self.assertEqual(self.app.favourites_as_list(), [(45000, "Arial")]) def test_toggling(self): self.app.set_favourites([]) grid = self.app.grid_cluster[0] grid.lock() self.app.toggle_from_favourites() self.assertIn((grid.code_point, grid.font), self.app.favourites_as_list(), "Toggle from favourites failed") self.app.toggle_from_favourites() self.assertNotIn((grid.code_point, grid.font), self.app.favourites_as_list(), "Toggle from favourites failed")
def setUp(self) -> None: self.app = MockApp()
def setUp(self) -> None: self.app = MockApp() self.dialog = dialogs.ManageFavourites(self.app) self.prev_fav = self.app.favourites_as_list()
class ManageFavouritesTestCase(unittest.TestCase): def setUp(self) -> None: self.app = MockApp() self.dialog = dialogs.ManageFavourites(self.app) self.prev_fav = self.app.favourites_as_list() def tearDown(self) -> None: self.app.set_favourites(self.prev_fav) def test_favourite_loading(self): self.app.set_favourites([(45000, 'Arial'), (45000, 'Arial black'), (5000, 'Elephant'), (6000, 'Courier'), (45000, 'Courier New'), (5000, 'Lucida Sans'), (4000, 'Lucida Fax')]) self.dialog.load_favourites() self.assertEqual(len(self.dialog.grids), len(self.app.favourites_as_list()), "Could not load favourites") self.assertEqual(self.dialog.grids[0].font, 'Arial', 'Incorrect font loaded') self.assertEqual(ord(self.dialog.grids[0]['text']), 45000, 'Incorrect code point loaded') def test_favourite_clearing(self): self.dialog.clear_favourites() self.app.set_favourites([(45000, 'Arial'), (45000, 'Arial black')]) self.dialog.load_favourites() self.assertEqual(len(self.dialog.grids), len(self.app.favourites_as_list()), "Could not load favourites") self.dialog.clear_favourites() self.assertEqual(len(self.dialog.grids), 0, "Could not clear favourites") def test_hovering(self): self.dialog.clear_favourites() self.app.set_favourites([(45000, 'Arial'), (45000, 'Arial black')]) self.dialog.load_favourites() tracker = components.GridTracker(self.dialog) self.dialog.components.append(tracker) grid_1 = random.choice(self.dialog.grids) grid_1.hover(True) self.assertEqual(grid_1.text, tracker.text, "Failed to dispatch hovered grid") grid_1.hover(False) self.dialog.deactivate_grid() self.assertEqual(tracker.text, "", "Failed to remove no longer hovered grid") def test_lock_mechanism(self): self.app.set_favourites([(45000, 'Arial'), (45000, 'Arial black')]) self.dialog.load_favourites() tracker = components.GridTracker(self.dialog) self.dialog.components.append(tracker) grid_1, grid_2, *_ = self.dialog.grids grid_1.lock() self.assertEqual(self.dialog.active_grid, grid_1, "Locked failed") grid_2.lock() self.assertEqual(self.dialog.active_grid, grid_2, "Unlock then lock new failed") grid_1.hover(True) self.dialog.deactivate_grid() self.assertEqual(tracker.text, grid_2.text, "Failed to persist locked grid") def test_remove_favourite(self): self.app.set_favourites([(45000, 'Arial'), (45000, 'Arial black')]) self.dialog.load_favourites() grid = self.dialog.grids[0] grid.lock() self.dialog.remove() self.assertIsNone(self.dialog.active_grid, "Failed to remove grid") self.assertFalse(grid.winfo_ismapped(), "Failed to remove grid from user interface") self.assertNotIn((45000, 'Arial'), self.app.favourites_as_list(), "Could not remove grid from shelve")