diff --git a/.gitignore b/.gitignore index b6e4761..826fb22 100644 --- a/.gitignore +++ b/.gitignore @@ -102,7 +102,7 @@ celerybeat.pid *.sage.py # Environments -.env +.test.env .venv env/ venv/ diff --git a/.test.env b/.test.env new file mode 100644 index 0000000..071f9c1 --- /dev/null +++ b/.test.env @@ -0,0 +1 @@ +TERM=dumb diff --git a/hyperfocus/termui/printer.py b/hyperfocus/termui/printer.py index 2af228a..b292b76 100644 --- a/hyperfocus/termui/printer.py +++ b/hyperfocus/termui/printer.py @@ -12,7 +12,7 @@ from hyperfocus.termui import formatter, icons -console = Console(highlight=False) +console = Console(highlight=False, force_terminal=True) def echo(text: str): diff --git a/poetry.lock b/poetry.lock index 185aa5c..833d51b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -286,6 +286,18 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "six", "pytest-xdist", "virtualenv"] +[[package]] +name = "pytest-dotenv" +version = "0.5.2" +description = "A py.test plugin that parses environment files before running tests" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +pytest = ">=5.0.0" +python-dotenv = ">=0.9.1" + [[package]] name = "pytest-mock" version = "3.8.2" @@ -311,6 +323,17 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" [package.dependencies] six = ">=1.5" +[[package]] +name = "python-dotenv" +version = "0.20.0" +description = "Read key-value pairs from a .env file and set them as environment variables" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.extras] +cli = ["click (>=5.0)"] + [[package]] name = "pyyaml" version = "6.0" @@ -396,7 +419,7 @@ testing = ["coverage (>=4)", "coverage-enable-subprocess (>=1)", "flaky (>=3)", [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "d9bd3dd96c29796bdacc2d9223dd33ef338ccc88b25a41f478b923438dd94689" +content-hash = "58c6906f9a91f4d61a13b658fc82f353baa0582245812a13183b1e24277cf545" [metadata.files] atomicwrites = [] @@ -457,11 +480,13 @@ pytest-cov = [ {file = "pytest-cov-3.0.0.tar.gz", hash = "sha256:e7f0f5b1617d2210a2cabc266dfe2f4c75a8d32fb89eafb7ad9d06f6d076d470"}, {file = "pytest_cov-3.0.0-py3-none-any.whl", hash = "sha256:578d5d15ac4a25e5f961c938b85a05b09fdaae9deef3bb6de9a6e766622ca7a6"}, ] +pytest-dotenv = [] pytest-mock = [] python-dateutil = [ {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, ] +python-dotenv = [] pyyaml = [ {file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"}, {file = "PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c"}, diff --git a/pyproject.toml b/pyproject.toml index 71aa6a6..0e00c3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ mypy = ">=0.961" freezegun = "^1.2.1" types-tabulate = "^0.8.11" pre-commit = "^2.6" +pytest-dotenv = "^0.5.2" [tool.poetry.scripts] hyf = "hyperfocus.cli:hyf" @@ -57,3 +58,7 @@ src_paths = ["hyperfocus", "tests"] module=["peewee", "pyperclip"] warn_unused_ignores = false ignore_missing_imports = true + +[tool.pytest.ini_options] +env_override_existing_values = 1 +env_files = [".test.env"] diff --git a/tests/conftest.py b/tests/conftest.py index 9d06184..4397054 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import datetime +import os import re import shutil from pathlib import Path @@ -70,3 +71,10 @@ def __init__(self): self._callback_commands = [] return MockSession() + + +@pytest.fixture(scope="session", autouse=True) +def no_color(): + os.environ["TERM"] = "dumb" + yield + del os.environ["TERM"] diff --git a/tests/test_printer.py b/tests/test_printer.py index 3cdeddf..422a773 100644 --- a/tests/test_printer.py +++ b/tests/test_printer.py @@ -7,8 +7,8 @@ @pytest.mark.parametrize( "func, expected", [ - ("banner", "\x1b[3;38;5;228mfoobar\x1b[0m\n"), - ("new_day", f"{icons.NEW_DAY} \x1b[38;5;81mfoobar\x1b[0m\n"), + ("banner", "foobar\n"), + ("new_day", f"{icons.NEW_DAY} foobar\n"), ], ) def test_banner(capsys, func, expected):