def test_changing_library_initializes_function_searh(): library = FunctionLibrary(modules=['os']) b = Application() b.function_library = library assert_equal(b.function_search.all_functions, library.functions)
def test_changing_library_functions_initializes_function_searh(): library = FunctionLibrary(modules=['os']) b = Application() b.function_library = library assert_equal(b.function_search.all_functions, library.functions) # This forces the library to recalculate its functions. library.modules = ['os', 'telnetlib'] assert_equal(b.function_search.all_functions, library.functions)
def test_appending_library_functions_initializes_function_searh(): library = FunctionLibrary(modules=['os']) b = Application() b.function_library = library assert_equal(b.function_search.all_functions, library.functions) # This is sorta cheating, but add an item to the function list # and ensure that we are updating. library.functions.append(MinimalFunctionInfo()) assert_equal(b.function_search.all_functions, library.functions)
def test_initializing_with_library_initializes_function_searh(): library = FunctionLibrary(modules=['os']) b = Application(function_library=library) raise nose.SkipTest # FIXME: # The assertion below is failing because in # enthought/block_canvas/app/app.py line 541 # post_init is set to True, which means that function_library # is not updated upon initialization. The post_init change # was made in a number of locations in this file at changeset 19002. assert_equal(b.function_search.all_functions, library.functions)
def trait_view(self, view): """ This implementation should go away immediately when groups are managed "graphically". A possible way to create a new "world" where the execution is still serial is to create a new instance of LoopApp that shares with the "main" one all the basic data (contexts, class_library, func_library, func_search) but not the same experiment. """ # To avoid circular imports from blockcanvas.app.app import Application code = None app_exist = False if hasattr(scripting, 'app'): app_exist = True # If the methods is called by another app that wants to add a group, # retrieve it from the scripting module recursively. app = scripting.app # Save the current reference in the scripting module if not hasattr(scripting, 'app_tree'): scripting.app_tree = [] scripting.app_tree.append(app) class_library = app.class_library func_library = app.function_library func_search = app.function_search else: # It is more or less a test if the method works well so the module # is chosen by hand. # It should never happen that this method is called outside an # instance of the BlockCanvas app. modules = ['os'] class_library = ClassLibrary(modules=modules) func_library = FunctionLibrary(modules=modules) func_search = FunctionSearch(all_functions=func_library.functions) # TODO: This new object overwrite the scripting.app reference so there # should be a way to call a "fix_scripting_app" method when this view # is closed. FIXED: Now this step is done by update_from_UI self.function_view_instance = Application( code=code, class_library=class_library, function_library=func_library, function_search=func_search) if app_exist: # Share the context with the Parent app if it exist self.function_view_instance.project.active_experiment.context.subcontext = \ app.project.active_experiment.context.subcontext # During the editing of the group fired events due to change in the context # are deferred now and completely cleaned after the group creation to # avoid useless execution. # Those parameters must be fixed after the group is Created/Updated. # This step is done by "update_from_UI" method self._prev_defer_execution = app.project.active_experiment.context.defer_execution app.project.active_experiment.context.defer_execution = True # To save some time is also nice to stop the execution in the calling app due to # events fired every time a statement is added to the execution model. # It must be noticed that allow_execute must be saved instead of just put it to # False, to properly manage nested groups/loops. self._prev_allow_execute = app.project.active_experiment.exec_model.allow_execute app.project.active_experiment.exec_model.allow_execute = False # No execution in the sub_app during the editing of the group self.function_view_instance.project.active_experiment.exec_model.allow_execute = False # Add current element/s to the view if self.gfunc is not None: for curr_elem in self.gfunc.curr_elemts: self.function_view_instance.add_function_to_execution_model( curr_elem, x=None, y=None) # When reopening an existing group add its statements for stmt in self.group_statements: self.function_view_instance.add_function_to_execution_model(stmt, x=None, y=None) return create_view(model=self.function_view_instance)