Beispiel #1
0
 def test_func(self):
     
     def new_function(x, y):
         return x+y
     
     proxy_obj, proxy_cls = self.conn.make_proxy_for_testing(new_function)
     
     #--------------------
     # Check got proxy
     
     print("Checking proxy_obj is a newref proxy")
     assert netref.is_netref(proxy_obj) == True
     print("Checking new_function is not a newref proxy")
     assert netref.is_netref(new_function) == False
     
     #--------------------
     # Check callable and return value
     expected_retval = 5
     new_func_retval = new_function(2, 3)
     proxy_func_retval = proxy_obj(2, 3)
     print("Checking (expected_retval={expected_retval}) == (new_func_retval={new_func_retval}) == (proxy_func_retval={proxy_func_retval})".format(**locals()))
     assert new_func_retval == proxy_func_retval == expected_retval
     
     #--------------------
     # Check async
     typ, hand = netref.asyncreq(proxy=proxy_obj, handler=4)
     print("Checking async call", ("async_request", 4))
     assert (typ, hand) == ("async_request", 4)
Beispiel #2
0
 def test_dict(self):
     
     local_dict = {"A":1, "B":2}
     
     proxy_obj, proxy_cls = self.conn.make_proxy_for_testing(local_dict)
     print("Checking proxy_obj is a newref proxy")
     assert netref.is_netref(proxy_obj) == True
     print("Checking new_function is not a newref proxy")
     assert netref.is_netref(local_dict) == False
     
     local_dict_retval = local_dict["A"]
     proxy_dict_retval = proxy_obj["A"]
     print("Checking (local_dict_retval={local_dict_retval}) == (proxy_dict_retval={proxy_dict_retval})".format(**locals()))
     assert local_dict_retval == proxy_dict_retval
     
     #------------------ 
     #method docs
     
     local_dict_keys_doc = local_dict.keys.__doc__
     proxy_dict_keys_doc = proxy_obj.keys.__doc__
     print("Checking keys method same (local_dict={local_dict_keys_doc}) == (proxy_obj={proxy_dict_keys_doc})".format(**locals()))
     assert local_dict_keys_doc == proxy_dict_keys_doc
     
     #------------------
     #method keys
     
     keys_proxy_obj, keys_proxy_cls = self.conn.make_proxy_for_testing(local_dict.keys)
     proxy_keys = keys_proxy_obj()
     local_dict_keys = local_dict.keys()
     print("Checking keys same (local_dict={local_dict_keys}) == (proxy_obj={proxy_keys})".format(**locals()))
     assert proxy_keys == local_dict_keys
     
     #-----------------
     #obj still iterable
     
     set_of_keys_from_proxy = set([key for key in proxy_obj])
     set_of_local_keys = set(local_dict_keys)
     print("Checking dict still iterable keys={set_of_keys_from_proxy})".format(**locals()))
     assert set_of_keys_from_proxy == set_of_local_keys
     
     #----------------
     #obj proxy still repr
     
     proxy_repr = repr(proxy_obj)
     local_repr = repr(local_dict)
     print("Checking dict still repr (proxy repr={proxy_repr})==(local repr={local_repr}))".format(**locals()))
     assert proxy_repr == local_repr
Beispiel #3
0
 def _box(self, obj):                  # Might be nice to have *obj
     """label and store a local object in such a way that it can be sent and unboxed
     the remote party either by-value or by-reference
     
     returns package
     package = (label, contents)        :for some labels, contents may be a tuple
     """
     if brine.dumpable(obj):                                    # Immutable obj supported by brine
         label = global_consts.LABEL_IMMUTABLE
         contents = obj
         package = (label, contents)
     
     elif type(obj) is tuple:                                   # Tuple containing mutables
         label = global_consts.LABEL_MUT_TUPLE
         contents = tuple(self._box(item) for item in obj)
         package = (label, contents)
     
     elif netref.is_netref(obj) and obj.____conn__() is self:   # This one detects local proxy objects
         label = global_consts.LABEL_LOCAL_OBJECT_REF
         contents = obj.____oid__
         package = (label, contents)
         
         print("using the third way in _box, detected local proxy object, wow, how did this come to be")
         # Will have to see this one in action
     
     else:                                                      # Pure mutable data
         oid = id(obj)
         cls = getattr(obj, "__class__", type(obj))
         
         #Add object to local object dict, I would have thought this should be a weakkeydict
         self._local_objects[oid] = obj  # the same id could be used later if garbage collected
         
         label = global_consts.LABEL_NETREFABLE
         contents = (oid, cls.__name__, cls.__module__)
         package = (label, contents)
         # cls.inspect.getmodule.__name__        !!!!!!!!!!!!!Maybe better !!!!!!!!!!!!!!!!!!!!!!!
         # If can't get name or module what to do???!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     
     return package