Add more BaseFormatter subclass tests

This commit is contained in:
Ian Cordasco 2016-06-04 13:02:29 -05:00
parent d477715064
commit 9ecca93a9b
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A

View file

@ -114,5 +114,31 @@ class AfterInitFormatter(base.BaseFormatter):
def test_after_init_is_always_called():
"""Verify after_init is called."""
formatter = AfterInitFormatter()
formatter = AfterInitFormatter(options())
assert getattr(formatter, 'post_initialized') is True
class FormatFormatter(base.BaseFormatter):
"""Subclass for testing format."""
def format(self, error):
"""Define method to verify operation."""
return repr(error)
def test_handle_formats_the_error():
"""Verify that a formatter will call format from handle."""
formatter = FormatFormatter(options(show_source=False))
filemock = formatter.output_fd = mock.Mock()
error = style_guide.Error(
code='A001',
filename='example.py',
line_number=1,
column_number=1,
text='Fake error',
physical_line='a = 1',
)
formatter.handle(error)
filemock.write.assert_called_once_with(repr(error) + '\n')