def test_parse(self, mocker): c = Command.parse( json.dumps({ '_from': 'A', '_to': 'B', '_command': 'Test', '_data': None })) assert c._from == 'A' assert c._to == 'B' assert c._command == 'Test'
def run(self): while not self.stopped.wait(self.sleep): for each in self.ps.listen(): if each['type'] == 'message': cmd = Command.parse(each['data'].decode('utf-8')) if self.isMine(cmd): Commander.processRes( self, Command.parse(each['data'].decode('utf-8'))) else: self.print(each['data'].decode('utf-8')) elif each['type'] == 'subscribe': self.print( 'Channel %s subscribed, listening count %d.' % (each['channel'].decode('utf-8'), each['data']), logging.DEBUG) elif each['type'] == 'unsubscribe': self.print( 'Channel %s unsubscribed, listening count %d.' % (each['channel'].decode('utf-8'), each['data']), logging.DEBUG) if self.isExit(): self.ps.close()