Skip to content

Commit

Permalink
test: update tests (#122)
Browse files Browse the repository at this point in the history
* chore(deps): add `pytest-benchmark`
* ci: move `pytest` command
* ci: disable `codeql` on `pull_request`
  • Loading branch information
DeadNews authored Jul 19, 2023
1 parent 6b309b3 commit 6226443
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 28 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: CodeQL
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: 23 17 * * 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: poetry install

- name: Run tests
run: poetry run pytest --cov-report=xml -m "not key_required"
run: poetry run poe test
env:
UPLOADCARE_KEY: ${{ secrets.UPLOADCARE_KEY }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml
.hypothesis/
.pytest_cache/
cover/
.benchmarks/

# Translations
*.mo
Expand Down
35 changes: 32 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 24 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,39 @@ ruff = "^0.0.278"

[tool.poetry.group.test.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-asyncio = "^0.21.1"
pytest-benchmark = "^4.0.0"
pytest-cov = "^4.1.0"
pytest-httpx = "^0.22.0"

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"

[tool.poe.tasks]
ruff = "ruff check ."
black = "black --check ."
mypy = "mypy ."
lint.sequence = ["ruff", "black", "mypy"]

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"
[tool.poe.tasks.test]
cmd = "pytest --cov-report=xml -m 'not online and not benchmark'"

[tool.poe.tasks.benchmark]
cmd = "pytest -m 'benchmark and not online' --benchmark-autosave --benchmark-compare"

[tool.pytest.ini_options]
addopts = "--verbose --cov=./src --cov-report=term"
testpaths = ["tests"]
markers = ["benchmark", "online"]

[tool.coverage.report]
exclude_lines = [
"# pragma: no cover",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.black]
line-length = 99
Expand All @@ -63,18 +82,6 @@ warn_unused_ignores = true
module = ["tests.*"]
allow_untyped_defs = true

[tool.pytest.ini_options]
addopts = "--verbose --cov=./src"
testpaths = ["tests"]
markers = ["docker", "key_required"]

[tool.coverage.report]
exclude_lines = [
"# pragma: no cover",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.ruff]
line-length = 99
select = ["ALL"]
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

@pytest.fixture()
def img() -> bytes:
return Path("tests/resources/pic.png").read_bytes()
return Path("tests/data/pic.png").read_bytes()
File renamed without changes.
File renamed without changes
62 changes: 62 additions & 0 deletions tests/test_bm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python
import pytest
from click.testing import CliRunner
from dotenv import load_dotenv
from images_upload_cli.__main__ import cli
from pytest_httpx import HTTPXMock

from tests.mock import uploadcare


@pytest.fixture()
def runner():
return CliRunner()


@pytest.mark.online()
@pytest.mark.benchmark(max_time=2)
def test_bm_cli_online(benchmark, runner: CliRunner):
@benchmark
def result():
return runner.invoke(
cli=cli,
args=[
"-h",
"uploadcare",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
],
)

assert result.exit_code == 0


@pytest.mark.benchmark(max_time=2)
def test_bm_cli(benchmark, runner: CliRunner, httpx_mock: HTTPXMock):
# mock response
httpx_mock.add_response(text=uploadcare)

# loading .env variables
load_dotenv(dotenv_path="tests/data/.env.sample")

@benchmark
def result():
return runner.invoke(
cli=cli,
args=[
"-h",
"uploadcare",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
"tests/data/pic.png",
],
)

assert result.exit_code == 0
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def runner():
[
pytest.param(["--help"], id="help"),
pytest.param(
["tests/resources/pic.png", "-C", "-h", "uploadcare", "--thumbnail", "--notify"],
["tests/data/pic.png", "-C", "-h", "uploadcare", "--thumbnail", "--notify"],
id="uploadcare,thumbnail",
),
],
Expand All @@ -24,11 +24,11 @@ def test_cli(runner: CliRunner, args: list[str]):
assert runner.invoke(cli=cli, args=args).exit_code == 0


@pytest.mark.key_required()
@pytest.mark.online()
@pytest.mark.parametrize(
"args",
[
pytest.param(["tests/resources/pic.png", "-C", "-h", hosting], id=hosting)
pytest.param(["tests/data/pic.png", "-C", "-h", hosting], id=hosting)
for hosting in HOSTINGS
],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def test_upload_funcs(
httpx_mock.add_response(text=mock_text)

# loading .env variables
load_dotenv(dotenv_path="tests/resources/.env.sample")
load_dotenv(dotenv_path="tests/data/.env.sample")

# images upload
async with AsyncClient() as client:
Expand Down

0 comments on commit 6226443

Please sign in to comment.