Exemplo n.º 1
0
    def __init__(self, play, proxy=True, strict=True, dump=True, recurse_lock=False, **options):
        super(Replay, self).__init__(play._target, **options)
        self._calls, self._expected, self._actual = ChainMap(self._calls, play._calls), play._calls, self._calls

        self._proxy = proxy
        self._strict = strict
        self._dump = dump
        self._context = play._context
        self._recurse_lock = allocate_lock() if recurse_lock is True else (recurse_lock and recurse_lock())
Exemplo n.º 2
0
    def __init__(self, play, proxy=True, strict=True, dump=True, recurse_lock=False, **options):
        super(Replay, self).__init__(play._target, **options)
        self._calls, self._expected, self._actual = ChainMap(self._calls, play._calls), play._calls, self._calls

        self._proxy = proxy
        self._strict = strict
        self._dump = dump
        self._context = play._context
        self._recurse_lock = allocate_lock() if recurse_lock is True else (recurse_lock and recurse_lock())
Exemplo n.º 3
0
 def __init__(self, contents=None):
     self.precondition_ = []
     self.lazy_init_lock_ = thread.allocate_lock()
     if contents is not None: self.MergeFromString(contents)
Exemplo n.º 4
0
 def test_LockType(self):
     # Make sure _thread.LockType is the same type as _thread.allocate_locke()
     self.failUnless(
         isinstance(_thread.allocate_lock(), _thread.LockType),
         "_thread.LockType is not an instance of what is " "returned by _thread.allocate_lock()",
     )
Exemplo n.º 5
0
 def setUp(self):
     # Create a lock
     self.lock = _thread.allocate_lock()
Exemplo n.º 6
0
 def __init__(self, contents=None):
   self.lazy_init_lock_ = thread.allocate_lock()
   if contents is not None: self.MergeFromString(contents)
Exemplo n.º 7
0
 def __init__(self, contents=None):
   self.field_ = []
   self.facet_ = []
   self.lazy_init_lock_ = thread.allocate_lock()
   if contents is not None: self.MergeFromString(contents)
Exemplo n.º 8
0
 def __init__(self, contents=None):
     self.result_ = QueryResult()
     self.entity_group_key_ = Reference()
     self.lazy_init_lock_ = thread.allocate_lock()
     if contents is not None: self.MergeFromString(contents)
Exemplo n.º 9
0
 def __init__(self, contents=None):
   self.result_ = QueryResult()
   self.entity_group_key_ = Reference()
   self.lazy_init_lock_ = thread.allocate_lock()
   if contents is not None: self.MergeFromString(contents)
 def setUp(self):
     # Create a lock
     self.lock = _thread.allocate_lock()
 def test_LockType(self):
     #Make sure _thread.LockType is the same type as _thread.allocate_locke()
     self.assertIsInstance(
         _thread.allocate_lock(), _thread.LockType,
         "_thread.LockType is not an instance of what "
         "is returned by _thread.allocate_lock()")
Exemplo n.º 12
0
 def test_LockType(self):
     #Make sure _thread.LockType is the same type as _thread.allocate_locke()
     self.failUnless(
         isinstance(_thread.allocate_lock(), _thread.LockType),
         "_thread.LockType is not an instance of what is "
         "returned by _thread.allocate_lock()")
Exemplo n.º 13
0
 def test_LockType(self):
     #Make sure _thread.LockType is the same type as _thread.allocate_locke()
     self.assertIsInstance(_thread.allocate_lock(), _thread.LockType,
                           "_thread.LockType is not an instance of what "
                           "is returned by _thread.allocate_lock()")
