Skip to content

Commit

Permalink
Merge pull request #451 from hexchain/pytest
Browse files Browse the repository at this point in the history
Use pytest and friends in tox and a couple of other fixes
  • Loading branch information
ronf committed Feb 19, 2022
2 parents 2f733d5 + c8eaa06 commit 324dddb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
5 changes: 3 additions & 2 deletions .coveragerc
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
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
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
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
@@ -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

0 comments on commit 324dddb

Please sign in to comment.