Example #1
0
def test_parent_context(same_process_evaluator, attribute, expected_name, expected_parent):
    import math
    import decimal
    import datetime

    class C:
        x = 1
        y = int
        z = True
        cos = math.cos
        dec = decimal.Decimal(1)
        dt = datetime.datetime(2000, 1, 1)
        ret_int = _return_int

    o = compiled.CompiledObject(
        same_process_evaluator,
        DirectObjectAccess(same_process_evaluator, C)
    )
    x, = o.py__getattribute__(attribute)
    assert x.py__name__() == expected_name
    module_name = x.parent_context.py__name__()
    if module_name == '__builtin__':
        module_name = 'builtins'  # Python 2
    assert module_name == expected_parent
    assert x.parent_context.parent_context is None
Example #2
0
 def get_or_create_access_handle(self, obj):
     id_ = id(obj)
     try:
         return self.get_access_handle(id_)
     except KeyError:
         access = DirectObjectAccess(self._evaluator_weakref(), obj)
         handle = AccessHandle(self, access, id_)
         self.set_access_handle(handle)
         return handle
Example #3
0
def test_qualified_names(same_process_evaluator, obj, expected_names):
    o = compiled.CompiledObject(
        same_process_evaluator, DirectObjectAccess(same_process_evaluator,
                                                   obj))
    assert o.get_qualified_names() == tuple(expected_names)