Skip to content

Commit

Permalink
Add basic test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb committed Oct 18, 2024
1 parent 6cad682 commit 572f394
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 15 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
with:
changed-files: ${{ needs.get-changed-files.outputs.changed-files }}

# test:
# name: Test
# needs:
# - pre-commit
# uses: ./.github/workflows/test-action.yml
tests:
name: Tests
needs:
- pre-commit
uses: ./.github/workflows/test-action.yml

docs:
name: Docs
Expand All @@ -52,7 +52,7 @@ jobs:
github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
needs:
- docs
# - test
- tests

build-python-package:
name: Python Package
Expand All @@ -68,6 +68,7 @@ jobs:
uses: ./.github/workflows/deploy-package-action.yml
if: ${{ inputs.release && success() }}
needs:
- tests
- docs
- build-python-package
with:
Expand All @@ -81,7 +82,7 @@ jobs:
runs-on: ubuntu-24.04
if: always()
needs:
# - test
- tests
- docs
- deploy-docs
- build-python-package
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: Tests

on:
workflow_call:

jobs:
macOS:
strategy:
fail-fast: false
max-parallel: 4
matrix:
os_version: [12, 13, 14, 15]

runs-on: macos-${{ matrix.os_version }}
timeout-minutes: 10

steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 2

- name: Install Nox
run: |
python -m pip install --upgrade pip
pip install 'nox[uv]>=2024.3'
- name: Install Test Requirements
run: |
nox --force-color -e tests_all --install-only
- name: Test
env:
SKIP_REQUIREMENTS_INSTALL: '1'
run: |
nox --force-color -e tests_all -- -vv --run-destructive
- name: Set Exit Status
if: always()
run: |
mkdir exitstatus
echo "${{ job.status }}" > exitstatus/${{ github.job }}-${{ runner.os }}
- name: Upload Exit Status
if: always()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: exitstatus-${{ github.job }}-${{ runner.os }}
path: exitstatus
if-no-files-found: error
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ ENV/

src/dooti/version.py
.nox/
artifacts/
91 changes: 91 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# pylint: disable=missing-function-docstring,protected-access
import os
import shutil
import sys
from importlib import metadata
from pathlib import Path

import nox

os.environ["PYTHONDONTWRITEBYTECODE"] = "1"

REPO_ROOT = Path(__file__).resolve().parent
ARTIFACTS_DIR = REPO_ROOT / "artifacts"
COVERAGE_REPORT_DB = REPO_ROOT / ".coverage"
COVERAGE_REPORT_PROJECT = "coverage-project.xml"
COVERAGE_REPORT_TESTS = "coverage-tests.xml"

SKIP_REQUIREMENTS_INSTALL = os.environ.get("SKIP_REQUIREMENTS_INSTALL", "0") == "1"
PYTHON_VERSIONS = ("3.10", "3.11", "3.12", "3.13")


nox.options.reuse_existing_virtualenvs = True
Expand Down Expand Up @@ -56,3 +66,84 @@ def docs_dev(session):
shutil.rmtree(build_dir)

session.run("sphinx-autobuild", *args)


@nox.session(python="3")
def tests(session):
return _tests(session)


@nox.session(python=PYTHON_VERSIONS)
def tests_all(session):
return _tests(session)


def _tests(session): # pylint: disable=too-many-branches
_install(session, "-e", ".[tests]")

interpreter_version = session.python
if interpreter_version == "3":
interpreter_version += f".{sys.version_info.minor}"

env = {
"COVERAGE_FILE": str(COVERAGE_REPORT_DB),
}

args = [
"--rootdir",
str(REPO_ROOT),
"--showlocals",
"-ra",
"-s",
]
if session._runner.global_config.forcecolor:
args.append("--color=yes")
if not session.posargs:
args.append("tests/")
else:
for arg in session.posargs:
if arg.startswith("--color") and args[0].startswith("--color"):
args.pop(0)
args.append(arg)
for arg in session.posargs:
if arg.startswith("-"):
continue
if arg.startswith(f"tests{os.sep}"):
break
try:
Path(arg).resolve().relative_to(REPO_ROOT / "tests")
break
except ValueError:
continue
else:
args.append("tests/")
session.run("coverage", "erase")
try:
session.run("coverage", "run", "-m", "pytest", *args, env=env)
finally:
session.run(
"coverage",
"xml",
"-o",
str(ARTIFACTS_DIR / interpreter_version / COVERAGE_REPORT_PROJECT),
"--omit=tests/*",
"--include=src/dooti/*",
)
session.run(
"coverage",
"xml",
"-o",
str(ARTIFACTS_DIR / interpreter_version / COVERAGE_REPORT_TESTS),
"--omit=src/dooti/*",
"--include=tests/*",
)
try:
session.run(
"coverage", "report", "--show-missing", "--include=src/dooti/*,tests/*"
)
finally:
if COVERAGE_REPORT_DB.exists():
shutil.move(
str(COVERAGE_REPORT_DB),
str(ARTIFACTS_DIR / interpreter_version / COVERAGE_REPORT_DB.name),
)
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ lint = [
]
tests = [
"pytest>=7.2.0",
"coverage",
"pytest-skip-markers",
]

[project.scripts]
Expand Down
10 changes: 2 additions & 8 deletions src/dooti/dooti.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ def get_default_uti(self, uti: str | UTType) -> str | None:
if not handler:
return None

# name = handler.lastPathComponent()[:-4]

return handler.fileSystemRepresentation().decode()

def get_default_ext(self, ext: str) -> str | None:
Expand All @@ -152,8 +150,6 @@ def get_default_ext(self, ext: str) -> str | None:
if not handler:
return None

# name = handler.lastPathComponent()[:-4]

return handler.fileSystemRepresentation().decode()

def get_default_scheme(self, scheme: str) -> str | None:
Expand All @@ -166,15 +162,13 @@ def get_default_scheme(self, scheme: str) -> str | None:
if "file" == scheme:
raise ValueError("The file:// scheme cannot be looked up.")

url = NSURL.URLWithString_(scheme + "://nonexistant")
url = NSURL.URLWithString_(scheme + "://nonexistent")

handler = self.workspace.URLForApplicationToOpenURL_(url)

if not handler:
return None

# name = handler.lastPathComponent()[:-4]

return handler.fileSystemRepresentation().decode()

def get_app_path(self, app: str) -> NSURL:
Expand All @@ -187,7 +181,7 @@ def get_app_path(self, app: str) -> NSURL:
:raises:
ApplicationNotFound: when no matching application was found
"""
if "/" == app[0]:
if app[0] == "/":
return NSURL.fileURLWithPath_(app)

try:
Expand Down
Loading

0 comments on commit 572f394

Please sign in to comment.