Exemple #1
0
 def test_xlret(self):
     """verify that the xlret return code translation works via the API"""
     with self.assertRaises(InvXlfnError):
         Excel(0xFFFF)
     with self.assertRaises(InvCountError):
         print xlfGetWorkspace()
     with self.assertRaises(FailedError):
         xlCoerce("fish & chips", xltypeNum)
     with self.assertRaises(InvXloperError):
         xlo = XLOPER()
         xlo.xltype = 0xDEAD
         xlCoerce(xlo, xltypeNum)
    def test_excepthook_fail(self):
        """verify that if our excepthook breaks, then we still give an error"""
        def _excepthook(*args):
            raise RuntimeError("sys.excepthook failed")

        with patch("sys.excepthook", new=_excepthook):
            xlo = _eval('_RaiseRuntimeError()')
            self.assertEqual(xlo, XLOPER.from_err(xlerrNum))
Exemple #3
0
def _argtype(type):
    #  if it's a direct conversion, just use the converter in the map
    if type in _argtypes:
        return _argtypes[type]

    # otherwise treat as an XLOPER, and defer to the XLOPER.to function
    code, ctype, conv = _argtypes[XLOPER]
    return (code, ctype, lambda x : XLOPER.from_address(x).value)
Exemple #4
0
def _xlResult(value):        
    """
    convert a return value into an XLOPER, caching in a dict so that it
    is not garbage collected until we get the xlAutoFree callback.
    """
    if value is None: return addressof(_xlNone)
    if value is True: return addressof(_xlTrue)
    if value is False: return addressof(_xlFalse)
    
    if isinstance(value, GeneratorType):
        rows, columns = xlfCaller().size
        gen = value
        value = XLOPER()              
        value._set_Multi(rows, columns, gen)

    if not isinstance(value, XLOPER):
        value = XLOPER(value)              

    if value.xltype & xlbitXLFree:
        _log.warning("returning XL allocated data to excel? %d" % sys.getrefcount(value))
        return addressof(value)

    _pxAutoFree[addressof(value)] = value

    if not value.xltype & xlbitXLFree:
        value.xltype |= xlbitDLLFree

    return addressof(value)
def __XLOPER(x=XLOPER()):
    return repr(x), type(x).__name__
 def test_excepthook(self):
     """verify that excepthook is called"""
     with patch('sys.excepthook'):
         xlo = _eval('_RaiseRuntimeError()')
         self.assertEqual(xlo, XLOPER.from_err(xlerrNum))
         self.assertTrue(sys.excepthook.called)
def _eval(source='', _1=XLOPER()):
    """Evaluate source as python expression and return its XLOPER representation

    Returns xloper representation of the result
    """
    return eval(str(source), locals(), globals())
Exemple #8
0
 def test_Async(self):
     with self.assertRaises(InvAsynchronousContextError):
         xlAsyncReturn(XLOPER(), 123)
Exemple #9
0
xleventCalculationCanceled = 2

from ExcelXLLSDK.gen.xltype import xlbitDLLFree, xlbitXLFree, xltypeInt
from ExcelXLLSDK.XLCALL import xlver

from ExcelXLLSDK._ctypes_win32 import (
    DisableThreadLibraryCalls, 
    DLL_PROCESS_ATTACH
)

#pylint: disable=R0903,C0111,C0103,W0232,C0301

_log = logging.getLogger(__name__)

_pxAutoFree = {}
_xlNone = XLOPER(None)
_xlTrue = XLOPER(True)
_xlFalse = XLOPER(False)


def _xlResult(value):        
    """
    convert a return value into an XLOPER, caching in a dict so that it
    is not garbage collected until we get the xlAutoFree callback.
    """
    if value is None: return addressof(_xlNone)
    if value is True: return addressof(_xlTrue)
    if value is False: return addressof(_xlFalse)
    
    if isinstance(value, GeneratorType):
        rows, columns = xlfCaller().size