Skip to content

Commit

Permalink
[IMP] checklog-odoo - use pytest instead of unittest refs #1
Browse files Browse the repository at this point in the history
  • Loading branch information
baimont committed Oct 10, 2023
1 parent 065d312 commit e9e0b68
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
source =
checklog-odoo
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- python-version: "3.12"
machine: ubuntu-22.04
steps:
- uses: "actions/checkout@v3"
- uses: "actions/checkout@v4"
- uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<!--- shortdesc-begin -->

Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions..
Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions.

<!--- shortdesc-end -->

Expand Down
27 changes: 13 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project]
name = "checklog-odoo"
dynamic = ["version"]
description = ''
description = 'Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions'
readme = "README.md"
requires-python = ">=3.7"
license = "MIT"
Expand Down Expand Up @@ -41,10 +41,15 @@ checklog-odoo = "checklog_odoo.cli.checklog:checklog_odoo"
path = "src/checklog_odoo/__about__.py"

[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
dependencies = []

[project.optional-dependencies]
metadata = []
test = [
"pytest",
"coverage[toml]",
]

[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
Expand Down Expand Up @@ -144,20 +149,14 @@ ban-relative-imports = "all"
"tests/**/*" = ["PLR2004", "S101", "TID252"]

[tool.coverage.run]
source_pkgs = ["checklog_odoo", "tests"]
branch = true
parallel = true
omit = [
"src/checklog_odoo/__about__.py",
]
source_pkgs = ["checklog-odoo"]

[tool.coverage.paths]
checklog_odoo = ["checklog_odoo", "*/checklog-odoo/checklog_odoo"]
tests = ["tests", "*/checklog-odoo/tests"]
source = ["src", ".tox/*/site-packages"]

[tool.coverage.report]
show_missing = true
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"pragma: no cover",
]
22 changes: 11 additions & 11 deletions tests/test_checklog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
# SPDX-License-Identifier: MIT

import os
import unittest
import pytest

from pathlib import Path

from click.testing import CliRunner

from checklog_odoo.cli.checklog import checklog_odoo

DATA_DIR = os.path.join(os.path.dirname(__file__), "data")


class TestChecklog(unittest.TestCase):
class TestChecklog:
def test1(self):
runner = CliRunner()
res = runner.invoke(checklog_odoo, [os.path.join(DATA_DIR, "test1.log")])
res = runner.invoke(checklog_odoo, [str(Path('data').joinpath("test1.log"))])
assert res.exit_code != 0
expected = "errors that caused failure (2):"
assert expected in res.output

def test2(self):
runner = CliRunner()
res = runner.invoke(
checklog_odoo, ["--ignore", " ERROR ", os.path.join(DATA_DIR, "test1.log")]
checklog_odoo, ["--ignore", " ERROR ", str(Path('data').joinpath("test1.log"))]
)
assert res.exit_code != 0
expected = "errors that caused failure (1):"
Expand All @@ -36,7 +36,7 @@ def test3(self):
runner = CliRunner()
res = runner.invoke(
checklog_odoo,
["-i", " ERROR ", "-i", " CRITICAL ", os.path.join(DATA_DIR, "test1.log")],
["-i", " ERROR ", "-i", " CRITICAL ", str(Path('data').joinpath("test1.log"))],
)
assert res.exit_code == 0
expected = "errors that did not cause failure (2):"
Expand All @@ -48,8 +48,8 @@ def test4(self):
checklog_odoo,
[
"-c",
os.path.join(DATA_DIR, "test_checklog.cfg"),
os.path.join(DATA_DIR, "test1.log"),
str(Path('data').joinpath("test_checklog.cfg")),
str(Path('data').joinpath("test1.log")),
],
)
assert res.exit_code != 0
Expand All @@ -60,11 +60,11 @@ def test4(self):

def test_empty(self):
runner = CliRunner()
res = runner.invoke(checklog_odoo, [os.path.join(DATA_DIR, "empty.log")])
res = runner.invoke(checklog_odoo, [str(Path('data').joinpath("empty.log"))])
assert res.exit_code != 0
expected = "No Odoo log record found in input."
assert expected in res.output
res = runner.invoke(
checklog_odoo, ["--no-err-if-empty", os.path.join(DATA_DIR, "empty.log")]
checklog_odoo, ["--no-err-if-empty", str(Path('data').joinpath("empty.log"))]
)
assert res.exit_code == 0
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ extras =
test
metadata
commands =
coverage run -m unittest discover
coverage run -m pytest {posargs}
coverage xml
coverage html

0 comments on commit e9e0b68

Please sign in to comment.