From 3c3dab95f5f9131bce1197e60f8dfc8a46c2a957 Mon Sep 17 00:00:00 2001 From: reck Date: Mon, 4 Dec 2017 03:51:29 +0530 Subject: [PATCH] raise exception when TypeError occurs in cashdraw (#268) --- .mailmap | 1 + AUTHORS | 1 + src/escpos/escpos.py | 4 ++-- test/test_function_cashdraw.py | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/test_function_cashdraw.py diff --git a/.mailmap b/.mailmap index 606ae8a..79b93c4 100644 --- a/.mailmap +++ b/.mailmap @@ -10,3 +10,4 @@ Ahmed Tahri TAHRI Ahmed Michael Elsdörfer csoft2k Sergio Pulgarin +reck31 diff --git a/AUTHORS b/AUTHORS index 5095c38..3104b78 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,6 +20,7 @@ mrwunderbar666 Nathan Bookham Patrick Kanzler Qian Linfeng +reck31 Renato Lorenzi Romain Porte Sam Cheng diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index e3b3a53..bac1910 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -697,8 +697,8 @@ class Escpos(object): else: try: self._raw(CD_KICK_DEC_SEQUENCE(*pin)) - except: - raise CashDrawerError() + except TypeError as err: + raise CashDrawerError(err) def linedisplay_select(self, select_display=False): """ Selects the line display or the printer diff --git a/test/test_function_cashdraw.py b/test/test_function_cashdraw.py new file mode 100644 index 0000000..4a8a8e9 --- /dev/null +++ b/test/test_function_cashdraw.py @@ -0,0 +1,19 @@ +#!/usr/bin/python +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import escpos.printer as printer +from escpos.exceptions import CashDrawerError +import pytest + + +def test_raise_CashDrawerError(): + """should raise an error if the sequence is invalid. + """ + instance = printer.Dummy() + with pytest.raises(CashDrawerError): + # call with sequence that is too long + instance.cashdraw([1,1,1,1,1,1]) +