def ensure_correct_plot(function_name): for a_plot, label in PLOT_LABEL.items(): if function_name == a_plot: if not function_is_called(function_name): gently_r("You are not calling the <code>{func_name}</code> function.".format(func_name=function_name), "no_{func_name}_call".format(func_name=function_name)) return True elif function_is_called(a_plot): gently_r("You have called the <code>{}</code> function, which makes a {}.".format(a_plot, label), "wrong_plt") return True return False
def ensure_correct_plot(function_name): for a_plot, label in PLOT_LABEL.items(): if function_name == a_plot: if not function_is_called(function_name): gently("You are not calling the <code>{func_name}</code> function." "<br><br><i>(no_{func_name}_call)<i>".format(func_name=function_name)) return True elif function_is_called(a_plot): gently("You have called the <code>{}</code> function, which makes a {}." "<br><br><i>(wrong_plt)<i>".format(a_plot, label)) return True return False
def ensure_show(): if not function_is_called("show"): gently("You have not called <code>show</code> function, which " "actually creates the graph.<br><br><i>(no_show)<i>") return True return False
def test_function_is_called(self): with Execution('a=[]\na.append(a)\na.pop()\n') as e: self.assertTrue(function_is_called('pop')) self.assertFalse(function_is_called('print')) self.assertEqual(e.message, "No errors reported.")