Skip to content

Commit 7904669

Browse files
potiukashb
authored andcommitted
[AIRFLOW-5755] Fixed most problems with py27
1 parent d601752 commit 7904669

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

airflow/models/dag.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,10 @@ def pickle(self, session=None):
11481148
def tree_view(self):
11491149
"""Print an ASCII tree representation of the DAG."""
11501150
def get_downstream(task, level=0):
1151-
print((" " * level * 4) + str(task))
1151+
line = (" " * level * 4) + str(task)
1152+
if six.PY2:
1153+
line = line.decode("utf-8")
1154+
print(line)
11521155
level += 1
11531156
for t in task.downstream_list:
11541157
get_downstream(t, level)

tests/contrib/hooks/test_ssh_hook.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,15 @@ def test_ssh_connection_old_cm(self):
211211
def test_tunnel(self):
212212
hook = SSHHook(ssh_conn_id='ssh_default')
213213

214+
import psutil
214215
import subprocess
215216
import socket
216217

217218
subprocess_kwargs = dict(
218219
args=["python", "-c", HELLO_SERVER_CMD],
219220
stdout=subprocess.PIPE,
220221
)
221-
with subprocess.Popen(**subprocess_kwargs) as server_handle, hook.create_tunnel(2135, 2134):
222+
with psutil.Popen(**subprocess_kwargs) as server_handle, hook.create_tunnel(2135, 2134):
222223
server_output = server_handle.stdout.read(5)
223224
self.assertEqual(b"ready", server_output)
224225
socket = socket.socket()

tests/models/test_baseoperator.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import datetime
2121
import unittest
22-
from unittest import mock
22+
from tests.compat import mock
2323
import uuid
2424
from collections import namedtuple
2525

@@ -214,12 +214,11 @@ def test_nested_template_fields_declared_must_exist(self):
214214
with DAG("test-dag", start_date=DEFAULT_DATE):
215215
task = DummyOperator(task_id="op1")
216216

217-
with self.assertRaises(AttributeError) as e:
217+
re = "('ClassWithCustomAttributes' object|ClassWithCustomAttributes instance) " \
218+
"has no attribute 'missing_field'"
219+
with self.assertRaisesRegexp(AttributeError, re):
218220
task.render_template(ClassWithCustomAttributes(template_fields=["missing_field"]), {})
219221

220-
self.assertEqual("'ClassWithCustomAttributes' object has no attribute 'missing_field'",
221-
str(e.exception))
222-
223222
def test_jinja_invalid_expression_is_just_propagated(self):
224223
"""Test render_template propagates Jinja invalid expression errors."""
225224
with DAG("test-dag", start_date=DEFAULT_DATE):

tests/models/test_dag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ def test_roots(self):
815815
t5 = DummyOperator(task_id="t5")
816816
[t1, t2] >> t3 >> [t4, t5]
817817

818-
self.assertCountEqual(dag.roots, [t1, t2])
818+
six.assertCountEqual(self, dag.roots, [t1, t2])
819819

820820
def test_leaves(self):
821821
"""Verify if dag.leaves returns the leaf tasks of a DAG."""
@@ -827,7 +827,7 @@ def test_leaves(self):
827827
t5 = DummyOperator(task_id="t5")
828828
[t1, t2] >> t3 >> [t4, t5]
829829

830-
self.assertCountEqual(dag.leaves, [t4, t5])
830+
six.assertCountEqual(self, dag.leaves, [t4, t5])
831831

832832
def test_tree_view(self):
833833
"""Verify correctness of dag.tree_view()."""

tests/test_sentry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import datetime
2121
import unittest
22-
from unittest.mock import Mock, MagicMock
22+
from tests.compat import Mock, MagicMock
2323
from freezegun import freeze_time
2424

2525
from sentry_sdk import configure_scope

tests/test_utils/system_tests_class.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919
import os
20-
from contextlib import ContextDecorator
20+
try:
21+
from contextdecorator import ContextDecorator
22+
except ImportError:
23+
from contextlib import ContextDecorator
24+
2125
from shutil import move
2226
from tempfile import mkdtemp
2327
from unittest import TestCase, skip

tests/www/test_views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,14 @@ def test_import_variables(self):
557557
self.assertEqual(case_b_dict, db_dict['dict_key'])
558558

559559

560-
@conf_vars({("webserver", "base_url"): "http://localhost:8080/test"})
561560
class TestMountPoint(unittest.TestCase):
562561
@classmethod
563562
def setUpClass(cls):
564563
# Clear cached app to remount base_url forcefully
565564
application.app = None
566-
app = application.cached_app(config={'WTF_CSRF_ENABLED': False}, testing=True)
567-
cls.client = Client(app, BaseResponse)
565+
with conf_vars({("webserver", "base_url"): "http://localhost:8080/test"}):
566+
app = application.cached_app(config={'WTF_CSRF_ENABLED': False}, testing=True)
567+
cls.client = Client(app, BaseResponse)
568568

569569
@classmethod
570570
def tearDownClass(cls):

0 commit comments

Comments
 (0)