def pytest_funcarg__boss(request): boss = Mock(Boss) boss.window = Mock(PidaWindow) boss.window.get_size.return_value = (640, 480) boss.window.get_position.return_value = (0, 0) boss.window.paned = Mock() boss.get_services.return_value = [] #XXX: mock up something for later return boss
def test_startup_with_missing_project(tmpdir, monkeypatch): #XXX: log entries boss = Mock() boss.return_value = [str(tmpdir.join('missing-dir'))] svc = ProjectService(boss) monkeypatch.setattr(svc, 'opt', boss) monkeypatch.setattr(svc, '_load_project', boss.load) svc._read_options() assert not boss.load.called
def test_recover_loading_error(): boss = Mock() svc = Buffer(boss) svc._documents = {} error = Mock() error.document = None error.message = 'test' #XXX: log messsages? svc.recover_loading_error(error)
def test_startup_with_missing_project(tmpdir, monkeypatch): #XXX: log entries boss = Mock() boss.return_value = [str(tmpdir.join('missing-dir'))] svc = ProjectService(boss) monkeypatch.setattr(svc, 'opt', boss) monkeypatch.setattr(svc , '_load_project', boss.load) svc._read_options() assert not boss.load.called
def test_startup_with_empty_project_dir(tmpdir, monkeypatch): boss = Mock() boss.return_value = [str(tmpdir)] svc = ProjectService(boss) monkeypatch.setattr(svc, 'opt', boss) def mock_load_project(dirname): assert dirname == tmpdir monkeypatch.setattr(svc, '_load_project', mock_load_project) svc._read_options()
def test_load_missing_project(tmpdir, monkeypatch): boss = Mock() svc = ProjectService(boss) svc.log = boss.log #XXX: loc recording, message matching svc._load_project(str(tmpdir.join('missing'))) assert boss.log.warn.called
def test_instanciate_options_view(): svc = Mock() svc.get_label.return_value = 'test' svc.boss.get_services.return_value = [svc] view = PidaOptionsView(svc) assert not view.options_book.props.show_tabs
def test_open_files_storage(): svc = Mock() svc.get_name.return_value = 'test' options = BufferOptionsConfig(svc) options.create_options() #XXX too stupid assert options.get_option('open_files').workspace
def test_load_project(tmpdir, monkeypatch): Project.create_blank_project_file('test', str(tmpdir)) boss = Mock() svc = ProjectService(boss) svc._projects = [] svc.log = boss.log svc.project_list = boss.project_list svc.events = boss.events svc._load_project(str(tmpdir)) print svc.log.warn.call_args assert svc._projects assert svc.events.emit.called
def test_loaded_event(): boss = Mock() project_service = ProjectService(boss) project_service.started = False project_service.create_all() project_service.start() #XXX: mock mimicing the result of project_service.pre_start project_service._projects = [] project_service.project_list = Mock() project_service.project_list.project_ol = Mock() caught = [] project_service.events.subscribe('loaded', lambda project: caught.append(project)) # # HACK: we assum the pida dev path, so we have a project to load :) DEVPATH = os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, os.path.pardir)) got = project_service._load_project(DEVPATH) #XXX: hack assert got is caught[0]
def test_plugins_view_enable_and_disable(): svc = Mock() view = plugins.PluginsView(svc) foo = PP('foo', True) bar = PP('bar', False) view.installed_list.extend([foo, bar]) svc.start_plugin.return_value = True view.on_installed_list__item_changed(None, foo, 'enabled', True) assert svc.start_plugin.called assert foo.enabled view.on_installed_list__item_changed(None, bar, 'enabled', False) assert svc.stop_plugin.called
def pytest_funcarg__view(request): #XXXX: factor services/mock services into a general conftest tmpdir = request.getfuncargvalue('tmpdir') browse = tmpdir.ensure('browse', dir=1) browse.ensure('test.py') boss = Mock(Boss) boss.cmd.return_value = [] svc = Filemanager(boss) #XXX: evil svc.create_all() svc.subscribe_all() svc.pre_start() svc.start() svc.started = 1 svc.browse(str(browse)) request.addfinalizer(svc.stop_components) return svc.file_view
def pytest_funcarg__svc(request): return Mock(WindowSvc)
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #SOFTWARE. from pida.utils.testing.mock import Mock from pida.core.document import Document from .waypoint import WayPoint, WayStack BOSS = Mock() class WaypointTest(object): def should(self, wp, should): for i, (doc, pos) in enumerate(should): self.assertEqual(wp[i].document, doc) self.assertEqual(wp[i].line, pos) def test_has(self): doc1 = Document(BOSS) doc2 = Document(BOSS) wp = WayStack(max_length=10, threshold=10) w1 = WayPoint(doc1, 10) w2 = WayPoint(doc1, 10) wp.append(w1)
def pytest_funcarg__boss(request): return Mock()