Exemplo n.º 14
0
    def __init__(self, PORT, startingMode=SAFE_MODE, sim_mode = False):
        """ the constructor which tries to open the
            connection to the robot at port PORT
        """
        # to do: find the shortest safe serial timeout value...
        # to do: use the timeout to do more error checking than
        #        is currently done...
        #
        # the -1 here is because windows starts counting from 1
        # in the hardware control panel, but not in pyserial, it seems
        
        displayVersion()
        
        # fields for simulator
        self.in_sim_mode = False
        self.sim_sock = None
        self.sim_host = '127.0.0.1'
        self.sim_port = 65000
        self.maxSensorRetries = MIN_SENSOR_RETRIES 
        
        # if PORT is the string 'simulated' (or any string for the moment)
        # we use our SRSerial class
        self.comPort = PORT   #we want to keep track of the port number for reconnect() calls
        print('PORT is', PORT)
        if type(PORT) == type('string'):
            if PORT == 'sim':
                self.init_sim_mode()
                self.ser = None
            else:
                # for Mac/Linux - use whole port name
                # print 'In Mac/Linux mode...'
                self.ser = serial.Serial(PORT, baudrate=57600, timeout=0.5)
        # otherwise, we try to open the numeric serial port...
                if (sim_mode):
                    self.init_sim_mode()
        else:
            # print 'In Windows mode...'
            try:
                self.ser = serial.Serial(PORT-1, baudrate=57600, timeout=0.5)
                if (sim_mode):
                    self.init_sim_mode()
            except serial.SerialException:
                print("unable to access the serial port - please cycle the robot's power")

        # did the serial port actually open?
        if self.in_sim_mode:
            print("In simulator mode")
        elif self.ser.isOpen():
            print('Serial port did open on iRobot Create...')
        else:
            print('Serial port did NOT open, check the')
            print('  - port number')
            print('  - physical connection')
            print('  - baud rate of the roomba (it\'s _possible_, if unlikely,')
            print('              that it might be set to 19200 instead')
            print('              of the default 57600 - removing and')
            print('              reinstalling the battery should reset it.')
        
        # define the class' Open Interface mode
        self.sciMode = OFF_MODE

        if (startingMode == SAFE_MODE):
            print('Putting the robot into safe mode...')
            self.toSafeMode()
            time.sleep(0.3)
        if (startingMode == FULL_MODE):
            print('Putting the robot into full mode...')
            self.toSafeMode()
            time.sleep(0.3)
            self.toFullMode()
            
        self.serialLock = dummy_thread.allocate_lock()
Exemplo n.º 15
0
    def __init__(self, PORT, startingMode=SAFE_MODE, sim_mode=False):
        """ the constructor which tries to open the
            connection to the robot at port PORT
        """
        # to do: find the shortest safe serial timeout value...
        # to do: use the timeout to do more error checking than
        #        is currently done...
        #
        # the -1 here is because windows starts counting from 1
        # in the hardware control panel, but not in pyserial, it seems

        displayVersion()

        # fields for simulator
        self.in_sim_mode = False
        self.sim_sock = None
        self.sim_host = '127.0.0.1'
        self.sim_port = 65000
        self.maxSensorRetries = MIN_SENSOR_RETRIES

        # if PORT is the string 'simulated' (or any string for the moment)
        # we use our SRSerial class
        self.comPort = PORT  #we want to keep track of the port number for reconnect() calls
        print('PORT is', PORT)
        if type(PORT) == type('string'):
            if PORT == 'sim':
                self.init_sim_mode()
                self.ser = None
            else:
                # for Mac/Linux - use whole port name
                # print 'In Mac/Linux mode...'
                self.ser = serial.Serial(PORT, baudrate=57600, timeout=0.5)
                # otherwise, we try to open the numeric serial port...
                if (sim_mode):
                    self.init_sim_mode()
        else:
            # print 'In Windows mode...'
            try:
                self.ser = serial.Serial(PORT - 1, baudrate=57600, timeout=0.5)
                if (sim_mode):
                    self.init_sim_mode()
            except serial.SerialException:
                print(
                    "unable to access the serial port - please cycle the robot's power"
                )

        # did the serial port actually open?
        if self.in_sim_mode:
            print("In simulator mode")
        elif self.ser.isOpen():
            print('Serial port did open on iRobot Create...')
        else:
            print('Serial port did NOT open, check the')
            print('  - port number')
            print('  - physical connection')
            print(
                '  - baud rate of the roomba (it\'s _possible_, if unlikely,')
            print('              that it might be set to 19200 instead')
            print('              of the default 57600 - removing and')
            print('              reinstalling the battery should reset it.')

        # define the class' Open Interface mode
        self.sciMode = OFF_MODE

        if (startingMode == SAFE_MODE):
            print('Putting the robot into safe mode...')
            self.toSafeMode()
            time.sleep(0.3)
        if (startingMode == FULL_MODE):
            print('Putting the robot into full mode...')
            self.toSafeMode()
            time.sleep(0.3)
            self.toFullMode()

        self.serialLock = dummy_thread.allocate_lock()