Example #1
0
    def test_sets_original_files_for_template_files(self):
        fd, filename = tempfile.mkstemp()
        try:
            os.write(fd, b'# conf')
            os.close(fd)

            spec = {
                '__cmd__': '{config_template!t}',
                'config_template': filename
            }
            task = ExternalTask.from_task_spec(spec)
            os.unlink(task.command)
            assert_that(task.original_files[task.command], is_(filename))
        finally:
            os.unlink(filename)
Example #2
0
 def callback():
     try:
         dialog.validate()
         group_spec = TaskGroupSpec.from_spec_file(dialog.filename)
         for spec in group_spec.iter_specs(dialog.start_repeat, dialog.num_repeats):
             task = ExternalTask.from_task_spec(spec, niceness=dialog.niceness)
             self.taskpile.enqueue(task)
         self.update()
     except Exception as err:
         msg = "Error: "
         if isinstance(err, KeyError):
             msg += "Undefined replacement key {}".format(str(err))
         else:
             msg += str(err)
         dialog.error = msg
         dialog.show()
Example #3
0
    def test_handles_config_template_files(self):
        fd, filename = tempfile.mkstemp()
        try:
            os.write(fd, b'# conf\nsetting = {somevar}\nfoo = bar\n')
            os.close(fd)

            spec = {
                '__cmd__': '{config_template!t}',
                '__name__': 'foo',
                'somevar': 'somevalue',
                'config_template': filename
            }
            task = ExternalTask.from_task_spec(spec)
            assert_that(task.command, is_not(filename))
            try:
                assert_that(task.command, is_(file_with_content(
                    b'# conf\nsetting = somevalue\nfoo = bar\n')))
            finally:
                os.unlink(task.command)
        finally:
            os.unlink(filename)
Example #4
0
 def test_can_be_created_from_task_spec(self):
     spec = {'__cmd__': 'cmd', '__name__': 'foo'}
     task = ExternalTask.from_task_spec(spec)
     assert_that(task, all_of(
         has_property('command', 'cmd'), has_property('name', 'foo')))