Vauxoo / stoqdrivers

Python fiscal printer (ECF) drivers
GNU Lesser General Public License v2.1
2 stars 3 forks source link

Fails tests with physical fiscal printer #8

Open moylop260 opened 8 years ago

moylop260 commented 8 years ago

I applied next patch to force run test directly in physical fiscal printer to disable all test (except mp4000) and use real port:

./stoqdrivers $: git diff
diff --git a/tests/test_coupon.py b/tests/test_coupon.py
index 59b2140..d960b8a 100644
--- a/tests/test_coupon.py
+++ b/tests/test_coupon.py
@@ -195,11 +195,11 @@ class _BaseTest(unittest.TestCase):
             self._port.save(filename)

     def setUp(self):
-        filename = self._get_recorder_filename()
+        filename = self._get_recorder_filename() and ''
         if not os.path.exists(filename):
             # Change this path to the serial port and set the baudrate used by
             # fiscal printer when recreating the tests.
-            real_port = SerialPort('/tmp/stoq-ecf')
+            real_port = SerialPort('/dev/ttyUSB0')
             real_port.setBaudrate(9600)
             self._port = LogSerialPort(real_port)
         else:
@@ -496,6 +496,7 @@ class _TestCoupon(object):
         self._device.get_sintegra()

+"""
 class DarumaFS345(_TestCoupon, _BaseTest):
     brand = 'daruma'
     model = 'FS345'
@@ -531,6 +532,7 @@ class BematechMP25FI(_TestCoupon, _BaseTest):
 class BematechMP2100(_TestCoupon, _BaseTest):
     brand = 'bematech'
     model = 'MP2100'
+"""

 class BematechMP4000(_TestCoupon, _BaseTest):
@@ -542,6 +544,7 @@ class BematechMP4000(_TestCoupon, _BaseTest):
                                   u'Efectivo')

+"""
 class FiscNet(_TestCoupon, _BaseTest):
     brand = "fiscnet"
     model = "FiscNetECF"
@@ -563,3 +566,4 @@ class EpsonFBIII(_TestCoupon, _BaseTest):
 # class DataregisEP375(_TestCoupon, _BaseTest):
 #     brand = "dataregis"
 #     model = "EP375"
+"""

Now, I executed the test and review the result:

./stoqdrivers $: make coverage
* PyFlakes
* PEP8
nosetests --nocapture --nologcapture --verbose --detailed-errors --with-xcoverage --with-xunit \
                    --cover-package=stoqdrivers --cover-erase stoqdrivers tests
test_add_item (tests.test_coupon.BematechMP4000) ... ok
...

The result of test and traceback is:

Traceback (most recent call last):
  File "./tests/test_coupon.py", line 470, in test_cancel_last_coupon
    self._device.cancel_last_coupon()
  File "./stoqdrivers/printers/fiscal.py", line 211, in cancel_last_coupon
    self._driver.cancel_last_coupon()
  File "./stoqdrivers/printers/bematech/MP25.py", line 553, in cancel_last_coupon
    self._send_command(CMD_CANCEL_LAST)
  File "./stoqdrivers/printers/bematech/MP4000.py", line 267, in _send_command
    self._check_error(retval)
  File "./stoqdrivers/printers/bematech/MP25.py", line 365, in _check_error
    status.check_error()
  File "./stoqdrivers/printers/bematech/MP4000.py", line 592, in check_error
    self._check_error_in_dict(self.st2_codes, self.st2)
  File "./stoqdrivers/printers/bematech/MP4000.py", line 580, in _check_error_in_dict
    raise error_codes[key]
CancelItemError: The item wasn't added in the coupon or can't be cancelled
Traceback (most recent call last):
  File "/mnt/datos/Trabajo/stoqdrivers/tests/test_coupon.py", line 431, in test_payment_receipt
    payment_id = self.get_card_constant()
  File "/mnt/datos/Trabajo/stoqdrivers/stoqdrivers/printers/fiscal.py", line 317, in payment_receipt_open
    return self._driver.payment_receipt_open(identifier, coo, method, value)
  File "/mnt/datos/Trabajo/stoqdrivers/stoqdrivers/printers/bematech/MP25.py", line 667, in payment_receipt_ope
