Example #1
0
 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
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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 _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()
Example #6
0
    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()
Example #7
0
 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
Example #8
0
 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
Example #9
0
 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
Example #10
0
 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)
Example #11
0
 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)
Example #12
0
 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
Example #13
0
 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
Example #14
0
 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]
Example #15
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
Example #17
0
 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
Example #18
0
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
Example #19
0
 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
Example #20
0
    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]
Example #21
0
    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
Example #22
0
 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')
Example #23
0
 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
Example #24
0
 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')
Example #25
0
 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
Example #26
0
 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
Example #27
0
 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")
Example #28
0
 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')