1- from contextlib import contextmanager
2- from functools import wraps
31from pathlib import Path
42from shutil import rmtree
5- from tempfile import TemporaryDirectory
63from typing import Callable
74
85from nox import Session , session
1411SessionFunc = Callable [[Session ], None ]
1512
1613
17- def build_test_repo (install : bool = True ) -> Callable [[SessionFunc ], SessionFunc ]:
18- """Build a test repo from test-config.yaml before a session"""
19-
20- def decorator (session_func : SessionFunc ) -> SessionFunc :
21- @wraps (session_func )
22- def wrapper (session : Session ) -> None :
23- _build_test_repo (session , install )
24- return session_func (session )
25-
26- return wrapper
27-
28- return decorator
29-
30-
31- def install_latest_idom (session_func : SessionFunc ) -> SessionFunc :
32- # install the latest version of IDOM by pulling it from the main repo
33-
34- @wraps (session_func )
35- def wrapper (session : Session ) -> None :
36- try :
37- session .run (
38- "git" , "clone" , "https://github.com/idom-team/idom.git" , external = True
39- )
40- session .install ("./idom[testing,starlette]" )
41- session_func (session )
42- finally :
43- idom_dir = HERE / "idom"
44- if idom_dir .exists ():
45- rmtree (idom_dir )
46-
47- return wrapper
48-
49-
50- @session
51- def test (session : Session ) -> None :
52- session .notify ("test_suite" , posargs = session .posargs )
53- session .notify ("test_style" )
54-
55-
56- @session
57- @build_test_repo ()
58- @install_latest_idom
14+ @session (tags = ["test" ])
5915def test_suite (session : Session ) -> None :
16+ build_test_repo (session )
17+ install_latest_reactpy (session )
6018 session .chdir ("test-repo" )
6119 session .run ("playwright" , "install" , "chromium" )
6220 session .run ("pytest" , "tests" , "--import-mode=importlib" , * session .posargs )
6321
6422
65- @session
66- @build_test_repo (install = False )
23+ @session (tags = ["test" ])
6724def test_style (session : Session ) -> None :
25+ build_test_repo (session , install = False )
6826 session .install ("black" , "flake8" )
6927 session .run ("black" , "--check" , "test-repo" , * list (map (str , HERE .glob ("*.py" ))))
7028 session .run ("flake8" , "test-repo" )
7129
7230
73- def _build_test_repo (session : Session , install : bool ) -> None :
31+ def build_test_repo (session : Session , install : bool = True ) -> None :
32+ """Build a test repo from test-config.yaml"""
7433 # Need to remove node_modules so cookiecutter doesn't think since the cookiecutter
7534 # will try to format those files if present
7635 for path in TEMPLATE_DIR .rglob ("node_modules" ):
@@ -91,3 +50,15 @@ def _build_test_repo(session: Session, install: bool) -> None:
9150 session .install ("." )
9251 session .install ("-r" , "requirements.txt" )
9352 session .chdir (".." )
53+
54+
55+ def install_latest_reactpy (session : Session ) -> SessionFunc :
56+ # install the latest version of ReactPy by pulling it from the main repo
57+ try :
58+ session .install (
59+ "reactpy[testing,starlette] @ git+https://github.com/reactive-python/reactpy"
60+ )
61+ finally :
62+ reactpy_dir = HERE / "reactpy"
63+ if reactpy_dir .exists ():
64+ rmtree (reactpy_dir )
0 commit comments