MCPcopy
hub / github.com/reflex-dev/reflex / create

Method create

reflex/testing.py:124–170  ·  view source on GitHub ↗

Create an AppHarness instance at root. Args: root: the directory that will contain the app under test. app_source: if specified, the source code from this function or module is used as the main module for the app. It may also be the raw source code te

(
        cls,
        root: Path,
        app_source: (
            Callable[[], None] | types.ModuleType | str | functools.partial[Any] | None
        ) = None,
        app_name: str | None = None,
    )

Source from the content-addressed store, hash-verified

122
123 @classmethod
124 def create(
125 cls,
126 root: Path,
127 app_source: (
128 Callable[[], None] | types.ModuleType | str | functools.partial[Any] | None
129 ) = None,
130 app_name: str | None = None,
131 ) -> Self:
132 """Create an AppHarness instance at root.
133
134 Args:
135 root: the directory that will contain the app under test.
136 app_source: if specified, the source code from this function or module is used
137 as the main module for the app. It may also be the raw source code text, as a str.
138 If unspecified, then root must already contain a working reflex app and will be used directly.
139 app_name: provide the name of the app, otherwise will be derived from app_source or root.
140
141 Returns:
142 AppHarness instance
143
144 Raises:
145 ValueError: when app_source is a string and app_name is not provided.
146 """
147 if app_name is None:
148 if app_source is None:
149 app_name = root.name
150 elif isinstance(app_source, functools.partial):
151 keywords = app_source.keywords
152 slug_suffix = "_".join([str(v) for v in keywords.values()])
153 func_name = app_source.func.__name__
154 app_name = f"{func_name}_{slug_suffix}"
155 app_name = re.sub(r"[^a-zA-Z0-9_]", "_", app_name)
156 elif isinstance(app_source, str):
157 msg = "app_name must be provided when app_source is a string."
158 raise ValueError(msg)
159 else:
160 app_name = app_source.__name__
161
162 app_name = app_name.lower()
163 while "__" in app_name:
164 app_name = app_name.replace("__", "_")
165 return cls(
166 app_name=app_name,
167 app_source=app_source,
168 app_path=root,
169 app_module_path=root / app_name / f"{app_name}.py",
170 )
171
172 def get_state_name(self, state_cls_name: str) -> str:
173 """Get the state name for the given state class name.

Callers 6

default_error_boundaryFunction · 0.45
_setup_stateMethod · 0.45
__init__Method · 0.45

Calls 4

valuesMethod · 0.80
lowerMethod · 0.80
replaceMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected