# Path: stoqdrivers/interfaces.py
# class ISerialPort(Interface):
#     """ Interface used by drivers to write commands and get reply from devices
#     """
# 
#     def getDSR():
#         """ Returns True if the device is done to send data. Some drivers
#         block in a loop waiting for this function returns True before call
#         read.
#         """
# 
#     def setDTR(value):
#         """ Set to True when the driver is going to send data to the device
#         """
# 
#     def read(n_bytes=1):
#         """ Read data """
# 
#     def write(data):
#         """ Write data """
# 
# Path: stoqdrivers/serialbase.py
# class SerialPort(Serial):
# 
#     def __init__(self, device, baudrate=9600):
#         # WARNING: Never change these default options, some drivers are based
#         # on this to work. Maybe we should change this and make all the driver
#         # specify its options, but right now I think that's ok, since these
#         # options are common to most of the drivers.
#         Serial.__init__(self, device, baudrate=baudrate, bytesize=EIGHTBITS,
#                         parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=3,
#                         write_timeout=3)
#         self.setDTR(True)
#         self.flushInput()
#         self.flushOutput()


import os
import unittest
import stoqdrivers
from zope.interface import implementer
from stoqdrivers.interfaces import ISerialPort
from stoqdrivers.serialbase import SerialPort
    def _load_data(self, datafile):
        fd = open(datafile, "rb")
        for n, line in enumerate(fd.readlines()):
            data = self._convert_data(line[2:-1])

            if line.startswith(b"W"):
                self._input.extend(data)
            elif line.startswith(b"R"):
                self._output += data
            else:
                raise TypeError("Unrecognized entry type at %s:%d: %r"
                                % (datafile, n + 1, line[0]))
        fd.close()


class _BaseTest(unittest.TestCase):
    def __init__(self, test_name):
        self._test_name = test_name
        unittest.TestCase.__init__(self, test_name)

    def tearDown(self):
        filename = self._get_recorder_filename()
        if not os.path.exists(filename):
            self._port.save(filename)

    def setUp(self):
        filename = self._get_recorder_filename()
        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.

# Path: stoqdrivers/interfaces.py
# class ISerialPort(Interface):
#     """ Interface used by drivers to write commands and get reply from devices
#     """
# 
#     def getDSR():
#         """ Returns True if the device is done to send data. Some drivers
#         block in a loop waiting for this function returns True before call
#         read.
#         """
# 
#     def setDTR(value):
#         """ Set to True when the driver is going to send data to the device
#         """
# 
#     def read(n_bytes=1):
#         """ Read data """
# 
#     def write(data):
#         """ Write data """
# 
# Path: stoqdrivers/serialbase.py
# class SerialPort(Serial):
# 
#     def __init__(self, device, baudrate=9600):
#         # WARNING: Never change these default options, some drivers are based
#         # on this to work. Maybe we should change this and make all the driver
#         # specify its options, but right now I think that's ok, since these
#         # options are common to most of the drivers.
#         Serial.__init__(self, device, baudrate=baudrate, bytesize=EIGHTBITS,
#                         parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=3,
#                         write_timeout=3)
#         self.setDTR(True)
#         self.flushInput()
#         self.flushOutput()


# Path: tests/base.py
import os
import unittest
import stoqdrivers
from zope.interface import implementer
from stoqdrivers.interfaces import ISerialPort
from stoqdrivers.serialbase import SerialPort

    def _load_data(self, datafile):
        fd = open(datafile, "rb")
        for n, line in enumerate(fd.readlines()):
            data = self._convert_data(line[2:-1])

            if line.startswith(b"W"):
                self._input.extend(data)
            elif line.startswith(b"R"):
                self._output += data
            else:
                raise TypeError("Unrecognized entry type at %s:%d: %r"
                                % (datafile, n + 1, line[0]))
        fd.close()


class _BaseTest(unittest.TestCase):
    def __init__(self, test_name):
        self._test_name = test_name
        unittest.TestCase.__init__(self, test_name)

    def tearDown(self):
        filename = self._get_recorder_filename()
        if not os.path.exists(filename):
            self._port.save(filename)

    def setUp(self):
        filename = self._get_recorder_filename()
        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', baudrate=115200)