def testProcessRunMP(self, dependency1, depfile): output = StringIO.StringIO() cmd_run = Run(dep_file=depfile.name, task_list=tasks_sample()) result = cmd_run._execute(output, num_process=1) assert 0 == result got = output.getvalue().split("\n")[:-1] assert [". t1", ". t2", ". g1.a", ". g1.b", ". t3"] == got
def testProcessRunFilter(self, depfile_name): output = StringIO() cmd_run = Run(backend='dbm', dep_file=depfile_name, task_list=tasks_sample(), sel_tasks=["g1.a"]) cmd_run._execute(output) got = output.getvalue().split("\n")[:-1] assert [". g1.a"] == got
def testProcessRunEmptyFilter(self, depfile): output = StringIO.StringIO() cmd_run = Run(dep_file=depfile.name, task_list=tasks_sample(), sel_tasks=[]) cmd_run._execute(output) got = output.getvalue().split("\n")[:-1] assert [] == got
def _run_doit(self, sel_tasks, reporter=None, doit_vars=None): """load this file as dodo file to collect tasks""" inc = IncrementalTasks(self.py_files, test_files=list(self.test_files)) output = StringIO() config = { 'dep_file': self.DB_FILE, 'continue': True, 'outfile': output, } if reporter: config['reporter'] = reporter ctx = { 'tasks_generator': inc, 'DOIT_CONFIG': config, } doit_cmd.reset_vars() if doit_vars: for key, value in doit_vars.items(): doit_cmd.set_var(key, value) loader = ModuleTaskLoader(ctx) cmd = Run(task_loader=loader) cmd.parse_execute(sel_tasks) output.seek(0) return inc.graph, output.read()
def testProcessRunMThread(self, dependency1, depfile_name): output = StringIO() cmd_run = Run(backend='dbm', dep_file=depfile_name, task_list=tasks_sample()) result = cmd_run._execute(output, num_process=1, par_type='thread') assert 0 == result got = output.getvalue().split("\n")[:-1] assert [". t1", ". t2", ". g1.a", ". g1.b", ". t3"] == got
def testProcessRunSingle(self, depfile_name): output = StringIO() cmd_run = Run(backend='dbm', dep_file=depfile_name, task_list=tasks_sample(), sel_tasks=["t3"]) cmd_run._execute(output, single=True) got = output.getvalue().split("\n")[:-1] # t1 is a depenendency of t3 but not included assert [". t3"] == got
def testMP_not_available(self, depfile, monkeypatch): # make sure MRunner wont be used monkeypatch.setattr(runner.MRunner, "available", Mock(return_value=False)) monkeypatch.setattr(runner.MRunner, "__init__", 'not available') output = StringIO.StringIO() cmd_run = Run(dep_file=depfile.name, task_list=tasks_sample()) cmd_run._execute(output, num_process=3)
def testCustomReporter(self, depfile): output = StringIO.StringIO() class MyReporter(reporter.ConsoleReporter): def get_status(self, task): self.outstream.write('MyReporter.start %s\n' % task.name) cmd_run = Run(dep_file=depfile.name, task_list=[tasks_sample()[0]]) cmd_run._execute(output, reporter=MyReporter) got = output.getvalue().split("\n")[:-1] assert 'MyReporter.start t1' == got[0]
def testSetVerbosity(self, depfile): output = StringIO.StringIO() t = Task('x', None) used_verbosity = [] def my_execute(out, err, verbosity): used_verbosity.append(verbosity) t.execute = my_execute cmd_run = Run(dep_file=depfile.name, task_list=[t]) cmd_run._execute(output, verbosity=2) assert 2 == used_verbosity[0], used_verbosity
def cmd_run(request, depfile_name): output = StringIO() cmd = Run(task_loader=DodoTaskLoader()) params, _ = cmd.cmdparser.parse([]) params["outfile"] = output params["dodoFile"] = os.path.join(SAMPLE_DIR, "dodo.py") params["cwdPath"] = SAMPLE_DIR params["dep_file"] = depfile_name cmd.params = params # hack to make params available from fixture return cmd
def cmd_run(request, depfile_name): output = StringIO() cmd = Run(task_loader=DodoTaskLoader()) params, _ = cmd.cmdparser.parse([]) params['outfile'] = output params['dodoFile'] = os.path.join(SAMPLE_DIR, 'dodo.py') params['cwdPath'] = SAMPLE_DIR params['dep_file'] = depfile_name cmd.params = params # hack to make params available from fixture return cmd
def testProcessRunSingleSubtasks(self, depfile_name): output = StringIO() task_list = tasks_sample() assert task_list[4].name == 'g1.b' task_list[4].task_dep = ['t3'] cmd_run = Run(backend='dbm', dep_file=depfile_name, task_list=task_list, sel_tasks=["g1"]) cmd_run._execute(output, single=True) got = output.getvalue().split("\n")[:-1] # t3 is a depenendency of g1.b but not included assert [". g1.a", ". g1.b"] == got
def testSetVerbosity(self, depfile_name): output = StringIO() t = Task('x', None) used_verbosity = [] def my_execute(out, err, verbosity): used_verbosity.append(verbosity) t.execute = my_execute cmd_run = Run(backend='dbm', dep_file=depfile_name, task_list=[t]) cmd_run._execute(output, verbosity=2) assert 2 == used_verbosity[0], used_verbosity
def test_outfile(self, depfile): cmd_run = Run(dep_file=depfile.name, task_list=tasks_sample(), sel_tasks=["g1.a"]) cmd_run._execute('test.out') try: outfile = open('test.out', 'r') got = outfile.read() outfile.close() assert ". g1.a\n" == got, repr(got) finally: if os.path.exists('test.out'): os.remove('test.out')
def testMP_not_available(self, dependency1, depfile_name, capsys, monkeypatch): # make sure MRunner wont be used monkeypatch.setattr(runner.MRunner, "available", Mock(return_value=False)) output = StringIO() cmd_run = Run(backend='dbm', dep_file=depfile_name, task_list=tasks_sample()) result = cmd_run._execute(output, num_process=1) assert 0 == result got = output.getvalue().split("\n")[:-1] assert [". t1", ". t2", ". g1.a", ". g1.b", ". t3"] == got err = capsys.readouterr()[1] assert "WARNING:" in err assert "parallel using threads" in err
def testInvalidReporter(self, depfile): output = StringIO.StringIO() cmd_run = Run(dep_file=depfile.name, task_list=tasks_sample()) pytest.raises(InvalidCommand, cmd_run._execute, output, reporter="i dont exist")
def testInvalidParType(self, dependency1, depfile_name): output = StringIO() cmd_run = Run(backend='dbm', dep_file=depfile_name, task_list=tasks_sample()) pytest.raises(InvalidCommand, cmd_run._execute, output, num_process=1, par_type='not_exist')