def test_plugin_wdir(plugin, monkeypatch, tmpdir): # Test signal/slot connections plugin.main.workingdirectory.set_explorer_cwd.connect.assert_called_with( plugin.update_default_wdir) plugin.main.projects.sig_project_created.connect.assert_called_with( plugin.handle_project_change) plugin.main.projects.sig_project_loaded.connect.assert_called_with( plugin.handle_project_change) plugin.main.projects.sig_project_closed.connect.assert_called_with( plugin.handle_project_change) # Test default_wdir is set to current working dir monkeypatch.setattr('spyder_unittest.unittestplugin.getcwd', lambda: 'fakecwd') plugin.update_default_wdir() assert plugin.unittestwidget.default_wdir == 'fakecwd' # Test after opening project, default_wdir is set to project dir project = Mock() project.CONF = {} project.root_path = str(tmpdir) plugin.main.projects.get_active_project = lambda: project plugin.main.projects.get_active_project_path = lambda: project.root_path plugin.handle_project_change() assert plugin.unittestwidget.default_wdir == str(tmpdir) # Test after closing project, default_wdir is set back to cwd plugin.main.projects.get_active_project = lambda: None plugin.main.projects.get_active_project_path = lambda: None plugin.handle_project_change() assert plugin.unittestwidget.default_wdir == 'fakecwd'
def test_plugin_config(plugin, tmpdir, qtbot): # Test config file does not exist and config is empty config_file_path = tmpdir.join('.spyproject', 'unittest.ini') assert not config_file_path.check() assert plugin.unittestwidget.config is None # Open project project = Mock() project.CONF = {} project.root_path = str(tmpdir) plugin.main.projects.get_active_project = lambda: project plugin.main.projects.get_active_project_path = lambda: project.root_path plugin.handle_project_change() # Test config file does exist but config is empty assert config_file_path.check() assert 'framework = ' in config_file_path.read().splitlines() assert plugin.unittestwidget.config is None # Set config and test that this is recorded in config file config = Config(framework='unittest', wdir=str(tmpdir)) with qtbot.waitSignal(plugin.unittestwidget.sig_newconfig): plugin.unittestwidget.config = config assert 'framework = unittest' in config_file_path.read().splitlines() # Close project and test that config is empty plugin.main.projects.get_active_project = lambda: None plugin.main.projects.get_active_project_path = lambda: None plugin.handle_project_change() assert plugin.unittestwidget.config is None # Re-open project and test that config is correctly read plugin.main.projects.get_active_project = lambda: project plugin.main.projects.get_active_project_path = lambda: project.root_path plugin.handle_project_change() assert plugin.unittestwidget.config == config