From bda7f85346f071e3c0157f02fc451df931b92f55 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Wed, 2 Mar 2016 23:16:58 +0100 Subject: [PATCH] ADD test for image printing and text * image printing does not check output * text test checks output of a very basic string --- setup.cfg | 3 +++ test/50x50.png | Bin 0 -> 653 bytes test/Dies ist ein Test.LF.txt | 1 + test/test_function_image.py | 38 ++++++++++++++++++++++++++++++ test/test_function_text.py | 42 ++++++++++++++++++++++++++++++++++ test/test_load_module.py | 5 ++++ 6 files changed, 89 insertions(+) create mode 100644 setup.cfg create mode 100644 test/50x50.png create mode 100644 test/Dies ist ein Test.LF.txt create mode 100644 test/test_function_image.py create mode 100644 test/test_function_text.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..9b67573 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[nosetests] +verbosity=3 +with-doctest=1 diff --git a/test/50x50.png b/test/50x50.png new file mode 100644 index 0000000000000000000000000000000000000000..67b483b6f7ad452c00af7e85ea4092b2a6a1e5af GIT binary patch literal 653 zcmV;80&@L{P)eSad^g zZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00H?)L_t(o!|j#NYZFlvg}*m8q*_so zixyN+i3@cjB8VbXH-d{IUAeO$QgB=U0zq&mBCZ50>K~wPbRoD3rF5$z2nDwyMAH~T zw5Z#{`B0 zJhEQzm_3n@21i(k-X;lv7H4?FRjNGZB5me-zD`R;$tS5Vs_06hwkY&KlGM>DZCAbL ztiNMmpRABIcK=Y>;2~Q%4?u|p8Z2ja2<*e#BxDyGG~?5C-m#yF=vE!$z5u^W}FV?_`C!(Q^zMB0XgZu&<(9= zv!>(P2cZj@UpX%0IbeknJNZNy)#||BA~${=s8HrGtF)rpTi|$JlXlNN-veebT&BfS z0KRgQGACR&KB?=x;57T_@|>6SWC^|R)+ zMQD$1E3|Yl(*N^U|2LWB$I<}Ma>J5`e6ZxIzz0iSnYd%g!^8(m&cXX($uao+SdtsG z{IKM>@qSnuz$8DG1_-_YEZKw4kEIc`MkfEXiTREY4W)U)q-Z1av+FWLvFOXh48bBL ncvHB=?;BxL@b4IHyraGWRE4iMl&_Lb00000NkvXXu0mjfr~w+` literal 0 HcmV?d00001 diff --git a/test/Dies ist ein Test.LF.txt b/test/Dies ist ein Test.LF.txt new file mode 100644 index 0000000..d7e5cff --- /dev/null +++ b/test/Dies ist ein Test.LF.txt @@ -0,0 +1 @@ +Dies ist ein Test. diff --git a/test/test_function_image.py b/test/test_function_image.py new file mode 100644 index 0000000..135da9e --- /dev/null +++ b/test/test_function_image.py @@ -0,0 +1,38 @@ +#!/usr/bin/python +"""tests for the image printing function + +:author: `Patrick Kanzler `_ +:organization: `python-escpos `_ +:copyright: Copyright (c) 2016 `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") diff --git a/test/test_function_text.py b/test/test_function_text.py new file mode 100644 index 0000000..2ad7bd1 --- /dev/null +++ b/test/test_function_text.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +"""tests for the text printing function + +:author: `Patrick Kanzler `_ +:organization: `python-escpos `_ +:copyright: Copyright (c) 2016 `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)) diff --git a/test/test_load_module.py b/test/test_load_module.py index 9603cf1..0cfcce9 100644 --- a/test/test_load_module.py +++ b/test/test_load_module.py @@ -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