Skip to content

Commit

Permalink
meh
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed May 13, 2024
1 parent a6ab587 commit ad4772c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ omit =
betty/_package/**
betty/_resizeimage.py
betty/tests/**
parallel = True
source = betty

[report]
Expand Down
4 changes: 4 additions & 0 deletions betty/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ def _init_ctx_verbosity(
logger_level is not None
and logger.getEffectiveLevel() > logger_level
):
print(logger)
print(logger)
print(logger)
logger.setLevel(logger_level)
raise RuntimeError([logger_level, logger, logger.level])

return _init_ctx_verbosity

Expand Down
65 changes: 48 additions & 17 deletions betty/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
import logging
from asyncio import to_thread
from collections.abc import AsyncIterator
from contextlib import chdir
from multiprocessing import get_context
from pathlib import Path
from typing import TypeVar, ParamSpec, Any
from unittest.mock import AsyncMock
from unittest.mock import AsyncMock, DEFAULT

import aiofiles
import click
Expand Down Expand Up @@ -33,21 +34,17 @@
P = ParamSpec("P")


class DummyCommandError(Exception):
pass


@click.command(name="test")
@click.command(name="noop")
@global_command
async def _test_command() -> None:
raise DummyCommandError
async def _noop_command() -> None:
pass


class DummyExtension(Extension, CommandProvider):
class NoOpExtension(Extension, CommandProvider):
@property
def commands(self) -> dict[str, Command]:
return {
"test": _test_command,
"noop": _noop_command,
}


Expand Down Expand Up @@ -99,7 +96,7 @@ async def test_configuration_without_help(self, new_temporary_app: App) -> None:

async def test_help_with_configuration(self, new_temporary_app: App) -> None:
new_temporary_app.project.configuration.extensions.append(
ExtensionConfiguration(DummyExtension)
ExtensionConfiguration(NoOpExtension)
)
await new_temporary_app.project.configuration.write()

Expand Down Expand Up @@ -144,12 +141,12 @@ async def test_with_discovered_configuration(
dump: Dump = {
"base_url": url,
"extensions": {
DummyExtension.name(): {},
NoOpExtension.name(): {},
},
}
await config_file.write(json.dumps(dump))
with chdir(working_directory_path):
await to_thread(run, "test", expected_exit_code=1)
await to_thread(run, "noop")


class TestCatchExceptions:
Expand Down Expand Up @@ -275,8 +272,10 @@ async def test_without_project(
self, betty_qtbot: BettyQtBot, new_temporary_app: App
) -> None:
process = get_context("spawn").Process(target=self._target, args=["gui"])
process.start()
process.join()
try:
process.start()
finally:
process.join()

async def test_with_project(
self, betty_qtbot: BettyQtBot, new_temporary_app: App, tmp_path: Path
Expand All @@ -291,8 +290,10 @@ async def test_with_project(
process = get_context("spawn").Process(
target=self._target, args=["gui", "-c", str(configuration_file_path)]
)
process.start()
process.join()
try:
process.start()
finally:
process.join()


class TestUnknownCommand:
Expand All @@ -316,3 +317,33 @@ async def test(self, mocker: MockerFixture) -> None:
m_update_translations = mocker.patch("betty.locale.update_translations")
await to_thread(run, "update-translations")
m_update_translations.assert_awaited_once()


class TestVerbosity:
async def xtest(self, mocker: MockerFixture, new_temporary_app: App) -> None:
# @todo just bloody mock it...
betty_logger = logging.Logger('betty')
root_logger = logging.Logger("root")
m_betty_logger = mocker.Mock(wraps=betty_logger)
m_root_logger = mocker.Mock(wraps=root_logger)
m_getLogger = mocker.Mock(wraps=logging.getLogger)
mocker.patch("logging.getLogger", new=m_getLogger)

def _get_logger(logger_name: str | None = None) -> logging.Logger:
return {"betty": m_betty_logger, None: m_root_logger}.get(logger_name, DEFAULT)

m_getLogger.side_effect = _get_logger
new_temporary_app.project.configuration.extensions.enable(NoOpExtension)
await new_temporary_app.project.configuration.write()

def _run() -> None:
run(
"-v",
"-c",
str(new_temporary_app.project.configuration.configuration_file_path),
"noop",
)
m_betty_logger.setLevel.assert_called_once_with(logging.INFO)
raise RuntimeError

await to_thread(_run)
4 changes: 3 additions & 1 deletion bin/test-pytest
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ cd "$(dirname "$0")/.."
echo 'Running pytest...'

coverage erase
pytest --cov --cov-append --cov-config=.coveragerc --no-cov-on-fail "$@"
COVERAGE_PROCESS_START="$(pwd)/.coveragerc" PYTHONPATH="$(cd site; pwd)" coverage run --module pytest "$@"
coverage combine
coverage report --skip-covered --skip-empty
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ test = [
'pytest ~= 7.3, >= 7.3.1',
'pytest-aioresponses ~= 0.2, >= 0.2.0 ',
'pytest-asyncio ~= 0.23, >= 0.23.4 ',
'pytest-cov ~= 5.0',
'pytest-mock ~= 3.10, >= 3.10.0',
'pytest-qt ~= 4.2, >= 4.2.0',
'pytest-xvfb ~= 3.0, >= 3.0.0',
Expand Down
3 changes: 3 additions & 0 deletions site/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import coverage

coverage.process_startup()

0 comments on commit ad4772c

Please sign in to comment.