This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit e310e7b4fa30eae9a9121f24bc8afd1a00e2e5a4
Author: Andrey Anshin <[email protected]>
AuthorDate: Thu Jan 11 13:52:53 2024 +0400

    Fix tests to adopt changes in Jinja 3.1.3 (#36731)
    
    (cherry picked from commit 8b33e25e502c18f42dd3f76c95fefd78fb3a04a3)
---
 tests/models/test_mappedoperator.py | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/tests/models/test_mappedoperator.py 
b/tests/models/test_mappedoperator.py
index 76dba4538b..253aab8eff 100644
--- a/tests/models/test_mappedoperator.py
+++ b/tests/models/test_mappedoperator.py
@@ -21,7 +21,6 @@ import logging
 from collections import defaultdict
 from datetime import timedelta
 from typing import TYPE_CHECKING
-from unittest import mock
 from unittest.mock import patch
 
 import pendulum
@@ -405,7 +404,12 @@ def test_mapped_expand_against_params(dag_maker, 
dag_params, task_params, expect
     assert t.expand_input.value == {"params": [{"c": "x"}, {"d": 1}]}
 
 
-def test_mapped_render_template_fields_validating_operator(dag_maker, session):
+def test_mapped_render_template_fields_validating_operator(dag_maker, session, 
tmp_path):
+    file_template_dir = tmp_path / "path" / "to"
+    file_template_dir.mkdir(parents=True, exist_ok=True)
+    file_template = file_template_dir / "file.ext"
+    file_template.write_text("loaded data")
+
     with set_current_task_instance_session(session=session):
 
         class MyOperator(BaseOperator):
@@ -427,7 +431,7 @@ def 
test_mapped_render_template_fields_validating_operator(dag_maker, session):
         def execute(self, context):
             pass
 
-        with dag_maker(session=session):
+        with dag_maker(session=session, 
template_searchpath=tmp_path.__fspath__()):
             task1 = BaseOperator(task_id="op1")
             output1 = task1.output
             mapped = MyOperator.partial(
@@ -455,10 +459,7 @@ def 
test_mapped_render_template_fields_validating_operator(dag_maker, session):
         mapped_ti.map_index = 0
 
         assert isinstance(mapped_ti.task, MappedOperator)
-        with patch("builtins.open", mock.mock_open(read_data=b"loaded data")), 
patch(
-            "os.path.isfile", return_value=True
-        ), patch("os.path.getmtime", return_value=0):
-            
mapped.render_template_fields(context=mapped_ti.get_template_context(session=session))
+        
mapped.render_template_fields(context=mapped_ti.get_template_context(session=session))
         assert isinstance(mapped_ti.task, MyOperator)
 
         assert mapped_ti.task.partial_template == "a", "Should be templated!"
@@ -468,7 +469,12 @@ def 
test_mapped_render_template_fields_validating_operator(dag_maker, session):
         assert mapped_ti.task.file_template == "loaded data", "Should be 
templated!"
 
 
-def 
test_mapped_expand_kwargs_render_template_fields_validating_operator(dag_maker, 
session):
+def 
test_mapped_expand_kwargs_render_template_fields_validating_operator(dag_maker, 
session, tmp_path):
+    file_template_dir = tmp_path / "path" / "to"
+    file_template_dir.mkdir(parents=True, exist_ok=True)
+    file_template = file_template_dir / "file.ext"
+    file_template.write_text("loaded data")
+
     with set_current_task_instance_session(session=session):
 
         class MyOperator(BaseOperator):
@@ -490,7 +496,7 @@ def 
test_mapped_expand_kwargs_render_template_fields_validating_operator(dag_mak
             def execute(self, context):
                 pass
 
-        with dag_maker(session=session):
+        with dag_maker(session=session, 
template_searchpath=tmp_path.__fspath__()):
             mapped = MyOperator.partial(
                 task_id="a", partial_template="{{ ti.task_id }}", 
partial_static="{{ ti.task_id }}"
             ).expand_kwargs(
@@ -502,10 +508,7 @@ def 
test_mapped_expand_kwargs_render_template_fields_validating_operator(dag_mak
         mapped_ti: TaskInstance = dr.get_task_instance(mapped.task_id, 
session=session, map_index=0)
 
         assert isinstance(mapped_ti.task, MappedOperator)
-        with patch("builtins.open", mock.mock_open(read_data=b"loaded data")), 
patch(
-            "os.path.isfile", return_value=True
-        ), patch("os.path.getmtime", return_value=0):
-            
mapped.render_template_fields(context=mapped_ti.get_template_context(session=session))
+        
mapped.render_template_fields(context=mapped_ti.get_template_context(session=session))
         assert isinstance(mapped_ti.task, MyOperator)
 
         assert mapped_ti.task.partial_template == "a", "Should be templated!"

Reply via email to