Skip to content

Commit

Permalink
get tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Jun 1, 2023
1 parent 8f0ffae commit 5e610bf
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 68 deletions.
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
name = "project"
version = "0.0.0"
description = "Scripts for managing the ReactPy respository"
dependencies = ["invoke", "ruff", "black"]
dependencies = [
"invoke",
"ruff",
"black",
"toml",
]

# --- Hatch ----------------------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions src/py/reactpy/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.coverage.*

# --- Build Artifacts ---
reactpy/_static
61 changes: 0 additions & 61 deletions src/py/reactpy/pyproject-temp.toml

This file was deleted.

44 changes: 41 additions & 3 deletions src/py/reactpy/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dependencies = [
"lxml >=4",
]
[project.optional-dependencies]
all = ["reactpy[starlette,sanic,fastapi,flask,tornado,testing]"]

starlette = [
"starlette >=0.13.6",
"uvicorn[standard] >=0.19.0",
Expand Down Expand Up @@ -73,13 +75,24 @@ Source = "https://github.com/reactive-python/reactpy"
path = "reactpy/__init__.py"

[tool.hatch.envs.default]
features = ["all"]
pre-install-command = "hatch run build --hooks-only"
dependencies = [
"coverage[toml]>=6.5",
"pytest",
"pytest-asyncio>=0.17",
"pytest-mock",
"pytest-rerunfailures",
"pytest-timeout",
"responses",
"playwright",
# I'm not quite sure why this needs to be installed for tests with Sanic to pass
"sanic-testing",
# Used to generate model changes from layout update messages
"jsonpointer",
]
[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test = "playwright install && pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = [
"- coverage combine",
Expand All @@ -102,8 +115,8 @@ dependencies = [
]

[tool.hatch.envs.lint.scripts]
typing = "mypy --install-types --non-interactive {args:reactpy tests}"
all = ["typing"]
types = "mypy --strict reactpy"
all = ["types"]

[[tool.hatch.build.hooks.build-scripts.scripts]]
work_dir = "../../js"
Expand All @@ -116,6 +129,23 @@ artifacts = [
"app/dist/"
]

# --- Pytest ---------------------------------------------------------------------------

[tool.pytest.ini_options]
testpaths = "tests"
xfail_strict = true
python_files = "*asserts.py test_*.py"
asyncio_mode = "auto"

# --- MyPy -----------------------------------------------------------------------------

[tool.mypy]
incremental = false
ignore_missing_imports = true
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true

# --- Coverage -------------------------------------------------------------------------

[tool.coverage.run]
Expand All @@ -131,8 +161,16 @@ reactpy = ["reactpy", "*/reactpy/reactpy"]
tests = ["tests", "*/reactpy/tests"]

[tool.coverage.report]
fail_under = 100
show_missing = true
skip_covered = true
sort = "Name"
exclude_lines = [
"no cov",
'\.\.\.\$',
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
omit = [
"reactpy/__main__.py",
]
2 changes: 1 addition & 1 deletion src/py/reactpy/tests/test__option.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_deprecated_option():
opt = DeprecatedOption("is deprecated!", "A_FAKE_OPTION", None)

with pytest.warns(DeprecationWarning, match="is deprecated!"):
assert opt.current == "is deprecated"
assert opt.current is None

with pytest.warns(DeprecationWarning, match="is deprecated!"):
opt.current = "something"
23 changes: 21 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import annotations

import json
import logging
import os
import re
from shlex import join
import sys
import toml
from dataclasses import dataclass
from logging import getLogger
from pathlib import Path
from shutil import rmtree
from typing import TYPE_CHECKING, Any, Callable
Expand Down Expand Up @@ -33,7 +36,16 @@ def __call__(
# --- Constants ------------------------------------------------------------------------


log = getLogger(__name__)
log = logging.getLogger(__name__)
log.setLevel("INFO")
log_handler = logging.StreamHandler(sys.stdout)
log_handler.setFormatter(logging.Formatter("%(message)s"))
log.addHandler(log_handler)


# --- Constants ------------------------------------------------------------------------


ROOT = Path(__file__).parent
SRC_DIR = ROOT / "src"
JS_DIR = SRC_DIR / "js"
Expand All @@ -59,6 +71,11 @@ def env(context: Context):
"""Install development environment"""
in_py(context, "pip install -e .", hide="out")
in_js(context, "npm ci", hide="out")
for py_proj in PY_PROJECTS:
py_proj_toml = toml.load(py_proj / "pyproject.toml")
hatch_default_env = py_proj_toml["tool"]["hatch"]["envs"].get("default", {})
hatch_default_deps = hatch_default_env.get("dependencies", [])
context.run(f"pip install {' '.join(map(repr, hatch_default_deps))}")


@task
Expand All @@ -70,6 +87,7 @@ def lint_py(context: Context, fix: bool = False):
else:
context.run("ruff .")
context.run("black --check --diff .")
in_py(context, "hatch run lint:all")


@task
Expand Down Expand Up @@ -142,6 +160,7 @@ def publish(context: Context, dry_run: str = ""):
def in_py(context: Context, *commands: str, **kwargs: Any) -> None:
for p in PY_PROJECTS:
with context.cd(p):
log.info(f"Running commands in {p}...")
for c in commands:
context.run(c, **kwargs)

Expand Down

0 comments on commit 5e610bf

Please sign in to comment.