fix file-printer-tests by using pytest-mock
This commit is contained in:
parent
a3ca2c2a16
commit
915adf8fd3
2
setup.py
2
setup.py
|
@ -118,7 +118,7 @@ setup(
|
||||||
setup_requires=[
|
setup_requires=[
|
||||||
'setuptools_scm',
|
'setuptools_scm',
|
||||||
],
|
],
|
||||||
tests_require=['tox', 'pytest', 'pytest-cov', 'nose', 'scripttest', 'mock', 'hypothesis'],
|
tests_require=['tox', 'pytest', 'pytest-cov', 'pytest-mock', 'nose', 'scripttest', 'mock', 'hypothesis'],
|
||||||
cmdclass={'test': Tox},
|
cmdclass={'test': Tox},
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
|
|
@ -15,7 +15,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
import mock
|
import pytest
|
||||||
from hypothesis import given
|
from hypothesis import given
|
||||||
from hypothesis.strategies import text
|
from hypothesis.strategies import text
|
||||||
|
|
||||||
|
@ -27,21 +27,22 @@ else:
|
||||||
mock_open_call = '__builtin__.open'
|
mock_open_call = '__builtin__.open'
|
||||||
|
|
||||||
@given(path=text())
|
@given(path=text())
|
||||||
@mock.patch(mock_open_call)
|
def test_load_file_printer(mocker, path):
|
||||||
@mock.patch('escpos.escpos.Escpos.__init__')
|
|
||||||
def test_load_file_printer(mock_escpos, mock_open, path):
|
|
||||||
"""test the loading of the file-printer"""
|
"""test the loading of the file-printer"""
|
||||||
|
mock_escpos = mocker.patch('escpos.escpos.Escpos.__init__')
|
||||||
|
mock_open = mocker.patch(mock_open_call)
|
||||||
printer.File(devfile=path)
|
printer.File(devfile=path)
|
||||||
assert mock_escpos.called
|
assert mock_escpos.called
|
||||||
mock_open.assert_called_with(path, "wb")
|
mock_open.assert_called_with(path, "wb")
|
||||||
|
|
||||||
|
|
||||||
@given(txt=text())
|
@given(txt=text())
|
||||||
@mock.patch.object(printer.File, 'device')
|
def test_auto_flush(mocker, txt):
|
||||||
@mock.patch(mock_open_call)
|
|
||||||
@mock.patch('escpos.escpos.Escpos.__init__')
|
|
||||||
def test_auto_flush(mock_escpos, mock_open, mock_device, txt):
|
|
||||||
"""test auto_flush in file-printer"""
|
"""test auto_flush in file-printer"""
|
||||||
|
mock_escpos = mocker.patch('escpos.escpos.Escpos.__init__')
|
||||||
|
mock_open = mocker.patch(mock_open_call)
|
||||||
|
mock_device = mocker.patch.object(printer.File, 'device')
|
||||||
|
|
||||||
p = printer.File(auto_flush=False)
|
p = printer.File(auto_flush=False)
|
||||||
# inject the mocked device-object
|
# inject the mocked device-object
|
||||||
p.device = mock_device
|
p.device = mock_device
|
||||||
|
@ -56,10 +57,11 @@ def test_auto_flush(mock_escpos, mock_open, mock_device, txt):
|
||||||
|
|
||||||
|
|
||||||
@given(txt=text())
|
@given(txt=text())
|
||||||
@mock.patch.object(printer.File, 'device')
|
def test_flush_on_close(mocker, txt):
|
||||||
@mock.patch(mock_open_call)
|
|
||||||
def test_flush_on_close(mock_open, mock_device, txt):
|
|
||||||
"""test flush on close in file-printer"""
|
"""test flush on close in file-printer"""
|
||||||
|
mock_open = mocker.patch(mock_open_call)
|
||||||
|
mock_device = mocker.patch.object(printer.File, 'device')
|
||||||
|
|
||||||
p = printer.File(auto_flush=False)
|
p = printer.File(auto_flush=False)
|
||||||
# inject the mocked device-object
|
# inject the mocked device-object
|
||||||
p.device = mock_device
|
p.device = mock_device
|
||||||
|
|
Loading…
Reference in New Issue