Fix lint
This commit is contained in:
parent
bd3d091318
commit
bfc114ae35
@ -17,6 +17,8 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
"""Tests for qutebrowser.misc.lineparser."""
|
"""Tests for qutebrowser.misc.lineparser."""
|
||||||
|
|
||||||
import io
|
import io
|
||||||
@ -37,6 +39,7 @@ class LineParserWrapper:
|
|||||||
self._test_save_prepared = False
|
self._test_save_prepared = False
|
||||||
|
|
||||||
def _open(self, mode):
|
def _open(self, mode):
|
||||||
|
"""Override _open to use StringIO/BytesIO instead of a real file."""
|
||||||
if mode not in 'rwa':
|
if mode not in 'rwa':
|
||||||
raise ValueError("Unknown mode {!r}!".format(mode))
|
raise ValueError("Unknown mode {!r}!".format(mode))
|
||||||
if self._test_save_prepared:
|
if self._test_save_prepared:
|
||||||
@ -49,7 +52,7 @@ class LineParserWrapper:
|
|||||||
else:
|
else:
|
||||||
prev_val = None
|
prev_val = None
|
||||||
|
|
||||||
if self._binary:
|
if self._binary: # pylint: disable=no-member
|
||||||
fobj = io.BytesIO(prev_val)
|
fobj = io.BytesIO(prev_val)
|
||||||
else:
|
else:
|
||||||
fobj = io.StringIO(prev_val)
|
fobj = io.StringIO(prev_val)
|
||||||
@ -59,22 +62,33 @@ class LineParserWrapper:
|
|||||||
return fobj
|
return fobj
|
||||||
|
|
||||||
def _write(self, fp, data):
|
def _write(self, fp, data):
|
||||||
|
"""Extend _write to get the data after writing it."""
|
||||||
super()._write(fp, data)
|
super()._write(fp, data)
|
||||||
self._data = fp.getvalue()
|
self._data = fp.getvalue()
|
||||||
|
|
||||||
def _prepare_save(self):
|
def _prepare_save(self):
|
||||||
|
"""Keep track if _prepare_save has been called."""
|
||||||
self._test_save_prepared = True
|
self._test_save_prepared = True
|
||||||
|
|
||||||
|
|
||||||
class TestableAppendLineParser(LineParserWrapper, lineparser.AppendLineParser):
|
class TestableAppendLineParser(LineParserWrapper, lineparser.AppendLineParser):
|
||||||
|
|
||||||
|
"""Wrapper over AppendLineParser to make it testable."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestableLineParser(LineParserWrapper, lineparser.LineParser):
|
class TestableLineParser(LineParserWrapper, lineparser.LineParser):
|
||||||
|
|
||||||
|
"""Wrapper over LineParser to make it testable."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestableLimitLineParser(LineParserWrapper, lineparser.LimitLineParser):
|
class TestableLimitLineParser(LineParserWrapper, lineparser.LimitLineParser):
|
||||||
|
|
||||||
|
"""Wrapper over LimitLineParser to make it testable."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -115,6 +129,7 @@ class AppendLineParserTests(unittest.TestCase):
|
|||||||
self._lineparser.save()
|
self._lineparser.save()
|
||||||
|
|
||||||
def _get_expected(self):
|
def _get_expected(self):
|
||||||
|
"""Get the expected data with newlines."""
|
||||||
return '\n'.join(self._expected_data) + '\n'
|
return '\n'.join(self._expected_data) + '\n'
|
||||||
|
|
||||||
def test_save(self):
|
def test_save(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user