Skip to content

Commit

Permalink
chore: use nox to run tests
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Dec 26, 2023
1 parent a586857 commit 3d15eb3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 46 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install build tool
run: |
pip install -U build
- name: Build artifacts
run: |
python -m build --sdist --wheel .
run: pipx run build

- name: Upload to Pypi
run: |
pip install twine
Expand Down
22 changes: 2 additions & 20 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,13 @@ jobs:
fail-fast: false
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
lektor-version: [latest, stable]
lektor-version: [dev, stable]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache PIP
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-${{ matrix.lektor-version }}
restore-keys: pip-${{ matrix.python-version }}-

- name: Install Lektor latest
if: matrix.lektor-version == 'latest'
run: pip install "lektor @ git+https://github.com/lektor/lektor.git"

- name: Install Lektor stable
if: matrix.lektor-version == 'stable'
run: pip install -U lektor

- name: Install Pytest
run: pip install -U pytest

- name: Run tests
run: pytest tests
run: pipx run nox -s "tests-${{ matrix.python-version }}(lektor_version='${{ matrix.lektor-version }}')"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
__pycache__/
.pdm.toml
*.egg-info/
.venv/
3 changes: 1 addition & 2 deletions lektor_tailwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import os
import subprocess
import threading

from lektor.pluginsystem import Plugin
from pytailwindcss import install, get_bin_path
from pytailwindcss import get_bin_path, install

__version__ = "0.1.2"
GRACEFUL_TIMEOUT = 5
Expand Down
18 changes: 18 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import nox


@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"])
@nox.parametrize("lektor_version", ["dev", "stable"])
def tests(session: nox.Session, lektor_version: str):
if lektor_version == "dev":
session.install("git+https://github.com/lektor/lektor.git")
else:
# Install Lektor stable
session.install("-U", "lektor")

# Install Pytest
session.install("-U", "pytest")
session.install(".")

# 运行测试
session.run("pytest", "tests")
32 changes: 15 additions & 17 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

import pytest

PACKAGE_FILES = (
"setup.py", "setup.cfg", "lektor_tailwind.py", "README.md", "LICENSE"
)
PACKAGE_FILES = ("setup.py", "setup.cfg", "lektor_tailwind.py", "README.md", "LICENSE")


@pytest.fixture
Expand All @@ -34,13 +32,6 @@ def tmp_project_path(tmp_path, monkeypatch):
for fn in "_build", "packages":
shutil.rmtree(project / fn, ignore_errors=True)

# Copy plugin source files to project packages
srcdir = testdir / ".."
packagedir = project / "packages/tailwind"
packagedir.mkdir(parents=True)
for fn in PACKAGE_FILES:
shutil.copy(srcdir / fn, packagedir / fn)

monkeypatch.setenv("LEKTOR_PROJECT", os.fspath(project))

return project
Expand All @@ -59,7 +50,9 @@ def slow_build(tmp_project_path):

plugin = tmp_project_path / "packages/slow_build"
plugin.mkdir(parents=True)
plugin.joinpath("setup.py").write_text(dedent("""
plugin.joinpath("setup.py").write_text(
dedent(
"""
from setuptools import setup
setup(
name="lektor-slow-build",
Expand All @@ -69,15 +62,21 @@ def slow_build(tmp_project_path):
],
},
)
"""))
plugin.joinpath("lektor_slow_build.py").write_text(dedent(f"""
"""
)
)
plugin.joinpath("lektor_slow_build.py").write_text(
dedent(
f"""
import time
from lektor.pluginsystem import Plugin
class SlowBuildPlugin(Plugin):
def on_before_build_all(self, *args, **kwargs):
time.sleep({build_delay:f})
"""))
"""
)
)


class LektorServerFixture:
Expand Down Expand Up @@ -131,8 +130,7 @@ def wait_for_build(self, timeout=30):
try_until = time.time() + timeout

while not (
stdout.contains(self.FINISHED_PRUNE)
and stderr.contains(self.TAILWIND_DONE)
stdout.contains(self.FINISHED_PRUNE) and stderr.contains(self.TAILWIND_DONE)
):
time_left = try_until - time.time()
if time_left <= 0:
Expand All @@ -152,7 +150,7 @@ def contains(self, regexp):
def discard_one(self, regexp):
m = re.search(regexp, self.buf)
if m is not None:
self.buf = self.buf[m.end():]
self.buf = self.buf[m.end() :]

def _communicate1(self, timeout):
"""Append any available output to the appropriate buffer."""
Expand Down

0 comments on commit 3d15eb3

Please sign in to comment.