Skip to content

Commit 69138b1

Browse files
authored
test: add json_test (#9)
1 parent 7b241df commit 69138b1

File tree

4 files changed

+154
-1
lines changed

4 files changed

+154
-1
lines changed

.github/workflows/unit-test.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: unit-test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
unit-test:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
pull-requests: read
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Find changes
21+
uses: dorny/paths-filter@v3
22+
id: filter
23+
with:
24+
list-files: shell
25+
filters: |
26+
loggingx:
27+
- "loggingx/**"
28+
29+
- name: Set up Python
30+
if: steps.filter.outputs.loggingx == 'true'
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: "3.8"
34+
35+
- name: Install dependencies with poetry
36+
if: steps.filter.outputs.loggingx == 'true'
37+
run: |
38+
python -m pip install --upgrade pip
39+
pip install poetry
40+
poetry install
41+
42+
- name: Run tests
43+
if: steps.filter.outputs.loggingx == 'true'
44+
run: |
45+
poetry run pytest

loggingx/json_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from datetime import datetime, timezone
2+
3+
from .json import _json_dumps, _orjson_dumps
4+
5+
dump_cases = [
6+
(datetime(2024, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc), "2024-01-01T00:00:00+00:00"),
7+
]
8+
9+
10+
def test_json_dumps() -> None:
11+
for input, expected in dump_cases:
12+
assert _json_dumps({"a": input}) == f'{{"a": "{expected}"}}'
13+
14+
15+
def test_orjson_dumps() -> None:
16+
for input, expected in dump_cases:
17+
assert _orjson_dumps({"a": input}) == f'{{"a":"{expected}"}}'

poetry.lock

Lines changed: 85 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ python = ">=3.8,<4.0"
4747
mypy = "^1.11.1"
4848
ruff = "^0.6.1"
4949
orjson = "^3.10.7"
50+
pytest = "^8.3.3"
5051

5152

5253
[tool.ruff]
@@ -82,6 +83,7 @@ exclude = [
8283
line-length = 120
8384
indent-width = 4
8485

86+
8587
[tool.ruff.lint]
8688
select = ["E4", "E7", "E9", "F", "I"]
8789
ignore = []
@@ -91,6 +93,7 @@ unfixable = []
9193

9294
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
9395

96+
9497
[tool.ruff.format]
9598
quote-style = "double"
9699
indent-style = "space"
@@ -99,3 +102,7 @@ line-ending = "auto"
99102

100103

101104
[tool.mypy]
105+
106+
107+
[tool.pytest.ini_options]
108+
testpaths = ["loggingx"]

0 commit comments

Comments
 (0)