Skip to content

Commit fefa7aa

Browse files
committed
test pre-commit
1 parent 2e4fdcf commit fefa7aa

6 files changed

Lines changed: 51 additions & 0 deletions

File tree

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.4.0
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
- id: ruff-format
8+
9+
- repo: https://github.com/pre-commit/mirrors-mypy
10+
rev: v1.9.0
11+
hooks:
12+
- id: mypy

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[tool.ruff]
2+
line-length = 88
3+
target-version = "py310"
4+
5+
[tool.ruff.lint]
6+
select = ["E", "F", "I", "N", "W"]
7+
8+
[tool.mypy]
9+
python_version = "3.10"
10+
ignore_missing_imports = true
11+
12+
[tool.pytest.ini_options]
13+
testpaths = ["tests"]

src/__init__.py

Whitespace-only changes.

src/calculator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def add(a: int, b: int) -> int:
2+
"""兩數相加"""
3+
return a + b
4+
5+
6+
def divide(a: int, b: int) -> float:
7+
"""兩數相除"""
8+
if b == 0:
9+
raise ValueError("除數不能為 0")
10+
return a / b

tests/__init__.py

Whitespace-only changes.

tests/test_calculator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from src.calculator import add, divide
4+
5+
6+
def test_add():
7+
assert add(1, 2) == 3
8+
9+
10+
def test_divide():
11+
assert divide(10, 2) == 5.0
12+
13+
14+
def test_divide_by_zero():
15+
with pytest.raises(ValueError):
16+
divide(1, 0)

0 commit comments

Comments
 (0)