diff --git a/tests/assets/images/logo.ico b/tests/assets/images/logo.ico new file mode 100644 index 00000000..3d6d2f9f Binary files /dev/null and b/tests/assets/images/logo.ico differ diff --git a/tests/test_animation/test_animations.py b/tests/test_animation/test_animations.py index 19782b29..c9c70e6d 100644 --- a/tests/test_animation/test_animations.py +++ b/tests/test_animation/test_animations.py @@ -38,9 +38,9 @@ def test_fps(self) -> None: def test_active(self) -> None: an = animations.Animation(60, lambda _: None) an.start() - self.assertEqual(an.active, True) + self.assertTrue(an.active) an.stop() - self.assertEqual(an.active, False) + self.assertFalse(an.active) @unittest.skipIf(platform.system() == "Linux", "No display name.") def test_skip(self) -> None: @@ -55,7 +55,7 @@ def test_skip(self) -> None: self.assertEqual(an._count, 0) @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test_count(self) -> None: # TODO + def test_count(self) -> None: an = animations.Animation(60, lambda _: None) an2 = animations.Animation(60, lambda _: None, repeat=2) @@ -78,7 +78,7 @@ def test_total_frames(self) -> None: an.stop() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test_repeat(self) -> None: # TODO + def test_repeat(self) -> None: an = animations.Animation(60, lambda _: None, repeat=0) an2 = animations.Animation(60, lambda _: None, repeat=1) an3 = animations.Animation(60, lambda _: None, repeat=2) @@ -136,7 +136,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: animations.MoveWindow(self.tk, (99, 99), 1, fps=1).command(1) animations.MoveWindow(self.top, (99, 99), 1, fps=1).command(1) @@ -157,7 +157,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: animations.MoveWindow(self.tk, (-99, -99), 1, fps=1).command(1) animations.MoveWindow(self.top, (-99, -99), 1, fps=1).command(1) @@ -183,7 +183,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: self.assertWarns(UserWarning, lambda: animations.MoveTkWidget(self.widget, (99, 99), 99)) self.assertWarns(UserWarning, lambda: animations.MoveTkWidget(self.widget2, (99, 99), 99)) self.an = animations.MoveTkWidget(self.widget3, (99, 99), 99) @@ -202,7 +202,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: self.an = animations.MoveWidget(self.widget, (99, 99), 99) self.an.start() @@ -219,7 +219,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: self.an = animations.MoveElement(self.widget.elements[0], (99, 99), 99) self.an.start() @@ -236,7 +236,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: self.an = animations.MoveItem(self.cv, self.item, (99, 99), 99) self.an.start() @@ -252,7 +252,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: self.an = animations.GradientTkWidget(self.widget, "fill", ("red", "#00FF00"), 99) self.an.start() self.assertRaises(ValueError, lambda: animations.GradientTkWidget(self.widget, "fill", ("", ""), 1000)) @@ -270,7 +270,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: self.an = animations.GradientItem(self.cv, self.item, "fill", ("red", "#0000FF"), 99) self.an.start() self.assertRaises(ValueError, lambda: animations.GradientItem(self.cv, self.item, "fill", ("", ""), 1000)) @@ -291,7 +291,7 @@ def tearDown(self) -> None: self.tk.destroy() @unittest.skipIf(platform.system() == "Linux", "No display name.") - def test(self) -> None: + def test_init(self) -> None: self.an1 = animations.ScaleFontSize(self.widget.texts[0], 10, 99) self.an1.start() self.an2 = animations.ScaleFontSize(self.widget.texts[0], 24.5, 99) diff --git a/tests/test_animation/test_contollers.py b/tests/test_animation/test_contollers.py index b7b539d1..a08b9e85 100644 --- a/tests/test_animation/test_contollers.py +++ b/tests/test_animation/test_contollers.py @@ -6,7 +6,7 @@ from tkintertools.animation import controllers -class Test(unittest.TestCase): +class TestCase(unittest.TestCase): def test_linear(self) -> None: self.assertEqual(controllers.linear(0), 0) diff --git a/tests/test_color/test_convert.py b/tests/test_color/test_convert.py index 96f572f7..8200e058 100644 --- a/tests/test_color/test_convert.py +++ b/tests/test_color/test_convert.py @@ -7,7 +7,7 @@ from tkintertools.color import convert -class Test(unittest.TestCase): +class TestCase(unittest.TestCase): def test_rgb_to_hex(self) -> None: self.assertEqual(convert.rgb_to_hex((255, 255, 255)), "#FFFFFF") diff --git a/tests/test_color/test_hsl.py b/tests/test_color/test_hsl.py index 13770d65..e0a515d8 100644 --- a/tests/test_color/test_hsl.py +++ b/tests/test_color/test_hsl.py @@ -6,7 +6,7 @@ from tkintertools.color import hsl -class Test(unittest.TestCase): +class TestCase(unittest.TestCase): def test_contrast(self) -> None: self.assertEqual(hsl.contrast((1, 1, 1)), (math.tau - 1, 0, 0)) diff --git a/tests/test_color/test_rgb.py b/tests/test_color/test_rgb.py index 3044fe48..a105332f 100644 --- a/tests/test_color/test_rgb.py +++ b/tests/test_color/test_rgb.py @@ -5,7 +5,7 @@ from tkintertools.color import rgb -class Test(unittest.TestCase): +class TestCase(unittest.TestCase): def test_contrast(self) -> None: self.assertEqual(rgb.contrast((0, 0, 0)), (255, 255, 255)) diff --git a/tests/test_core/test_configs.py b/tests/test_core/test_configs.py index e397b292..e740418a 100644 --- a/tests/test_core/test_configs.py +++ b/tests/test_core/test_configs.py @@ -17,9 +17,9 @@ def test_reset(self) -> None: configs.Env.reset() self.assertEqual(configs.Env.system, configs.Env.get_default_system()) - self.assertEqual(configs.Env.is_dark, False) - self.assertEqual(configs.Env.default_animation, True) - self.assertEqual(configs.Env.auto_update, True) + self.assertFalse(configs.Env.is_dark) + self.assertTrue(configs.Env.default_animation) + self.assertTrue(configs.Env.auto_update) def test_get_default_system(self) -> None: with unittest.mock.patch('platform.system', return_value='Windows'): diff --git a/tests/test_core/test_containers.py b/tests/test_core/test_containers.py new file mode 100644 index 00000000..5e2a3771 --- /dev/null +++ b/tests/test_core/test_containers.py @@ -0,0 +1,167 @@ +# pylint: disable=all + +import contextlib +import io +import unittest +import unittest.mock + +from tkintertools.core import containers +from tkintertools.standard import widgets + + +class TestTk(unittest.TestCase): + + def test_init(self) -> None: + containers.Tk(icon="").destroy() + containers.Tk(icon="tests/assets/images/logo.ico").destroy() + containers.Tk(title=":)").destroy() + + with unittest.mock.patch("platform.system", return_value="Darwin"): + containers.Tk(icon="tests/assets/images/logo.ico").destroy() + + def test_ratios(self) -> None: + with containers.Tk() as tk: + self.assertEqual(tk.ratios, (1., 1.)) + tk.wm_geometry(f"{tk.size[0]//2}x{tk.size[1]//2}") + tk.update_idletasks() + tk._zoom() + self.assertEqual(tk.ratios, (0.5, 0.5)) + + def test_alpha(self) -> None: + with containers.Tk() as tk: + self.assertEqual(tk.alpha(), 1.) + self.assertIsNone(tk.alpha(0.8)) + self.assertEqual(tk.alpha(), 0.8) + + def test_topmost(self) -> None: + with containers.Tk() as tk: + self.assertIsNone(tk.topmost()) + self.assertTrue(tk.topmost(None)) + self.assertIsNone(tk.topmost(False)) + self.assertFalse(tk.topmost(None)) + + def test_fullscreen(self) -> None: + with containers.Tk() as tk: + self.assertIsNone(tk.fullscreen()) + self.assertTrue(tk.fullscreen(None)) + self.assertIsNone(tk.fullscreen(False)) + self.assertFalse(tk.fullscreen(None)) + + def test_toolwindow(self) -> None: + with containers.Tk() as tk: + self.assertIsNone(tk.toolwindow()) + self.assertTrue(tk.toolwindow(None)) + self.assertIsNone(tk.toolwindow(False)) + self.assertFalse(tk.toolwindow(None)) + + def test_transparentcolor(self) -> None: + with containers.Tk() as tk: + self.assertEqual(tk.transparentcolor(), None) + self.assertIsNone(tk.transparentcolor("red")) + self.assertEqual(tk.transparentcolor(), "red") + self.assertIsNone(tk.transparentcolor("")) + self.assertEqual(tk.transparentcolor(), None) + + def test_center(self) -> None: + with containers.Tk() as tk: + tk.center() + with containers.Toplevel() as tl: + tl.center(refer=tk) + + def test_theme(self) -> None: + with containers.Tk() as tk: + with containers.Toplevel(tk): + with containers.Canvas(tk): + tk.theme(True, include_children=True, include_canvases=True) + + def test_at_exit(self) -> None: + a = None + + def command() -> None: + nonlocal a + a = True + + with containers.Tk() as tk: + tk.at_exit(command, ensure_destroy=False) + tk.call(tk.wm_protocol("WM_DELETE_WINDOW")) + + self.assertTrue(a) + + tk = containers.Tk() # NOTE: This does not need to be destroyed again + tk.at_exit(lambda: None) + tk.call(tk.wm_protocol("WM_DELETE_WINDOW")) + + def callback_raise() -> None: + raise RuntimeError + + with io.StringIO() as captured_output: + with contextlib.redirect_stderr(captured_output): + with containers.Tk() as tk: + tk.at_exit(callback_raise, ensure_destroy=False) + tk.call(tk.wm_protocol("WM_DELETE_WINDOW")) + + self.assertTrue(bool(captured_output.getvalue())) + + def test_zoom(self) -> None: + with containers.Tk() as tk: + with containers.Canvas(tk): + tk.ratios # trigger caching + tk.geometry(size=(23, 33)) + tk.update_idletasks() + tk._zoom() + + @unittest.mock.patch("tkintertools.core.containers.Tk.theme") + def test_wrap_method(self, mock_theme: unittest.mock.Mock) -> None: + with containers.Tk() as tk: + tk._wrap_method("wm_resizable") + tk.wm_resizable(False, False) + mock_theme.assert_called() + + +class TestToplevel(unittest.TestCase): + + def setUp(self) -> None: + self.tk = containers.Tk() + + def tearDown(self) -> None: + self.tk.destroy() + + def test_init(self) -> None: + self.tl = containers.Toplevel(grab=True, focus=True) + + +class TestCanvas(unittest.TestCase): + + def test_init(self) -> None: + with containers.Tk() as tk: + containers.Canvas(tk, auto_update=True) + + def test_ratios(self) -> None: + with containers.Tk() as tk: + with containers.Canvas(tk) as cv: + cv.place(width=100, height=100) + cv.update_idletasks() + self.assertEqual(cv.ratios, (1., 1.)) + cv.place(width=50, height=50) + cv.update_idletasks() + self.assertEqual(cv.ratios, (0.5, 0.5)) + + def test_theme(self) -> None: + with containers.Tk() as tk: + with containers.Canvas(tk) as cv: + widgets.Button(cv, (0, 0), auto_update=True) + widgets.Button(cv, (0, 0), auto_update=False) + widgets.Button(cv, (0, 0), auto_update=True).disable() + with containers.Canvas(cv): + cv.theme(True) + + def test_initialization(self) -> None: + with containers.Tk() as tk: + for anchor in "nw", "n", "w", "ne", "sw", "e", "s", "se", "center": + with containers.Canvas(tk) as cv: + cv.place(width=100, height=100, anchor=anchor) + cv._initialization() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_theme/test_manager.py b/tests/test_theme/test_manager.py index 08ad2694..2754b8d4 100644 --- a/tests/test_theme/test_manager.py +++ b/tests/test_theme/test_manager.py @@ -12,7 +12,7 @@ @unittest.skipIf(platform.system() == "Linux", "No display name.") -class Test(unittest.TestCase): +class TestCase(unittest.TestCase): def setUp(self) -> None: self.tk = containers.Tk() diff --git a/tests/test_toolbox/test_utility.py b/tests/test_toolbox/test_utility.py index 5cd0d3c6..d1644252 100644 --- a/tests/test_toolbox/test_utility.py +++ b/tests/test_toolbox/test_utility.py @@ -37,7 +37,7 @@ def test_lock(self) -> None: self.assertTrue(self.t.get()) -class Test(unittest.TestCase): +class TestCase(unittest.TestCase): @unittest.skipIf(platform.system() == "Linux", "No display name.") def setUp(self) -> None: