Skip to content

Commit

Permalink
Move from 3.7 to support 3.11 on tests. (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanderaa authored Nov 8, 2023
1 parent 53927d7 commit ba17b09
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]
runs-on: "ubuntu-20.04"
env:
PYTHON_VER: "${{ matrix.python-version }}"
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.7"]
python-version: ["3.10"]
env:
PYTHON_VER: "${{ matrix.python-version }}"
steps:
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]
runs-on: "ubuntu-20.04"
env:
PYTHON_VER: "${{ matrix.python-version }}"
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ classifiers = [
"Intended Audience :: Developers",
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
include = [
"LICENSE",
Expand All @@ -26,7 +27,7 @@ include = [
]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"
textfsm = "^1.1.0"

[tool.poetry.dev-dependencies]
Expand Down Expand Up @@ -55,7 +56,7 @@ test = ["pytest"]

[tool.black]
line-length = 120
target-version = ['py37']
target-version = ['py38']
include = '\.pyi?$'
exclude = '''
(
Expand Down
26 changes: 24 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tasks for use with Invoke."""
import os
import sys
from distutils.util import strtobool
from invoke import task

try:
Expand All @@ -10,6 +9,29 @@
sys.exit("Please make sure to `pip install toml` or enable the Poetry shell and run `poetry install`.")


def strtobool(val: str) -> bool:
"""Convert a string representation of truth to true (1) or false (0).
Args:
val (str): String representation of truth.
Returns:
bool: True or False
"""
val = val.lower()

# Check for valid truth values
if val in ("y", "yes", "t", "true", "on", "1"):
return True

# Check for valid false values
if val in ("n", "no", "f", "false", "off", "0"):
return False

# Raise error if not valid truth value
raise ValueError(f"Invalid truth value {val}")


def is_truthy(arg):
"""Convert "truthy" strings into Booleans.
Expand All @@ -30,7 +52,7 @@ def is_truthy(arg):
TOOL_CONFIG = PYPROJECT_CONFIG["tool"]["poetry"]

# Can be set to a separate Python version to be used for launching or building image
PYTHON_VER = os.getenv("PYTHON_VER", "3.7")
PYTHON_VER = os.getenv("PYTHON_VER", "3.9")
# Name of the docker image/image
IMAGE_NAME = os.getenv("IMAGE_NAME", TOOL_CONFIG["name"])
# Tag for the image
Expand Down
33 changes: 33 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Test functions for tasks.py."""
import pytest

from tasks import strtobool


@pytest.mark.parametrize(
"test_case, expected",
[
("y", True),
("yes", True),
("true", True),
("t", True),
("on", True),
("1", True),
("n", False),
("no", False),
("false", False),
("f", False),
("off", False),
("0", False),
],
)
def test_strtobool(test_case, expected):
"""Test strtobool function."""
assert strtobool(test_case) == expected


def test_strtobool_error():
"""Test generation of the error message."""
with pytest.raises(ValueError) as excinfo:
strtobool("invalid")
assert "Invalid truth value invalid" in str(excinfo.value)

0 comments on commit ba17b09

Please sign in to comment.