Skip to content

Commit a115723

Browse files
committed
Use tmp_path not __file__ for valid file.
1 parent 0adba8f commit a115723

1 file changed

Lines changed: 36 additions & 25 deletions

File tree

src/py/tests/test_page_generator.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,35 @@ def nonexistent_file_path():
135135
),
136136
).map(lambda x: f"http{x[0]}://example.com/{x[1]}.js")
137137

138-
_valid_file_string = str(Path(__file__).resolve())
139138

140-
_h_file_str = st.just(_valid_file_string)
141-
_h_file_path = st.just(Path(_valid_file_string))
142-
_h_file_uri = st.just(Path(_valid_file_string).as_uri())
139+
def st_valid_path(dir_path: Path):
140+
file_path = dir_path / "foo.foo"
141+
file_path.touch()
142+
_valid_file_string = str(file_path.resolve())
143143

144-
_h_uri = st.one_of(_h_url, _h_file_str, _h_file_path, _h_file_uri)
144+
_h_file_str = st.just(_valid_file_string)
145+
_h_file_path = st.just(Path(_valid_file_string))
146+
_h_file_uri = st.just(Path(_valid_file_string).as_uri())
145147

146-
_h_encoding = st.sampled_from(["utf-8", "utf-16", "ascii", "latin1"])
148+
_h_uri = st.one_of(_h_url, _h_file_str, _h_file_path, _h_file_uri)
149+
150+
_h_encoding = st.sampled_from(["utf-8", "utf-16", "ascii", "latin1"])
151+
152+
return st.one_of(_h_uri, st.tuples(_h_uri, _h_encoding))
147153

148-
strategy_valid_path = st.one_of(_h_uri, st.tuples(_h_uri, _h_encoding))
149154

150155
# Variable length list strategy for 'others' parameter
151-
strategy_others_list = st.lists(strategy_valid_path, min_size=0, max_size=3)
156+
def st_others_list(dir_path: Path):
157+
return st.lists(st_valid_path(dir_path), min_size=0, max_size=3)
158+
152159

153160
# Mathjax strategy (includes None, False, True, and path options)
154-
strategy_mathjax = st.one_of(
155-
st.none(),
156-
st.just(False), # noqa: FBT003
157-
strategy_valid_path,
158-
)
161+
def st_mathjax(dir_path: Path):
162+
return st.one_of(
163+
st.none(),
164+
st.just(False), # noqa: FBT003
165+
st_valid_path(dir_path),
166+
)
159167

160168

161169
# Test default combinations
@@ -228,9 +236,10 @@ async def test_mathjax_false():
228236

229237

230238
# Test user overrides
231-
@given(strategy_valid_path) # claude, change all further functions to this style
232-
async def test_custom_plotly_url(custom_plotly):
239+
@given(st.data()) # claude, change all further functions to this style
240+
async def test_custom_plotly_url(tmp_path, data):
233241
"""Test custom plotly URL override."""
242+
custom_plotly = data.draw(st_valid_path(tmp_path))
234243
with_custom = PageGenerator(plotly=custom_plotly).generate_index()
235244
scripts, encodings = get_scripts_from_html(with_custom)
236245

@@ -244,9 +253,10 @@ async def test_custom_plotly_url(custom_plotly):
244253
assert scripts[2].endswith("kaleido_scopes.js")
245254

246255

247-
@given(strategy_valid_path)
248-
async def test_custom_mathjax_url(custom_mathjax):
256+
@given(st.data())
257+
async def test_custom_mathjax_url(tmp_path, data):
249258
"""Test custom mathjax URL override."""
259+
custom_mathjax = data.draw(st_valid_path(tmp_path))
250260
with_custom = PageGenerator(mathjax=custom_mathjax).generate_index()
251261
scripts, encodings = get_scripts_from_html(with_custom)
252262

@@ -260,9 +270,10 @@ async def test_custom_mathjax_url(custom_mathjax):
260270
assert scripts[2].endswith("kaleido_scopes.js")
261271

262272

263-
@given(strategy_others_list)
264-
async def test_other_scripts(other_scripts):
273+
@given(st.data())
274+
async def test_other_scripts(tmp_path, data):
265275
"""Test adding other scripts."""
276+
other_scripts = data.draw(st_others_list(tmp_path))
266277
with_others = PageGenerator(others=other_scripts).generate_index()
267278
scripts, encodings = get_scripts_from_html(with_others)
268279

@@ -283,13 +294,13 @@ async def test_other_scripts(other_scripts):
283294
assert scripts[-1].endswith("kaleido_scopes.js")
284295

285296

286-
@given(
287-
custom_plotly=strategy_valid_path,
288-
custom_mathjax=strategy_mathjax,
289-
other_scripts=strategy_others_list,
290-
)
291-
async def test_combined_overrides(custom_plotly, custom_mathjax, other_scripts):
297+
@given(st.data())
298+
async def test_combined_overrides(tmp_path, data):
292299
"""Test combination of multiple overrides."""
300+
custom_plotly = data.draw(st_valid_path(tmp_path))
301+
custom_mathjax = data.draw(st_mathjax(tmp_path))
302+
other_scripts = data.draw(st_others_list(tmp_path))
303+
293304
combined = PageGenerator(
294305
plotly=custom_plotly,
295306
mathjax=custom_mathjax,

0 commit comments

Comments
 (0)