Skip to content

Commit

Permalink
Replace tmpdir fixture with tmp_path in tests (#3551) (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
theruziev authored and asvetlov committed Jan 19, 2019
1 parent 8bfcf9a commit 94e7b49
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
13 changes: 0 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import hashlib
import pathlib
import platform
import shutil
import ssl
import tempfile

import pytest
import trustme

pytest_plugins = ['aiohttp.pytest_plugin', 'pytester']


@pytest.fixture
def shorttmpdir():
"""Provides a temporary directory with a shorter file system path than the
tmpdir fixture.
"""
tmpdir = pathlib.Path(tempfile.mkdtemp())
yield tmpdir
shutil.rmtree(tmpdir, ignore_errors=True)


@pytest.fixture
def tls_certificate_authority():
if (platform.system() == 'Linux' and
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def ssl_key():


@pytest.fixture
def unix_sockname(shorttmpdir):
sock_path = shorttmpdir / 'socket.sock'
def unix_sockname(tmpdir):
sock_path = tmpdir / 'socket.sock'
return str(sock_path)


Expand Down
8 changes: 4 additions & 4 deletions tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ def test_run_app_custom_backlog_unix(patched_loop) -> None:


@skip_if_no_unix_socks
def test_run_app_http_unix_socket(patched_loop, shorttmpdir) -> None:
def test_run_app_http_unix_socket(patched_loop, tmpdir) -> None:
app = web.Application()

sock_path = str(shorttmpdir / 'socket.sock')
sock_path = str(tmpdir / 'socket.sock')
printer = mock.Mock(wraps=stopper(patched_loop))
web.run_app(app, path=sock_path, print=printer)

Expand All @@ -366,10 +366,10 @@ def test_run_app_http_unix_socket(patched_loop, shorttmpdir) -> None:


@skip_if_no_unix_socks
def test_run_app_https_unix_socket(patched_loop, shorttmpdir) -> None:
def test_run_app_https_unix_socket(patched_loop, tmpdir) -> None:
app = web.Application()

sock_path = str(shorttmpdir / 'socket.sock')
sock_path = str(tmpdir / 'socket.sock')
ssl_context = ssl.create_default_context()
printer = mock.Mock(wraps=stopper(patched_loop))
web.run_app(app, path=sock_path, ssl_context=ssl_context, print=printer)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def test_non_app() -> None:

@pytest.mark.skipif(platform.system() == "Windows",
reason="Unix socket support is required")
async def test_addresses(make_runner, shorttmpdir) -> None:
async def test_addresses(make_runner, tmpdir) -> None:
_sock = get_unused_port_socket('127.0.0.1')
runner = make_runner()
await runner.setup()
tcp = web.SockSite(runner, _sock)
await tcp.start()
path = str(shorttmpdir / 'tmp.sock')
path = str(tmpdir / 'tmp.sock')
unix = web.UnixSite(runner, path)
await unix.start()
actual_addrs = runner.addresses
Expand Down

0 comments on commit 94e7b49

Please sign in to comment.