ADD test for image printing and text

* image printing does not check output
* text test checks output of a very basic string
This commit is contained in:
Patrick Kanzler 2016-03-02 23:16:58 +01:00
parent 70307d0f24
commit bda7f85346
6 changed files with 89 additions and 0 deletions

3
setup.cfg Normal file
View File

@ -0,0 +1,3 @@
[nosetests]
verbosity=3
with-doctest=1

BIN
test/50x50.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

View File

@ -0,0 +1 @@
Dies ist ein Test.

View File

@ -0,0 +1,38 @@
#!/usr/bin/python
"""tests for the image printing function
:author: `Patrick Kanzler <patrick.kanzler@fablab.fau.de>`_
:organization: `python-escpos <https://github.com/python-escpos>`_
:copyright: Copyright (c) 2016 `python-escpos <https://github.com/python-escpos>`_
:license: GNU GPL v3
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from nose.tools import with_setup
import escpos.printer as printer
import os
devfile = 'testfile'
def setup_testfile():
"""create a testfile as devfile"""
fhandle = open(devfile, 'a')
try:
os.utime(devfile, None)
finally:
fhandle.close()
def teardown_testfile():
"""destroy testfile again"""
os.remove(devfile)
@with_setup(setup_testfile, teardown_testfile)
def test_function_image_with_50x50_png():
"""test the image function with 50x50.png (grayscale png)"""
instance = printer.File(devfile=devfile)
instance.image("test/50x50.png")

View File

@ -0,0 +1,42 @@
#!/usr/bin/python
"""tests for the text printing function
:author: `Patrick Kanzler <patrick.kanzler@fablab.fau.de>`_
:organization: `python-escpos <https://github.com/python-escpos>`_
:copyright: Copyright (c) 2016 `python-escpos <https://github.com/python-escpos>`_
:license: GNU GPL v3
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from nose.tools import with_setup
import escpos.printer as printer
import os
import filecmp
devfile = 'testfile'
def setup_testfile():
"""create a testfile as devfile"""
fhandle = open(devfile, 'a')
try:
os.utime(devfile, None)
finally:
fhandle.close()
def teardown_testfile():
"""destroy testfile again"""
os.remove(devfile)
@with_setup(setup_testfile, teardown_testfile)
def test_function_text_dies_ist_ein_test_lf():
"""test the text printing function with simple string and compare output"""
instance = printer.File(devfile=devfile)
instance.text('Dies ist ein Test.\n')
instance.flush()
assert(filecmp.cmp('test/Dies ist ein Test.LF.txt', devfile))

View File

@ -7,6 +7,11 @@
:license: GNU GPL v3
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from nose.tools import with_setup
import escpos.printer as printer