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

OS matrix in CI #596

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
25 changes: 15 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@ on:
- main
pull_request:
schedule:
- cron: '0 12 * * *'
- cron: "0 12 * * *"

jobs:
test:
strategy:
matrix:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
runs-on: ubuntu-latest
conf:
- { py: "3.7", os: "ubuntu-latest" }
- { py: "3.8", os: "ubuntu-latest" }
- { py: "3.9", os: "ubuntu-latest" }
- { py: "3.10", os: "ubuntu-latest" }
- { py: "3.11", os: "ubuntu-latest" }
# NOTE: We only test Windows and macOS on the latest Python;
# these primarily exist to ensure that we don't accidentally
# introduce Linux-isms into the development tooling.
- { py: "3.11", os: "windows-latest" }
- { py: "3.11", os: "macos-latest" }
runs-on: ${{ matrix.conf.os }}
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
- uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435
with:
python-version: ${{ matrix.python }}
python-version: ${{ matrix.conf.py }}
cache: "pip"
cache-dependency-path: pyproject.toml

Expand Down
13 changes: 7 additions & 6 deletions test/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import pretend # type: ignore
Expand All @@ -9,15 +10,15 @@

def test_get_cache_dir(monkeypatch):
# When we supply a cache directory, always use that
cache_dir = _get_cache_dir(Path("/tmp/foo/cache_dir"))
assert str(cache_dir) == "/tmp/foo/cache_dir"
cache_dir = _get_cache_dir(os.path.join("tmp", "foo", "cache_dir"))
assert str(cache_dir) == os.path.join("tmp", "foo", "cache_dir")
Comment on lines +13 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, is this because of the Windows failure? We should probably use pytest's built-in tempdir functionality here 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, to make the paths OS-agnostic. The os.path.join is to use have the string expand to a Windows-style path, but yeah those pytest docs look to be a better fit here.


get_pip_cache = pretend.call_recorder(lambda: "/fake/pip/cache/dir")
get_pip_cache = pretend.call_recorder(lambda: os.path.join("fake", "pip", "cache", "dir"))
monkeypatch.setattr(cache, "_get_pip_cache", get_pip_cache)

# When `pip cache dir` works, we use it. In this case, it's mocked.
cache_dir = _get_cache_dir(None, use_pip=True)
assert str(cache_dir) == "/fake/pip/cache/dir"
assert str(cache_dir) == os.path.join("fake", "pip", "cache", "dir")


def test_get_pip_cache():
Expand All @@ -44,8 +45,8 @@ def test_get_cache_dir_old_pip(monkeypatch):
monkeypatch.setattr(cache, "_PIP_VERSION", Version("1.0.0"))

# When we supply a cache directory, always use that
cache_dir = _get_cache_dir(Path("/tmp/foo/cache_dir"))
assert str(cache_dir) == "/tmp/foo/cache_dir"
cache_dir = _get_cache_dir(os.path.join("tmp", "foo", "cache_dir"))
assert str(cache_dir) == os.path.join("tmp", "foo", "cache_dir")

# In this case, we can't query `pip` to figure out where its HTTP cache is
# Instead, we use `~/.pip-audit-cache`
Expand Down