class RIDE(wx.App): def __init__(self, path=None, updatecheck=True): self._initial_path = path self._updatecheck = updatecheck context.APP = self wx.App.__init__(self, redirect=False) def OnInit(self): self.settings = RideSettings() librarydatabase.initialize_database() self.preferences = Preferences(self.settings) self.namespace = Namespace(self.settings) self._controller = ChiefController(self.namespace, self.settings) self.frame = RideFrame(self, self._controller) self._editor_provider = EditorProvider() self._plugin_loader = PluginLoader(self, self._get_plugin_dirs(), context.get_core_plugins()) self._plugin_loader.enable_plugins() self.editor = self._get_editor() self.editor.show() self._load_data() self.frame.tree.populate(self.model) self.frame.tree.set_editor(self.editor) self._publish_system_info() if self._updatecheck: UpdateNotifierController( self.settings).notify_update_if_needed(UpdateDialog) wx.CallLater(200, ReleaseNotes(self).bring_to_front) return True def _publish_system_info(self): RideLogMessage(context.SYSTEM_INFO).publish() @property def model(self): return self._controller def _get_plugin_dirs(self): return [ self.settings.get_path('plugins'), os.path.join(self.settings['install root'], 'site-plugins'), contrib.CONTRIB_PATH ] def _get_editor(self): from robotide.editor import EditorPlugin for pl in self._plugin_loader.plugins: if isinstance(pl._plugin, EditorPlugin): return pl._plugin def _load_data(self): path = self._initial_path or self._get_latest_path() if path: with self.active_event_loop(): observer = LoadProgressObserver(self.frame) self._controller.load_data(path, observer) def _get_latest_path(self): recent = self._get_recentfiles_plugin() if not recent or not recent.recent_files: return None return recent.recent_files[0] def _get_recentfiles_plugin(self): from robotide.recentfiles import RecentFilesPlugin for pl in self.get_plugins(): if isinstance(pl._plugin, RecentFilesPlugin): return pl._plugin def get_plugins(self): return self._plugin_loader.plugins def register_preference_panel(self, panel_class): '''Add the given panel class to the list of known preference panels''' self.preferences.add(panel_class) def unregister_preference_panel(self, panel_class): '''Remove the given panel class from the list of known preference panels''' self.preferences.remove(panel_class) def register_editor(self, object_class, editor_class, activate): self._editor_provider.register_editor(object_class, editor_class, activate) def unregister_editor(self, object_class, editor_class): self._editor_provider.unregister_editor(object_class, editor_class) def activate_editor(self, object_class, editor_class): self._editor_provider.set_active_editor(object_class, editor_class) def get_editors(self, object_class): return self._editor_provider.get_editors(object_class) def get_editor(self, object_class): return self._editor_provider.get_editor(object_class) @contextmanager def active_event_loop(self): # With wxPython 2.9.1, ProgressBar.Pulse breaks if there's no active # event loop. # See http://code.google.com/p/robotframework-ride/issues/detail?id=798 loop = wx.EventLoop() wx.EventLoop.SetActive(loop) yield del loop
class RIDE(wx.App): def __init__(self, path=None, updatecheck=True): self._initial_path = path self._updatecheck = updatecheck context.APP = self wx.App.__init__(self, redirect=False) def OnInit(self): self.settings = RideSettings() self.preferences = Preferences(self.settings) self.namespace = Namespace(self.settings) self._controller = ChiefController(self.namespace, self.settings) self.frame = RideFrame(self, self._controller) self._editor_provider = EditorProvider() self._plugin_loader = PluginLoader(self, self._get_plugin_dirs(), context.get_core_plugins()) self._plugin_loader.enable_plugins() self.editor = self._get_editor() self.editor.show() self._load_data() self.frame.tree.populate(self.model) self.frame.tree.set_editor(self.editor) self._publish_system_info() if self._updatecheck: UpdateNotifierController(self.settings).notify_update_if_needed(UpdateDialog) wx.CallLater(200, ReleaseNotes(self).bring_to_front) return True def _publish_system_info(self): RideLogMessage(context.SYSTEM_INFO).publish() @property def model(self): return self._controller def _get_plugin_dirs(self): return [self.settings.get_path('plugins'), os.path.join(self.settings['install root'], 'site-plugins'), contrib.CONTRIB_PATH] def _get_editor(self): from robotide.editor import EditorPlugin for pl in self._plugin_loader.plugins: if isinstance(pl._plugin, EditorPlugin): return pl._plugin def _load_data(self): path = self._initial_path or self._get_latest_path() if path: with self.active_event_loop(): observer = LoadProgressObserver(self.frame) self._controller.load_data(path, observer) def _get_latest_path(self): recent = self._get_recentfiles_plugin() if not recent or not recent.recent_files: return None return recent.recent_files[0] def _get_recentfiles_plugin(self): from robotide.recentfiles import RecentFilesPlugin for pl in self.get_plugins(): if isinstance(pl._plugin, RecentFilesPlugin): return pl._plugin def get_plugins(self): return self._plugin_loader.plugins def register_preference_panel(self, panel_class): '''Add the given panel class to the list of known preference panels''' self.preferences.add(panel_class) def unregister_preference_panel(self, panel_class): '''Remove the given panel class from the list of known preference panels''' self.preferences.remove(panel_class) def register_editor(self, object_class, editor_class, activate): self._editor_provider.register_editor(object_class, editor_class, activate) def unregister_editor(self, object_class, editor_class): self._editor_provider.unregister_editor(object_class, editor_class) def activate_editor(self, object_class, editor_class): self._editor_provider.set_active_editor(object_class, editor_class) def get_editors(self, object_class): return self._editor_provider.get_editors(object_class) def get_editor(self, object_class): return self._editor_provider.get_editor(object_class) @contextmanager def active_event_loop(self): # With wxPython 2.9.1, ProgressBar.Pulse breaks if there's no active # event loop. # See http://code.google.com/p/robotframework-ride/issues/detail?id=798 loop = wx.EventLoop() wx.EventLoop.SetActive(loop) yield del loop
class RIDE(wx.App): def __init__(self, path=None): self._initial_path = path context.APP = self wx.App.__init__(self, redirect=False) def OnInit(self): self.namespace = Namespace() self._controller = ChiefController(self.namespace) self.frame = RideFrame(self, self._controller) self._editor_provider = EditorProvider() self._plugin_loader = PluginLoader(self, self._get_plugin_dirs(), context.get_core_plugins()) self._plugin_loader.enable_plugins() self.editor = self._get_editor() self.editor.show() self._load_data() self.frame.tree.populate(self.model) self.frame.tree.set_editor(self.editor) self._publish_system_info() wx.CallLater(200, self._get_release_notes().bring_to_front) return True def _publish_system_info(self): RideLogMessage(context.SYSTEM_INFO).publish() @property def model(self): return self._controller def _get_plugin_dirs(self): return [context.SETTINGS.get_path('plugins'), os.path.join(context.SETTINGS['install root'], 'site-plugins'), contrib.CONTRIB_PATH] def _get_editor(self): from robotide.editor import EditorPlugin for pl in self._plugin_loader.plugins: if isinstance(pl._plugin, EditorPlugin): return pl._plugin def _get_release_notes(self): from .releasenotes import ReleaseNotesPlugin for pl in self._plugin_loader.plugins: if isinstance(pl._plugin, ReleaseNotesPlugin): return pl._plugin def _load_data(self): if self._initial_path: with self.active_event_loop(): observer = LoadProgressObserver(self.frame) self._controller.load_data(self._initial_path, observer) def get_plugins(self): return self._plugin_loader.plugins def register_editor(self, object_class, editor_class, activate): self._editor_provider.register_editor(object_class, editor_class, activate) def unregister_editor(self, object_class, editor_class): self._editor_provider.unregister_editor(object_class, editor_class) def activate_editor(self, object_class, editor_class): self._editor_provider.set_active_editor(object_class, editor_class) def get_editors(self, object_class): return self._editor_provider.get_editors(object_class) def get_editor(self, object_class): return self._editor_provider.get_editor(object_class) @contextmanager def active_event_loop(self): # With wxPython 2.9.1, ProgressBar.Pulse breaks if there's no active # event loop. # See http://code.google.com/p/robotframework-ride/issues/detail?id=798 loop = wx.EventLoop() wx.EventLoop.SetActive(loop) yield del loop
class ChiefControllerTest(unittest.TestCase): def setUp(self): self.ctrl = ChiefController(Namespace()) self.load_observer = MessageRecordingLoadObserver() self.suite_listener = PublisherListener(RideOpenSuite) self.resource_listener = PublisherListener(RideOpenResource) def tearDown(self): self.suite_listener.unsubscribe() self.resource_listener.unsubscribe() def test_loading_suite_at_startup(self): self._load(MINIMAL_SUITE_PATH) assert_true(self.ctrl._controller is not None) self._test_listeners([MINIMAL_SUITE_PATH], []) def _test_listeners(self, suite_paths, resource_paths): assert_equals(self._get_paths(self.suite_listener.data), suite_paths) assert_equals(self._get_paths(self.resource_listener.data), resource_paths) def _get_paths(self, data): return [item.path for item in data] def test_loading_resource_at_startup(self): self._load(RESOURCE_PATH) assert_true(self.ctrl.resources != []) self._test_listeners([], ALL_RESOURCE_PATH_RELATED_RESOURCE_IMPORTS) def test_loading_invalid_data_at_startup(self): msg = "Given file 'invalid' is not a valid Robot Framework test case or resource file." self.ctrl.load_data('invalid', self.load_observer) assert_true(self.load_observer.finished) assert_equals(self.load_observer.message, msg) self._test_listeners([], []) def _load(self, path): self.ctrl.load_data(path, self.load_observer) assert_true(self.load_observer.notified) assert_true(self.load_observer.finished) def test_loading_datafile(self): data = self.ctrl.load_datafile(MINIMAL_SUITE_PATH, self.load_observer) assert_true(self.load_observer.finished) assert_true(data is not None) self._test_listeners([MINIMAL_SUITE_PATH], []) def test_reloading(self): self.ctrl.new_file_project(MINIMAL_SUITE_PATH) files1 = self.ctrl.datafiles self.ctrl.new_file_project(MINIMAL_SUITE_PATH) files2 = self.ctrl.datafiles assert_true(files1 != files2) def test_loading_resource_file(self): resource = self.ctrl.load_resource(RESOURCE_PATH, self.load_observer) assert_true(self.load_observer.finished) assert_true(resource is not None) self._test_listeners([], ALL_RESOURCE_PATH_RELATED_RESOURCE_IMPORTS) def test_loading_invalid_datafile(self): self.ctrl.load_datafile('invalid', self.load_observer) assert_equals(self.load_observer.message, "Invalid data file 'invalid'.") self._test_listeners([], []) def test_loading_invalid_resource(self): assert_none(self.ctrl.load_resource('invalid', self.load_observer)) assert_equals(self.load_observer.message, "Invalid resource file 'invalid'.") self._test_listeners([], []) def test_dirtyness(self): self.ctrl.load_data(COMPLEX_SUITE_PATH, MessageRecordingLoadObserver()) assert_true(not self.ctrl.is_dirty()) self.ctrl.data.create_test('newnessness') assert_true(self.ctrl.is_dirty()) def test_load_dirty_controllers(self): self.ctrl.load_data(SUITEPATH, MessageRecordingLoadObserver()) assert_equals(len(self.ctrl._get_all_dirty_controllers()), 0) tcf = self._find_suite_by_type(self.ctrl.data.children, TestCaseFileController) tcf.create_test('newnessness') assert_equals(len(self.ctrl._get_all_dirty_controllers()), 1) self.ctrl.data.mark_dirty() assert_equals(len(self.ctrl._get_all_dirty_controllers()), 2) sub_dir = self._find_suite_by_type(self.ctrl.data.children, TestDataDirectoryController) sub_dir_tcf = self._find_suite_by_type(sub_dir.children, TestCaseFileController) sub_dir_tcf.create_test('newnessness') assert_equals(len(self.ctrl._get_all_dirty_controllers()), 3) def _find_suite_by_type(self, suites, type): for child in suites: if isinstance(child, type): return child return None def test_creating_new_resource(self): controller = self.ctrl.new_resource('somepath') assert_equals(controller.name, 'Somepath') def test_resource_with_same_path_is_not_added_twice(self): self.ctrl.new_resource('somepath') self.ctrl.new_resource('somepath') assert_equals(len(self.ctrl.resources), 1) def test_sort_external_resources(self): self.ctrl.load_data(EXTERNAL_RES_UNSORTED_PATH, MessageRecordingLoadObserver()) assert_equals([res.name for res in self.ctrl.external_resources], ["Abc", "Bar", "Foo", "Hello", "Resource"]) def test_datafiles_property_with_resource_file_only(self): resource = self.ctrl.load_resource(RESOURCE_PATH, self.load_observer) assert_equals(self.ctrl.datafiles[0], resource) def test_get_all_keywords_with_resource_file_only(self): chief = datafilereader.construct_chief_controller(RESOURCE_PATH) all_kws = chief.get_all_keywords() res_kws = [kw for kw in all_kws if kw.name == 'Resource UK'] assert_equals(len(res_kws), 1) def test_resource_import_modified(self): self.ctrl.resource_import_modified(RELATIVE_PATH_TO_RESOURCE_FILE, DATAPATH) self._test_listeners([], ALL_RESOURCE_PATH_RELATED_RESOURCE_IMPORTS)
class ChiefControllerTest(unittest.TestCase): def setUp(self): self._library_manager = _library_manager() self.ctrl = ChiefController(Namespace(FakeSettings()), FakeSettings(), self._library_manager) self.load_observer = MessageRecordingLoadObserver() self.suite_listener = PublisherListener(RideOpenSuite) self.resource_listener = PublisherListener(RideOpenResource) def tearDown(self): self.suite_listener.unsubscribe() self.resource_listener.unsubscribe() self.ctrl.close() self._library_manager.stop() def test_loading_suite_at_startup(self): self._load(MINIMAL_SUITE_PATH) assert_true(self.ctrl._controller is not None) self._test_listeners([MINIMAL_SUITE_PATH], []) def _test_listeners(self, suite_paths, resource_paths): self.assertEqual(self._get_paths(self.suite_listener.data), suite_paths) self.assertEqual(self._get_paths(self.resource_listener.data), resource_paths) def _get_paths(self, data): return [item.path for item in data] def test_loading_resource_at_startup(self): self._load(RESOURCE_PATH) assert_true(self.ctrl.resources != []) self._test_listeners([], ALL_RESOURCE_PATH_RELATED_RESOURCE_IMPORTS) def test_loading_invalid_data_at_startup(self): msg = "Given file 'invalid' is not a valid Robot Framework test case or resource file." self.ctrl.load_data('invalid', self.load_observer) assert_true(self.load_observer.finished) assert_equals(self.load_observer.message, msg) self._test_listeners([], []) def _load(self, path): self.ctrl.load_data(path, self.load_observer) assert_true(self.load_observer.notified) assert_true(self.load_observer.finished) def test_loading_datafile(self): data = self.ctrl.load_datafile(MINIMAL_SUITE_PATH, self.load_observer) assert_true(self.load_observer.finished) assert_true(data is not None) self._test_listeners([MINIMAL_SUITE_PATH], []) def test_reloading(self): self.ctrl.new_file_project(MINIMAL_SUITE_PATH) files1 = self.ctrl.datafiles self.ctrl.new_file_project(MINIMAL_SUITE_PATH) files2 = self.ctrl.datafiles assert_true(files1 != files2) def test_loading_resource_file(self): resource = self.ctrl.load_resource(RESOURCE_PATH, self.load_observer) assert_true(self.load_observer.finished) assert_true(resource is not None) self._test_listeners([], ALL_RESOURCE_PATH_RELATED_RESOURCE_IMPORTS) def test_loading_invalid_datafile(self): self.ctrl.load_datafile('invalid', self.load_observer) assert_equals(self.load_observer.message, "Invalid data file 'invalid'.") self._test_listeners([], []) def test_loading_invalid_resource(self): assert_none(self.ctrl.load_resource('invalid', self.load_observer)) assert_equals(self.load_observer.message, "Invalid resource file 'invalid'.") self._test_listeners([], []) def test_dirtyness(self): self.ctrl.load_data(COMPLEX_SUITE_PATH, MessageRecordingLoadObserver()) assert_true(not self.ctrl.is_dirty()) self.ctrl.data.create_test('newnessness') assert_true(self.ctrl.is_dirty()) def test_load_dirty_controllers(self): self.ctrl.load_data(SUITEPATH, MessageRecordingLoadObserver()) assert_equals(len(self.ctrl._get_all_dirty_controllers()), 0) tcf = self._find_suite_by_type(self.ctrl.data.children, TestCaseFileController) tcf.create_test('newnessness') assert_equals(len(self.ctrl._get_all_dirty_controllers()), 1) self.ctrl.data.mark_dirty() assert_equals(len(self.ctrl._get_all_dirty_controllers()), 2) sub_dir = self._find_suite_by_type(self.ctrl.data.children, TestDataDirectoryController) sub_dir_tcf = self._find_suite_by_type(sub_dir.children, TestCaseFileController) sub_dir_tcf.create_test('newnessness') assert_equals(len(self.ctrl._get_all_dirty_controllers()), 3) def _find_suite_by_type(self, suites, type): for child in suites: if isinstance(child, type): return child return None def test_creating_new_resource(self): controller = self.ctrl.new_resource('somepath') assert_equals(controller.name, 'Somepath') def test_resource_with_same_path_is_not_added_twice(self): self.ctrl.new_resource('somepath') self.ctrl.new_resource('somepath') assert_equals(len(self.ctrl.resources), 1) def test_load_data_with_external_resources_all_externals_are_used(self): are_used = [] def handle(message): are_used.append(message.datafile.is_used()) self.resource_listener.outer_listener = handle self._load(EXTERNAL_RES_UNSORTED_PATH) assert_true(self.ctrl.resources != []) res_path = os.path.join(os.path.split(EXTERNAL_RES_UNSORTED_PATH)[0], 'external_resources') abc_path = os.path.join(res_path, 'subdirectory2', 'subsubdirectory', 'Abc.txt') bar_path = os.path.join(res_path, 'subdirectory2', 'bar.txt') foo_path = os.path.join(res_path, 'subdirectory', 'Foo.txt') hello_path = os.path.join(res_path, 'subdirectory2', 'subsubdirectory', 'hello.txt') resource_path = os.path.join(res_path, 'subdirectory2', 'Resource.txt') self.assertEqual(are_used, [True for _ in range(5)]) self._test_listeners([EXTERNAL_RES_UNSORTED_PATH], [abc_path, bar_path, foo_path, hello_path, resource_path]) def test_sort_external_resources(self): self.ctrl.load_data(EXTERNAL_RES_UNSORTED_PATH, MessageRecordingLoadObserver()) assert_equals([res.name for res in self.ctrl.external_resources], ["Abc", "Bar", "Foo", "Hello", "Resource"]) def test_datafiles_property_with_resource_file_only(self): resource = self.ctrl.load_resource(RESOURCE_PATH, self.load_observer) assert_equals(self.ctrl.datafiles[0], resource) def test_get_all_keywords_with_resource_file_only(self): chief = datafilereader.construct_chief_controller(RESOURCE_PATH) all_kws = chief.get_all_keywords() chief.close() res_kws = [kw for kw in all_kws if kw.name == 'Resource UK'] assert_equals(len(res_kws), 1) def test_resource_import_modified(self): self.ctrl.resource_import_modified(RELATIVE_PATH_TO_RESOURCE_FILE, DATAPATH) self._test_listeners([], ALL_RESOURCE_PATH_RELATED_RESOURCE_IMPORTS)