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

✅ Add CI configs to run tests on Windows and MacOS #824

Merged
merged 23 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
517a3d1
matrix with OS and Python versions to run unit test
svlandeg May 3, 2024
240514c
fix typo
svlandeg May 3, 2024
fed844c
fix typo (2)
svlandeg May 3, 2024
112c3d0
fix sourcing
svlandeg May 3, 2024
91678fc
revert sourcing fix
svlandeg May 3, 2024
eefcf56
read_text with 'utf-8' encoding specifically
svlandeg May 3, 2024
7c48939
skip completion tests for Windows and MacOS
svlandeg May 3, 2024
7e3a08e
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
6f0878b
Merge branch 'master' into feature/windows_ci
svlandeg May 13, 2024
93074e2
include OS in coverage name to prevent duplicates
svlandeg May 13, 2024
4b08ebf
use matrix os specifically
svlandeg May 13, 2024
07d593b
ignore errors in generating coverage report (test)
svlandeg May 13, 2024
9aba40b
revert ignoring errors (as it didn't work)
svlandeg May 13, 2024
4d69948
another test with env
svlandeg May 13, 2024
37f6ea5
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2024
aa586d7
use env argument for every test currently failing on Windows
svlandeg May 13, 2024
7cedc45
revert using matrix.os (change not strictly necessary)
svlandeg May 13, 2024
0a76dbd
disable caching on macOS
svlandeg May 13, 2024
88d7aa0
c/p source paths to coverage.paths section (test)
svlandeg May 13, 2024
5dec753
try coverage run with relative files (test)
svlandeg May 13, 2024
4644679
create needs_linux pytest fixture
svlandeg May 14, 2024
f992a31
fix import
svlandeg May 14, 2024
324d1fb
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] May 14, 2024
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
17 changes: 14 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ on:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ "3.11" ]
include:
- os: ubuntu-latest
python-version: "3.7"
- os: macos-latest
python-version: "3.8"
- os: windows-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "3.10"
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Dump GitHub context
env:
Expand All @@ -33,6 +43,7 @@ jobs:
# cache: "pip"
# cache-dependency-path: pyproject.toml
- uses: actions/cache@v3
if: ${{ runner.os != 'macOS' }}
id: cache
with:
path: ${{ env.pythonLocation }}
Expand All @@ -52,7 +63,7 @@ jobs:
- name: Store coverage files
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}
name: coverage-${{ runner.os }}-${{ matrix.python-version }}
path: coverage

coverage-combine:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ omit = [
"typer/_typing.py"
]
context = '${CONTEXT}'
relative_files = true

[tool.coverage.report]
exclude_lines = [
Expand Down
4 changes: 4 additions & 0 deletions tests/test_completion/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

from docs_src.commands.index import tutorial001 as mod

from ..utils import needs_linux


@needs_linux
def test_show_completion():
result = subprocess.run(
[
Expand All @@ -20,6 +23,7 @@ def test_show_completion():
assert "_TUTORIAL001.PY_COMPLETE=complete_bash" in result.stdout


@needs_linux
def test_install_completion():
bash_completion_path: Path = Path.home() / ".bashrc"
text = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -55,5 +56,6 @@ def test_script():
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -55,5 +56,6 @@ def test_script():
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -56,5 +57,6 @@ def test_script():
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -56,5 +57,6 @@ def test_script():
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -47,5 +48,6 @@ def test_script():
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -51,5 +52,6 @@ def test_script():
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -51,5 +52,6 @@ def test_script():
[sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
)
assert "Usage" in result.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_main(tmpdir):
if binary_file.exists(): # pragma: no cover
binary_file.unlink()
result = runner.invoke(app, ["--file", f"{binary_file}"])
text = binary_file.read_text()
text = binary_file.read_text(encoding="utf-8")
binary_file.unlink()
assert result.exit_code == 0
assert "Binary file written" in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_main(tmpdir):
if binary_file.exists(): # pragma: no cover
binary_file.unlink()
result = runner.invoke(app, ["--file", f"{binary_file}"])
text = binary_file.read_text()
text = binary_file.read_text(encoding="utf-8")
binary_file.unlink()
assert result.exit_code == 0
assert "Binary file written" in result.output
Expand Down
4 changes: 4 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
needs_py310 = pytest.mark.skipif(
sys.version_info < (3, 10), reason="requires python3.10+"
)

needs_linux = pytest.mark.skipif(
not sys.platform.startswith("linux"), reason="Test requires Linux"
)
Loading