Skip to content

Commit

Permalink
improve auto-generated AppHarness app_name with partials (#3088)
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-bartscher authored Apr 16, 2024
1 parent a84bc1e commit 9b7e5f4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions reflex/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,21 @@ def create(
"""
if app_name is None:
if app_source is None:
app_name = root.name.lower()
app_name = root.name
elif isinstance(app_source, functools.partial):
app_name = app_source.func.__name__.lower()
keywords = app_source.keywords
slug_suffix = "_".join([str(v) for v in keywords.values()])
func_name = app_source.func.__name__
app_name = f"{func_name}_{slug_suffix}"
app_name = re.sub(r"[^a-zA-Z0-9_]", "_", app_name)
elif isinstance(app_source, str):
raise ValueError(
"app_name must be provided when app_source is a string."
)
else:
app_name = app_source.__name__.lower()
app_name = app_source.__name__

app_name = app_name.lower()
return cls(
app_name=app_name,
app_source=app_source,
Expand Down

0 comments on commit 9b7e5f4

Please sign in to comment.