예제 #1
0
    def test_resolve_template_files_list(self):

        with NamedTemporaryFile(suffix='.template') as f:
            f.write(b'{{ ds }}')
            f.flush()
            template_dir = os.path.dirname(f.name)
            template_file = os.path.basename(f.name)

            with DAG('test-dag', start_date=DEFAULT_DATE, template_searchpath=template_dir):
                task = DummyOperator(task_id='op1')

            task.test_field = [template_file, 'some_string']
            task.template_fields = ('test_field',)
            task.template_ext = ('.template',)
            task.resolve_template_files()

        self.assertEqual(task.test_field, ['{{ ds }}', 'some_string'])
예제 #2
0
    def test_resolve_template_files_value(self):

        with NamedTemporaryFile(suffix='.template') as f:
            f.write('{{ ds }}'.encode('utf8'))
            f.flush()
            template_dir = os.path.dirname(f.name)
            template_file = os.path.basename(f.name)

            dag = DAG('test-dag',
                      start_date=DEFAULT_DATE,
                      template_searchpath=template_dir)

            with dag:
                task = DummyOperator(task_id='op1')

            task.test_field = template_file
            task.template_fields = ('test_field', )
            task.template_ext = ('.template', )
            task.resolve_template_files()

        self.assertEqual(task.test_field, '{{ ds }}')
예제 #3
0
    def test_resolve_template_files_value(self):

        with NamedTemporaryFile(suffix='.template') as f:
            f.write('{{ ds }}'.encode('utf8'))
            f.flush()
            template_dir = os.path.dirname(f.name)
            template_file = os.path.basename(f.name)

            dag = DAG('test-dag',
                      start_date=DEFAULT_DATE,
                      template_searchpath=template_dir)

            with dag:
                task = DummyOperator(task_id='op1')

            task.test_field = template_file
            task.template_fields = ('test_field',)
            task.template_ext = ('.template',)
            task.resolve_template_files()

        self.assertEqual(task.test_field, '{{ ds }}')