def test_service_delegate_tile(linked_tile): """Make sure our service delegate tile works correctly.""" hw = linked_tile # pylint:disable=invalid-name; We use hw throughout CoreTools to denote a HardwareManager instance # Normally this is not required but since we are conecting to a # virtual tile that doesn't have a known proxy ('bsctst'), we need # to temporarily register the proxy that we would like to use othweise # we will get a: # HardwareError: HardwareError: Could not find proxy object for tile # Additional Information: # - known_names: ['Simple', 'NO APP'] # - name: 'bsctst' HardwareManager.RegisterDevelopmentProxy(BasicRPCDispatcherProxy) # When we call get(address) the HardwareManager will ask the tile at that address, # in this case the ServiceDelegateTile what it's 6 character name is. It will # return, in this case 'bsctst' because that's what we put in the config.json # file we created in the linked_tile fixture. The HardwareManager will then # look up in its dictionary of known proxies for one whose ModuleName() exactly # matches and return that object. proxy = hw.get(11) result = proxy.add(5, 1) assert result == 5 + 1
def LoadFromFile(cls, script_path): """Import a virtual tile from a file rather than an installed module script_path must point to a python file ending in .py that contains exactly one VirtualTile class definition. That class is loaded and executed as if it were installed. To facilitate development, if there is a proxy object defined in the same file, it is also added to the HardwareManager proxy registry so that it can be found and used with the device. Args: script_path (string): The path to the script to load Returns: VirtualTile: A subclass of VirtualTile that was loaded from script_path """ search_dir, filename = os.path.split(script_path) if search_dir == '': search_dir = './' if filename == '' or not os.path.exists(script_path): raise ArgumentError("Could not find script to load virtual tile", path=script_path) module_name, ext = os.path.splitext(filename) if ext != '.py': raise ArgumentError("Script did not end with .py", filename=filename) try: file_obj = None file_obj, pathname, desc = imp.find_module(module_name, [search_dir]) mod = imp.load_module(module_name, file_obj, pathname, desc) finally: if file_obj is not None: file_obj.close() devs = [ x for x in itervalues(mod.__dict__) if inspect.isclass(x) and issubclass(x, VirtualTile) and x != VirtualTile ] if len(devs) == 0: raise ArgumentError( "No VirtualTiles subclasses were defined in script", path=script_path) elif len(devs) > 1: raise ArgumentError( "More than one VirtualTiles subclass was defined in script", path=script_path, tiles=devs) # Allow automatically injecting associated proxy objects so that we can use this tile with a proxy without # installing it. proxies = [ x for x in itervalues(mod.__dict__) if inspect.isclass(x) and issubclass(x, TileBusProxyObject) and x != TileBusProxyObject ] for proxy in proxies: HardwareManager.RegisterDevelopmentProxy(proxy) return devs[0]