def test_highlight_colors(self): sidebar = self.shell.shell_sidebar test_colors = {"background": '#abcdef', "foreground": '#123456'} orig_idleConf_GetHighlight = idlelib.sidebar.idleConf.GetHighlight def mock_idleconf_GetHighlight(theme, element): if element in ['linenumber', 'console']: return test_colors return orig_idleConf_GetHighlight(theme, element) GetHighlight_patcher = unittest.mock.patch.object( idlelib.sidebar.idleConf, 'GetHighlight', mock_idleconf_GetHighlight) GetHighlight_patcher.start() def cleanup(): GetHighlight_patcher.stop() sidebar.update_colors() self.addCleanup(cleanup) def get_sidebar_colors(): canvas = sidebar.canvas texts = list(canvas.find(tk.ALL)) fgs = {canvas.itemcget(text, 'fill') for text in texts} self.assertEqual(len(fgs), 1) fg = next(iter(fgs)) bg = canvas.cget('background') return {"background": bg, "foreground": fg} self.assertNotEqual(get_sidebar_colors(), test_colors) sidebar.update_colors() self.assertEqual(get_sidebar_colors(), test_colors)
def cleanup(): GetHighlight_patcher.stop() sidebar.update_colors()