From 5d2566c7a306e7835e9a8c474f667fcd8ea07a7b Mon Sep 17 00:00:00 2001 From: Guido Imperiale Date: Tue, 14 Apr 2020 14:15:02 +0100 Subject: [PATCH] Polish --- distributed/tests/test_client.py | 24 ++++++--------- distributed/tests/test_scheduler.py | 1 - distributed/tests/test_security.py | 46 +++++++++++++---------------- distributed/tests/test_variable.py | 1 - distributed/tests/test_worker.py | 13 +++----- 5 files changed, 33 insertions(+), 52 deletions(-) diff --git a/distributed/tests/test_client.py b/distributed/tests/test_client.py index 297394631ae..3cfad303708 100644 --- a/distributed/tests/test_client.py +++ b/distributed/tests/test_client.py @@ -152,8 +152,7 @@ def test_map(c, s, a, b): L4 = c.map(add, range(3), range(4)) results = yield c.gather(L4) - if sys.version_info[0] >= 3: - assert results == list(map(add, range(3), range(4))) + assert results == list(map(add, range(3), range(4))) def f(x, y=10): return x + y @@ -1439,9 +1438,7 @@ def test_many_submits_spread_evenly(c, s, a, b): def test_traceback(c, s, a, b): x = c.submit(div, 1, 0) tb = yield x.traceback() - - if sys.version_info[0] >= 3: - assert any("x / y" in line for line in pluck(3, traceback.extract_tb(tb))) + assert any("x / y" in line for line in pluck(3, traceback.extract_tb(tb))) @gen_cluster(client=True) @@ -1468,12 +1465,11 @@ def test_gather_traceback(c, s, a, b): def test_traceback_sync(c): x = c.submit(div, 1, 0) tb = x.traceback() - if sys.version_info[0] >= 3: - assert any( - "x / y" in line - for line in concat(traceback.extract_tb(tb)) - if isinstance(line, str) - ) + assert any( + "x / y" in line + for line in concat(traceback.extract_tb(tb)) + if isinstance(line, str) + ) y = c.submit(inc, x) tb2 = y.traceback() @@ -2597,9 +2593,8 @@ def test_run_coroutine(c, s, a, b): with pytest.raises(RuntimeError, match="hello"): yield c.run(throws, 1) - if sys.version_info >= (3, 5): - results = yield c.run(asyncinc, 2, delay=0.01) - assert results == {a.address: 3, b.address: 3} + results = yield c.run(asyncinc, 2, delay=0.01) + assert results == {a.address: 3, b.address: 3} def test_run_coroutine_sync(c, s, a, b): @@ -5212,7 +5207,6 @@ def test_scatter_direct(s, a, b): yield c.close() -@pytest.mark.skipif(sys.version_info[0] < 3, reason="cloudpickle Py27 issue") @gen_cluster(client=True) def test_unhashable_function(c, s, a, b): d = {"a": 1} diff --git a/distributed/tests/test_scheduler.py b/distributed/tests/test_scheduler.py index 2b48fa030e4..7551ae7f09d 100644 --- a/distributed/tests/test_scheduler.py +++ b/distributed/tests/test_scheduler.py @@ -794,7 +794,6 @@ def test_retire_workers_no_suspicious_tasks(c, s, a, b): @pytest.mark.skipif( sys.platform.startswith("win"), reason="file descriptors not really a thing" ) -@pytest.mark.skipif(sys.version_info < (3, 6), reason="intermittent failure") @gen_cluster(client=True, nthreads=[], timeout=240) def test_file_descriptors(c, s): yield gen.sleep(0.1) diff --git a/distributed/tests/test_security.py b/distributed/tests/test_security.py index 8665ebead33..dae035449af 100644 --- a/distributed/tests/test_security.py +++ b/distributed/tests/test_security.py @@ -149,15 +149,15 @@ def test_tls_config_for_role(): sec.get_tls_config_for_role("supervisor") +def assert_many_ciphers(ctx): + assert len(ctx.get_ciphers()) > 2 # Most likely + + def test_connection_args(): def basic_checks(ctx): assert ctx.verify_mode == ssl.CERT_REQUIRED assert ctx.check_hostname is False - def many_ciphers(ctx): - if sys.version_info >= (3, 6): - assert len(ctx.get_ciphers()) > 2 # Most likely - c = { "distributed.comm.tls.ca-file": ca_file, "distributed.comm.tls.scheduler.key": key1, @@ -171,12 +171,12 @@ def many_ciphers(ctx): assert not d["require_encryption"] ctx = d["ssl_context"] basic_checks(ctx) - many_ciphers(ctx) + assert_many_ciphers(ctx) d = sec.get_connection_args("worker") ctx = d["ssl_context"] basic_checks(ctx) - many_ciphers(ctx) + assert_many_ciphers(ctx) # No cert defined => no TLS d = sec.get_connection_args("client") @@ -193,13 +193,12 @@ def many_ciphers(ctx): assert d["require_encryption"] ctx = d["ssl_context"] basic_checks(ctx) - if sys.version_info >= (3, 6): - supported_ciphers = ctx.get_ciphers() - tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]] - assert len(tls_12_ciphers) == 1 - tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]] - if len(tls_13_ciphers): - assert len(tls_13_ciphers) == 3 + + supported_ciphers = ctx.get_ciphers() + tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]] + assert len(tls_12_ciphers) == 1 + tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]] + assert len(tls_13_ciphers) in (0, 3) def test_listen_args(): @@ -207,10 +206,6 @@ def basic_checks(ctx): assert ctx.verify_mode == ssl.CERT_REQUIRED assert ctx.check_hostname is False - def many_ciphers(ctx): - if sys.version_info >= (3, 6): - assert len(ctx.get_ciphers()) > 2 # Most likely - c = { "distributed.comm.tls.ca-file": ca_file, "distributed.comm.tls.scheduler.key": key1, @@ -224,12 +219,12 @@ def many_ciphers(ctx): assert not d["require_encryption"] ctx = d["ssl_context"] basic_checks(ctx) - many_ciphers(ctx) + assert_many_ciphers(ctx) d = sec.get_listen_args("worker") ctx = d["ssl_context"] basic_checks(ctx) - many_ciphers(ctx) + assert_many_ciphers(ctx) # No cert defined => no TLS d = sec.get_listen_args("client") @@ -246,13 +241,12 @@ def many_ciphers(ctx): assert d["require_encryption"] ctx = d["ssl_context"] basic_checks(ctx) - if sys.version_info >= (3, 6): - supported_ciphers = ctx.get_ciphers() - tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]] - assert len(tls_12_ciphers) == 1 - tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]] - if len(tls_13_ciphers): - assert len(tls_13_ciphers) == 3 + + supported_ciphers = ctx.get_ciphers() + tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]] + assert len(tls_12_ciphers) == 1 + tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]] + assert len(tls_13_ciphers) in (0, 3) @pytest.mark.asyncio diff --git a/distributed/tests/test_variable.py b/distributed/tests/test_variable.py index 64765d808c7..b8aaa9275c5 100644 --- a/distributed/tests/test_variable.py +++ b/distributed/tests/test_variable.py @@ -161,7 +161,6 @@ def test_timeout_get(c, s, a, b): assert result == 1 -@pytest.mark.skipif(sys.version_info[0] == 2, reason="Multi-client issues") @pytest.mark.slow @gen_cluster(client=True, nthreads=[("127.0.0.1", 2)] * 5, Worker=Nanny, timeout=None) def test_race(c, s, *workers): diff --git a/distributed/tests/test_worker.py b/distributed/tests/test_worker.py index a5e364ec0cd..42cd1bf0c92 100644 --- a/distributed/tests/test_worker.py +++ b/distributed/tests/test_worker.py @@ -136,11 +136,10 @@ def reset(self): with pytest.raises(ZeroDivisionError): yield y - if sys.version_info[0] >= 3: - tb = yield y._traceback() - assert any( - "1 / 0" in line for line in pluck(3, traceback.extract_tb(tb)) if line - ) + tb = yield y._traceback() + assert any( + "1 / 0" in line for line in pluck(3, traceback.extract_tb(tb)) if line + ) assert "Compute Failed" in hdlr.messages["warning"][0] logger.setLevel(old_level) @@ -473,9 +472,6 @@ def f(dask_worker=None): @gen_cluster(client=True) def test_run_coroutine_dask_worker(c, s, a, b): - if sys.version_info < (3,) and tornado.version_info < (4, 5): - pytest.skip("test needs Tornado 4.5+ on Python 2.7") - @gen.coroutine def f(dask_worker=None): yield gen.sleep(0.001) @@ -586,7 +582,6 @@ def test_clean(c, s, a, b): assert not c -@pytest.mark.skipif(sys.version_info[:2] == (3, 4), reason="mul bytes fails") @gen_cluster(client=True) def test_message_breakup(c, s, a, b): n = 100000