Esempio n. 1
0
def test_parse_from_socket():
    rs = PseudoRServer()
    rs.start()
    time.sleep(0.5)
    # now connect to it:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("localhost", PseudoRServer.PORT))
    sock.send(binaryRExpressions.binaryRExpressions['"abc"'])
    assert rparser.rparse(sock) == 'abc'
    sock.close()
    rs.close()
Esempio n. 2
0
def test_parse_from_socket():
    rs = PseudoRServer()
    rs.start()
    time.sleep(0.5)
    # now connect to it:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("localhost", PseudoRServer.PORT))
    sock.send(binaryRExpressions.binaryRExpressions['"abc"'])
    assert rparser.rparse(sock) == "abc"
    sock.close()
    rs.close()
Esempio n. 3
0
 def eval(self, aString):
     '@brief Evaluate a string expression through Rserve and return the result transformed into python objects'
     if type(aString) != str:
         raise TypeError('Only string evaluation is allowed')
     self._reval(aString)
     if DEBUG:
         # Read entire data into memory en block, it's easier to debug
         src = self._receive()
         print 'Raw response:', repr(src)
     else:
         src = self.sock.makefile()
     try:
         return rparse(src, atomicArray=self.atomicArray)
     except REvalError:
         # R has reported an evaulation error, so let's obtain a descriptive explanation
         # about why the error has occurred. R allows to retrieve the error message
         # of the last exception via a built-in function called 'geterrmessage()'.
         errorMsg = self.eval('geterrmessage()').strip()
         raise REvalError(errorMsg)
Esempio n. 4
0
 def eval(self, aString):
     '@brief Evaluate a string expression through Rserve and return the result transformed into python objects'
     if type(aString) != str:
         raise TypeError('Only string evaluation is allowed')
     self._reval(aString)
     if DEBUG:
         # Read entire data into memory en block, it's easier to debug
         src = self._receive()
         print 'Raw response:', repr(src)
     else:
         src = self.sock.makefile()
     try:
         return rparse(src, atomicArray=self.atomicArray)
     except REvalError:
         # R has reported an evaulation error, so let's obtain a descriptive explanation
         # about why the error has occurred. R allows to retrieve the error message
         # of the last exception via a built-in function called 'geterrmessage()'.
         errorMsg = self.eval('geterrmessage()').strip()
         raise REvalError(errorMsg)
Esempio n. 5
0
def rExprTester(rExpr, pyExpr, rBinExpr):
    """
    @Brief  Actual test function called via py.test and the generator "test_rExprGenerator() above.
    @Param  rExpr    <string>             The r expression from r2pyExpressions above
    @Param  pyExpr   <python expression>  The python expression from r2pyExpressions above
    @Param  rBinExpr <string>             rExpr translated by r into its binary (network) representation
    """
    qTypeCode = struct.unpack("b", rBinExpr[8])[0]
    #
    v = rparser.rparse(rBinExpr, atomicArray=False)
    if isinstance(v, ndarray):
        compareArrays(v, pyExpr)
    elif v.__class__.__name__ == "TaggedList":
        # do comparison of string representation for now ...
        assert repr(v) == repr(pyExpr)
    else:
        assert v == pyExpr

    # serialize parsed rBinExpr back to binary data stream and check that it is identical to the original value:
    assert rserializer.rSerializeResponse(v) == rBinExpr
Esempio n. 6
0
def rExprTester(rExpr, pyExpr, rBinExpr):
    '''
    @Brief  Actual test function called via py.test and the generator "test_rExprGenerator() above.
    @Param  rExpr    <string>             The r expression from r2pyExpressions above
    @Param  pyExpr   <python expression>  The python expression from r2pyExpressions above
    @Param  rBinExpr <string>             rExpr translated by r into its binary (network) representation
    '''
    qTypeCode = struct.unpack('b', rBinExpr[8])[0]
    #
    v = rparser.rparse(rBinExpr, atomicArray=False)
    if isinstance(v, ndarray):
        compareArrays(v, pyExpr)
    elif v.__class__.__name__ == 'TaggedList':
        # do comparison of string representation for now ...
        assert repr(v) == repr(pyExpr)
    else:
        assert v == pyExpr

    # serialize parsed rBinExpr back to binary data stream and check that it is identical to the original value:
    assert rserializer.rSerializeResponse(v) == rBinExpr
Esempio n. 7
0
 def setRexp(self, name, o):
     '@brief Convert a python object into an RExp and bind it to a variable called "name" in the R namespace'
     rAssign(name, o, self.sock)
     # Rserv sends an emtpy confirmation message, or error message in case of an error.
     # rparse() will raise an Exception in the latter case.
     rparse(self.sock, atomicArray=self.atomicArray)
Esempio n. 8
0
 def setRexp(self, name, o):
     '@brief Convert a python object into an RExp and bind it to a variable called "name" in the R namespace'
     rAssign(name, o, self.sock)
     # Rserv sends an emtpy confirmation message, or error message in case of an error.
     # rparse() will raise an Exception in the latter case.
     rparse(self.sock, atomicArray=self.atomicArray)