Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pytest and friends in tox #451

Merged
merged 3 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ exclude_lines =
partial_branches =
pragma: no branch
for .*
omit =
.tox/*
include =
asyncssh/*
tests/*
2 changes: 1 addition & 1 deletion asyncssh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def _set_tokens(self) -> None:
conn_hash = sha1(conn_info.encode('utf-8')).hexdigest()

self._tokens.update({'C': conn_hash,
'd': str(Path.home()),
'd': str(os.path.expanduser('~')),
'h': host,
'L': short_local_host,
'l': local_host,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ def mock_gethostname():

return 'thishost.local'

def mock_home():
def mock_expanduser(_):
"""Return a static local home directory"""

return '/home/user'

with patch('socket.gethostname', mock_gethostname):
with patch('pathlib.Path.home', mock_home):
with patch('os.path.expanduser', mock_expanduser):
config = self._parse_config(
'Hostname newhost\n'
'User newuser\n'
Expand Down
9 changes: 7 additions & 2 deletions tests/test_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@

_openssl_available = _openssl_version != b''

if _openssl_available:
_openssl_curves = run('openssl ecparam -list_curves')
else:
_openssl_curves = b''

# The openssl "-v2prf" option is only available in OpenSSL 1.0.2 or later
_openssl_supports_v2prf = _openssl_version >= b'OpenSSL 1.0.2'

Expand Down Expand Up @@ -2260,9 +2265,9 @@ def test_ec_explicit(self):
'-param_enc explicit' % curve)
asyncssh.read_private_key('priv')

@unittest.skipIf(b'secp224r1' not in run('openssl ecparam -list_curves'),
"this openssl doesn't support secp224r1")
@unittest.skipIf(not _openssl_available, "openssl isn't available")
@unittest.skipIf(b'secp224r1' not in _openssl_curves,
"this openssl doesn't support secp224r1")
def test_ec_explicit_unknown(self):
"""Import EC key with unknown explicit parameters"""

Expand Down
43 changes: 34 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
[tox]
envlist = {py36,py37,py38,py39,py310}-{linux,macos,windows}
minversion = 3.7
envlist = clean,{py36,py37,py38,py39,py310}-{linux,darwin,windows},report
skip_missing_interpreters = True

[testenv]
deps =
aiofiles>=0.6.0
bcrypt>=3.1.3
coverage
linux,macos: gssapi>=1.2.0
fido2>=0.9.2
libnacl>=1.4.2
pyOpenSSL>=17.0.0
python-pkcs11>=0.7.0
pytest>=7.0.1
pytest-cov>=3.0.0
setuptools>=18.5
linux,darwin: gssapi>=1.2.0
linux,darwin: python-pkcs11>=0.7.0
linux,darwin: uvloop>=0.9.1
windows: pywin32>=227
{py36,py37,py38,py39,py310}-{linux,macos}: uvloop>=0.9.1
platform =
linux: linux
macos: darwin
darwin: darwin
windows: win32
sitepackages = True
skip_missing_interpreters = True
usedevelop = True
setenv =
{py36,py37,py38,py39,py310}-{linux,darwin,windows}: COVERAGE_FILE = .coverage.{envname}
commands =
{envpython} -m pytest --cov --cov-report=term-missing:skip-covered {posargs}
depends =
{py36,py37,py38,py39,py310}-{linux,darwin,windows}: clean
report: {py36,py37,py38,py39,py310}-{linux,darwin,windows}

[testenv:clean]
deps = coverage
skip_install = true
commands = coverage erase

[testenv:report]
deps = coverage
skip_install = true
parallel_show_output = true
commands =
{envpython} -m coverage run -p -m unittest
coverage combine
coverage report --show-missing
coverage html

[pytest]
testpaths = tests