n
    '%-16s%014d%06d' % (method, value, coo))
  File "/mnt/datos/Trabajo/stoqdrivers/stoqdrivers/printers/bematech/MP4000.py", line 267, in _send_command
    self._check_error(retval)
  File "/mnt/datos/Trabajo/stoqdrivers/stoqdrivers/printers/bematech/MP25.py", line 365, in _check_error
    status.check_error()
  File "/mnt/datos/Trabajo/stoqdrivers/stoqdrivers/printers/bematech/MP4000.py", line 592, in check_error
    self._check_error_in_dict(self.st2_codes, self.st2)
  File "/mnt/datos/Trabajo/stoqdrivers/stoqdrivers/printers/bematech/MP4000.py", line 580, in _check_error_in_d
ict
    raise error_codes[key]
CommandError: Invalid CMD parameter
Traceback (most recent call last):
  File "./tests/test_coupon.py", line 496, in test_sintegra
    self._device.get_sintegra()
  File "./stoqdrivers/printers/fiscal.py", line 402, in get_sintegra
    return self._driver.get_sintegra()
  File "./stoqdrivers/printers/bematech/MP25.py", line 778, in get_sintegra
    length, names = self._send_command(CMD_READ_TAXCODES, response='b32s')
  File "./stoqdrivers/printers/bematech/MP4000.py", line 260, in _send_command
    reply = self._read_reply(struct.calcsize(format))
  File "./stoqdrivers/printers/bematech/MP4000.py", line 201, in _read_reply
    raise DriverError(_("Timeout communicating with fiscal "
DriverError: Timeout communicating with fiscal printer
Traceback (most recent call last):
  File "./tests/test_coupon.py", line 351, in test_totalize
    taxcode=TaxType.ICMS)
  File "/Library/Python/2.7/site-packages/kiwi/argcheck.py", line 186, in wrapper
    return func(*args, **kwargs)
  File "./stoqdrivers/printers/fiscal.py", line 181, in totalize
    result = self._driver.coupon_totalize(discount, surcharge, taxcode)
  File "./stoqdrivers/printers/bematech/MP4000.py", line 190, in coupon_totalize
    type, int(value * Decimal('1e2'))))
  File "./stoqdrivers/printers/bematech/MP4000.py", line 267, in _send_command
    self._check_error(retval)
  File "./stoqdrivers/printers/bematech/MP25.py", line 365, in _check_error
    status.check_error()
  File "./stoqdrivers/printers/bematech/MP4000.py", line 592, in check_error
    self._check_error_in_dict(self.st2_codes, self.st2)
  File "./stoqdrivers/printers/bematech/MP4000.py", line 580, in _check_error_in_dict
    raise error_codes[key]
CommandError: Invalid CMD parameter
moylop260 commented 8 years ago

@ruiztulio Can you help us to fix it?

Could you tell me how I can help you to fix it? We have next program in windows to sniffer the wrote commands...

captura de pantalla 2015-11-02 a las 3 06 08 a m
moylop260 commented 8 years ago

FYI this was replied in virtual port saving the real input/output of physical fiscal printer: https://travis-ci.org/Vauxoo/stoqdrivers/builds/88749298#L634-L710

moylop260 commented 8 years ago

@ruiztulio I re-run the tests after next fix: https://github.com/Vauxoo/stoqdrivers/pull/11 The result was: https://travis-ci.org/Vauxoo/stoqdrivers/builds/89493943#L325-L326 tulio

moylop260 commented 8 years ago

@ruiztulio What is the last status? We can add a wrapper in the test to send ok if this printer don't have the command tested.

ruiztulio commented 8 years ago

@moylop260 I cannot find the error, and even tried to add the mp4000 in the same statement than mp20: statement

which don't have the cancel_last_coupon command either

So far all my tries have failed

moylop260 commented 8 years ago

@ruiztulio Ok I got it with test_cancel_last_coupon Thank you.

With test_totalize, test_sintegra and test_payment_receipt... what is the situation?

moylop260 commented 8 years ago

@ruiztulio Could you check my last comment, please?

ruiztulio commented 8 years ago

@moylop260 I haven't dedicated much time on this lately, but some of the generated text files seems to be wrong and shows an error returned by the printer, as you can see here the st2: error

And the rep in the printer error (according to the manual): manual The last line in in the text file is showing that the command was not executed.

So, can you run only the 3 tests with the printer, better one by one and not batched, to check if they run properly in that way?

I think that one of the tests failed and the printer was in an error state, then the others failed too and all this was recorded in the files.