Skip to content

Commit e9d08dd

Browse files
committed
fix tests
1 parent 47a61e6 commit e9d08dd

6 files changed

Lines changed: 42 additions & 12 deletions

File tree

reflex/app.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,12 @@ def __call__(self) -> FastAPI:
602602
compile_future = concurrent.futures.ThreadPoolExecutor(max_workers=1).submit(
603603
self._compile
604604
)
605-
compile_future.add_done_callback(
605+
606+
def callback(f: concurrent.futures.Future):
606607
# Force background compile errors to print eagerly
607-
lambda f: f.result()
608-
)
608+
return f.result()
609+
610+
compile_future.add_done_callback(callback)
609611
# Wait for the compile to finish in prod mode to ensure all optional endpoints are mounted.
610612
if is_prod_mode():
611613
compile_future.result()
@@ -1329,10 +1331,12 @@ def memoized_toast_provider():
13291331
ExecutorSafeFunctions.STATE = self._state
13301332

13311333
with console.timing("Compile to Javascript"), executor as executor:
1332-
result_futures: list[concurrent.futures.Future[tuple[str, str]]] = []
1334+
result_futures: list[concurrent.futures.Future[tuple[str, str] | None]] = []
13331335

13341336
def _submit_work(
1335-
fn: Callable[P, tuple[str, str]], *args: P.args, **kwargs: P.kwargs
1337+
fn: Callable[P, tuple[str, str] | None],
1338+
*args: P.args,
1339+
**kwargs: P.kwargs,
13361340
):
13371341
f = executor.submit(fn, *args, **kwargs)
13381342
f.add_done_callback(lambda _: progress.advance(task))
@@ -1356,8 +1360,9 @@ def _submit_work(
13561360

13571361
# Wait for all compilation tasks to complete.
13581362
compile_results.extend(
1359-
future.result()
1363+
result
13601364
for future in concurrent.futures.as_completed(result_futures)
1365+
if (result := future.result()) is not None
13611366
)
13621367

13631368
app_root = self._app_root(app_wrappers=app_wrappers)

reflex/plugins/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ class AddTaskProtcol(Protocol):
1818
"""Protocol for adding a task to the pre-compile context."""
1919

2020
def __call__(
21-
self, task: Callable[P, tuple[str, str]], /, *args: P.args, **kwargs: P.kwargs
21+
self,
22+
task: Callable[P, tuple[str, str] | None],
23+
/,
24+
*args: P.args,
25+
**kwargs: P.kwargs,
2226
) -> None:
2327
"""Add a task to the pre-compile context.
2428

reflex/plugins/tailwind_v3.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ def add_tailwind_to_postcss_config():
153153

154154
postcss_file = get_web_dir() / Dirs.POSTCSS_JS
155155
if not postcss_file.exists():
156-
raise ValueError(
156+
print( # noqa: T201
157157
f"Could not find {Dirs.POSTCSS_JS}. "
158158
"Please make sure the file exists and is valid."
159159
)
160+
return
160161

161162
postcss_file_lines = postcss_file.read_text().splitlines()
162163

@@ -169,10 +170,11 @@ def add_tailwind_to_postcss_config():
169170
None,
170171
)
171172
if not line_with_postcss_plugins:
172-
raise ValueError(
173+
print( # noqa: T201
173174
f"Could not find line with 'plugins' in {Dirs.POSTCSS_JS}. "
174175
"Please make sure the file exists and is valid."
175176
)
177+
return
176178

177179
postcss_file_lines.insert(line_with_postcss_plugins + 1, "tailwindcss: {},")
178180

@@ -185,6 +187,9 @@ class TailwindV3Plugin(Plugin):
185187
def get_frontend_development_dependancies(self, **context) -> list[str]:
186188
"""Get the packages required by the plugin.
187189
190+
Args:
191+
**context: The context for the plugin.
192+
188193
Returns:
189194
A list of packages required by the plugin.
190195
"""

reflex/utils/prerequisites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def install_frontend_packages(packages: set[str], config: Config):
13341334
)
13351335

13361336
# Install custom packages defined in frontend_packages
1337-
if len(packages) > 0:
1337+
if packages:
13381338
run_package_manager(
13391339
[primary_package_manager, "add", "--legacy-peer-deps", *packages],
13401340
show_status_message="Installing frontend packages from config and components",

tests/units/compiler/test_compiler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def test_compile_stylesheets(tmp_path: Path, mocker):
155155
/ (PageNames.STYLESHEET_ROOT + ".css")
156156
),
157157
"@import url('./tailwind.css'); \n"
158+
"@import url('@radix-ui/themes/styles.css'); \n"
158159
"@import url('https://fonts.googleapis.com/css?family=Sofia&effect=neon|outline|emboss|shadow-multiple'); \n"
159160
"@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css'); \n"
160161
"@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css'); \n"
@@ -215,6 +216,7 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker):
215216
/ (PageNames.STYLESHEET_ROOT + ".css")
216217
),
217218
"@import url('./tailwind.css'); \n"
219+
"@import url('@radix-ui/themes/styles.css'); \n"
218220
"@import url('./style.css'); \n"
219221
f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}'); \n"
220222
f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}'); \n",
@@ -233,6 +235,7 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker):
233235
/ (PageNames.STYLESHEET_ROOT + ".css")
234236
),
235237
"@import url('./tailwind.css'); \n"
238+
"@import url('@radix-ui/themes/styles.css'); \n"
236239
"@import url('./style.css'); \n"
237240
f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}'); \n"
238241
f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}'); \n",
@@ -266,6 +269,7 @@ def test_compile_stylesheets_exclude_tailwind(tmp_path, mocker):
266269
mock = mocker.Mock()
267270

268271
mocker.patch.object(mock, "tailwind", None)
272+
mocker.patch.object(mock, "plugins", [])
269273
mocker.patch("reflex.compiler.compiler.get_config", return_value=mock)
270274

271275
(assets_dir / "style.css").touch()
@@ -277,7 +281,7 @@ def test_compile_stylesheets_exclude_tailwind(tmp_path, mocker):
277281

278282
assert compiler.compile_root_stylesheet(stylesheets) == (
279283
str(Path(".web") / "styles" / (PageNames.STYLESHEET_ROOT + ".css")),
280-
"@import url('./style.css'); \n",
284+
"@import url('@radix-ui/themes/styles.css'); \n@import url('./style.css'); \n",
281285
)
282286

283287

tests/units/test_app.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,17 @@ def compilable_app(tmp_path) -> Generator[tuple[App, Path], None, None]:
12901290
web_dir = app_path / ".web"
12911291
web_dir.mkdir(parents=True)
12921292
(web_dir / constants.PackageJson.PATH).touch()
1293+
(web_dir / constants.Dirs.POSTCSS_JS).touch()
1294+
(web_dir / constants.Dirs.POSTCSS_JS).write_text(
1295+
"""
1296+
module.exports = {
1297+
plugins: {
1298+
"postcss-import": {},
1299+
autoprefixer: {},
1300+
},
1301+
};
1302+
""",
1303+
)
12931304
app = App(theme=None)
12941305
app._get_frontend_packages = unittest.mock.Mock()
12951306
with chdir(app_path):
@@ -1312,8 +1323,8 @@ def test_app_wrap_compile_theme(
13121323
"""
13131324
conf = rx.Config(app_name="testing", react_strict_mode=react_strict_mode)
13141325
mocker.patch("reflex.config._get_config", return_value=conf)
1315-
13161326
app, web_dir = compilable_app
1327+
mocker.patch("reflex.utils.prerequisites.get_web_dir", return_value=web_dir)
13171328
app.theme = rx.theme(accent_color="plum")
13181329
app._compile()
13191330
app_js_contents = (web_dir / "pages" / "_app.js").read_text()
@@ -1461,6 +1472,7 @@ def test_raise_on_state():
14611472
def test_call_app():
14621473
"""Test that the app can be called."""
14631474
app = App()
1475+
app._get_frontend_packages = unittest.mock.Mock()
14641476
api = app()
14651477
assert isinstance(api, FastAPI)
14661478

0 commit comments

Comments
 (0)