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_reactpy (session_func : SessionFunc ) -> SessionFunc :
32- # install the latest version of ReactPy 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" ,
39- "clone" ,
40- "https://github.com/reactive-python/reactpy.git" ,
41- external = True ,
42- )
43- session .install ("./reactpy[testing,starlette]" )
44- session_func (session )
45- finally :
46- reactpy_dir = HERE / "reactpy"
47- if reactpy_dir .exists ():
48- rmtree (reactpy_dir )
49-
50- return wrapper
51-
52-
53- @session
54- def test (session : Session ) -> None :
55- session .notify ("test_suite" , posargs = session .posargs )
56- session .notify ("test_style" )
57-
58-
59- @session
60- @build_test_repo ()
61- @install_latest_reactpy
14+ @session (tags = ["test" ])
6215def test_suite (session : Session ) -> None :
16+ build_test_repo (session )
17+ install_latest_reactpy (session )
6318 session .chdir ("test-repo" )
6419 session .run ("playwright" , "install" , "chromium" )
6520 session .run ("pytest" , "tests" , "--import-mode=importlib" , * session .posargs )
6621
6722
68- @session
69- @build_test_repo (install = False )
23+ @session (tags = ["test" ])
7024def test_style (session : Session ) -> None :
25+ build_test_repo (session , install = False )
7126 session .install ("black" , "flake8" )
7227 session .run ("black" , "--check" , "test-repo" , * list (map (str , HERE .glob ("*.py" ))))
7328 session .run ("flake8" , "test-repo" )
7429
7530
76- 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"""
7733 # Need to remove node_modules so cookiecutter doesn't think since the cookiecutter
7834 # will try to format those files if present
7935 for path in TEMPLATE_DIR .rglob ("node_modules" ):
@@ -94,3 +50,15 @@ def _build_test_repo(session: Session, install: bool) -> None:
9450 session .install ("." )
9551 session .install ("-r" , "requirements.txt" )
9652 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