Skip to content

Commit

Permalink
chore: ignore ssh2 in tests, --pre flag for pre release python build/…
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
carlmontanari committed Jul 28, 2024
1 parent 09d30f9 commit de30afe
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pre_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
python -m pip install --upgrade setuptools wheel
python -m pip install nox
- name: run nox
# TERM is needed needed to make the terminal a tty (i think? without this system ssh is super broken)
# TERM is needed to make the terminal a tty (i think? without this system ssh is super broken)
# libssh2/ssh2-python were getting libssh2 linked incorrectly/weirdly and libraries were trying to be loaded
# from the temp dir that pip used for installs. setting the DYLD_LIBRARY_PATH envvar seems to solve this -- note
# that if brew macos packages get updated on runners this may break again :)
run: TERM=xterm DYLD_LIBRARY_PATH=/opt/homebrew/Cellar/libssh2/1.11.0_1/lib python -m nox -p $FRIENDLY_PYTHON_VERSION -k "not darglint"
run: TERM=xterm DYLD_LIBRARY_PATH=/opt/homebrew/Cellar/libssh2/1.11.0_1/lib PRE_RELEASE=1 python -m nox -p $FRIENDLY_PYTHON_VERSION -k "not darglint"
21 changes: 18 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""scrapli.noxfile"""

import os
import re
import sys
from pathlib import Path
Expand All @@ -11,6 +12,8 @@
nox.options.stop_on_first_error = False
nox.options.default_venv_backend = "venv"

PRE = bool(os.environ.get("PRE_RELEASE"))


def parse_requirements(dev: bool = True) -> Dict[str, str]:
"""
Expand Down Expand Up @@ -64,6 +67,18 @@ def parse_requirements(dev: bool = True) -> Dict[str, str]:
SKIP_LIST: List[str] = []


def _get_install_test_args() -> List[str]:
args = [".[dev]"]

if sys.platform == "darwin":
args = [".[dev-darwin]"]

if PRE:
args.append("--pre")

return args


@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"])
def unit_tests(session):
"""
Expand All @@ -85,7 +100,7 @@ def unit_tests(session):
session.run("chmod", "0600", "tests/test_data/files/scrapli_key", external=True)
session.run("chmod", "0600", "tests/test_data/files/scrapli_key_encrypted", external=True)
session.install("-U", "setuptools", "wheel", "pip")
session.install(".[dev]")
session.install(*_get_install_test_args())
session.run(
"python",
"-m",
Expand Down Expand Up @@ -119,7 +134,7 @@ def integration_tests(session):
return

session.install("-U", "setuptools", "wheel", "pip")
session.install(".[dev]")
session.install(*_get_install_test_args())
# setting scrapli boxen -> 1 so that the saved scrapli replay sessions are "correctly"
# pointing to the boxen dev env (i.e. port 21022 instead of 22 for iosxe, etc.)
session.run(
Expand Down Expand Up @@ -192,7 +207,7 @@ def pylama(session):
N/A
"""
session.install(".[dev]")
session.install(*_get_install_test_args())
session.run("python", "-m", "pylama", ".")


Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ Homepage = "https://github.com/carlmontanari/scrapli"
[tool.setuptools.dynamic]
version = { attr = "scrapli.__version__" }
dependencies = { file = "requirements.txt" }
# dev-darwin is same as dev but excludes ssh2-python
optional-dependencies.dev-darwin = { file = [
"requirements-dev.txt",
"requirements-textfsm.txt",
"requirements-genie.txt",
"requirements-ttp.txt",
"requirements-paramiko.txt",
"requirements-asyncssh.txt",
"requirements-community.txt",
] }
optional-dependencies.dev = { file = [
"requirements-dev.txt",
"requirements-textfsm.txt",
Expand Down
8 changes: 5 additions & 3 deletions scrapli/transport/plugins/ssh2/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from dataclasses import dataclass
from typing import Optional

from ssh2.channel import Channel
from ssh2.exceptions import AuthenticationError, SSH2Error
from ssh2.session import Session
# ignoring unable to import complaints for linters as ssh2 support is a bit lackluster due to
# upstream library staleness
from ssh2.channel import Channel # pylint: disable=E0401,E0611
from ssh2.exceptions import AuthenticationError, SSH2Error # pylint: disable=E0401,E0611
from ssh2.session import Session # pylint: disable=E0401,E0611

from scrapli.exceptions import (
ScrapliAuthenticationFailed,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def device_type(request):
yield request.param


@pytest.fixture(scope="function", params=["system", "ssh2", "paramiko"])
@pytest.fixture(scope="function", params=["system", "paramiko"])
def transport(request):
yield request.param

Expand Down
12 changes: 9 additions & 3 deletions tests/unit/transport/plugins/ssh2/test_ssh2_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
from scrapli.exceptions import ScrapliConnectionNotOpened


@pytest.mark.skipif(sys.version_info >= (3, 12), reason="skipping ssh2 on 3.12")
@pytest.mark.skipif(
(sys.version_info >= (3, 12) or sys.platform != "linux"), reason="skipping ssh2 on 3.12"
)
def test_open_channel_no_session(ssh2_transport):
with pytest.raises(ScrapliConnectionNotOpened):
assert ssh2_transport._open_channel()


@pytest.mark.skipif(sys.version_info >= (3, 12), reason="skipping ssh2 on 3.12")
@pytest.mark.skipif(
(sys.version_info >= (3, 12) or sys.platform != "linux"), reason="skipping ssh2 on 3.12"
)
def test_isalive_no_session(ssh2_transport):
assert ssh2_transport.isalive() is False


@pytest.mark.skipif(sys.version_info >= (3, 12), reason="skipping ssh2 on 3.12")
@pytest.mark.skipif(
(sys.version_info >= (3, 12) or sys.platform != "linux"), reason="skipping ssh2 on 3.12"
)
def test_write_exception(ssh2_transport):
with pytest.raises(ScrapliConnectionNotOpened):
ssh2_transport.write("blah")

0 comments on commit de30afe

Please sign in to comment.