def test_annotate_prints_only_end_msg_plus_newline_when_start_msg_is_none( self): with patch('sys.stdout', new=io.StringIO()) as mock_stdout: msg = 'This is the end' end_only = annotate(end_msg=msg)(self.func) end_only(1, 2, 3) # 3 arbitrary arguments assert mock_stdout.getvalue() == msg + '\n'
def test_annotate_prints_start_and_end_msgs_in_correct_order(self): with patch('sys.stdout', new=io.StringIO()) as mock_stdout: start_msg = 'This is the start' end_msg = 'This is the end' expected_print = start_msg + "\n" + end_msg + "\n" annotated = annotate(start_msg=start_msg, end_msg=end_msg)(self.func) annotated(1, 2, 3) assert mock_stdout.getvalue() == expected_print
def test_annotate_ommits_newline_after_start_msg_if_no_start_nl(self): with patch('sys.stdout', new=io.StringIO()) as mock_stdout: msg = 'This is the start' start_only = annotate(start_msg=msg, start_no_nl=True)(self.func) start_only(1, 2, 3) # 3 arbitrary arguments assert mock_stdout.getvalue() == msg
def test_annotate_does_not_modify_doc(self): expected_doc = self.doc actual_doc = annotate(start_msg='herro')(self.func).__doc__ assert actual_doc == expected_doc
def test_annotate_does_not_modify_signature(self): expected_params = signature(self.func).parameters.keys() animated_func = annotate(start_msg='bogus')(self.func) actual_params = signature(self.func).parameters.keys() assert actual_params == expected_params
def test_annotate_raises_when_end_msg_is_not_none_nor_string(self): with pytest.raises(TypeError): annotate(end_msg=2)
def test_annotate_raises_when_start_and_end_msgs_are_none(self): with pytest.raises(ValueError): annotate()