|
9 | 9 |
|
10 | 10 | from marimo import _loggers |
11 | 11 | from marimo._ast import load |
| 12 | +from marimo._ast.parse import MarimoFileError |
12 | 13 |
|
13 | 14 | DIR_PATH = os.path.dirname(os.path.realpath(__file__)) |
14 | 15 |
|
@@ -216,6 +217,13 @@ def test_get_codes_app_with_only_comments(load_app) -> None: |
216 | 217 | app = load_app(get_filepath("test_app_with_only_comments")) |
217 | 218 | assert app is None |
218 | 219 |
|
| 220 | + @staticmethod |
| 221 | + def test_get_codes_non_marimo_python_script(static_load) -> None: |
| 222 | + with pytest.raises(MarimoFileError, match="is not a marimo notebook."): |
| 223 | + static_load( |
| 224 | + get_filepath("test_get_codes_non_marimo_python_script") |
| 225 | + ) |
| 226 | + |
219 | 227 | @staticmethod |
220 | 228 | def test_get_codes_app_with_no_cells(load_app) -> None: |
221 | 229 | app = load_app(get_filepath("test_app_with_no_cells")) |
@@ -310,66 +318,3 @@ def test_get_status_warn() -> None: |
310 | 318 | ) |
311 | 319 | == "has_errors" |
312 | 320 | ) |
313 | | - |
314 | | - @staticmethod |
315 | | - def test_non_marimo_file_error(tmp_path) -> None: |
316 | | - """Test loading a marimo Python script raises UnknownPythonScriptError.""" |
317 | | - regular_python = textwrap.dedent( |
318 | | - """ |
319 | | - import numpy as np |
320 | | -
|
321 | | - def main(): |
322 | | - x = np.array([1, 2, 3]) |
323 | | - print(x) |
324 | | -
|
325 | | - if __name__ == "__main__": |
326 | | - main() |
327 | | - """ |
328 | | - ).strip() |
329 | | - |
330 | | - filepath = tmp_path / "regular_script.py" |
331 | | - filepath.write_text(regular_python) |
332 | | - |
333 | | - with pytest.raises( |
334 | | - load.UnknownPythonScriptError, match="is not a marimo notebook" |
335 | | - ): |
336 | | - load.get_notebook_status(str(filepath)) |
337 | | - |
338 | | - @staticmethod |
339 | | - def test_python_script_metadata_and_imports_error(tmp_path) -> None: |
340 | | - """Test loading a file with metadata and imports raises UnknownPythonScriptError.""" |
341 | | - metadata_only = textwrap.dedent( |
342 | | - """ |
343 | | - # /// script |
344 | | - # dependencies = ["numpy", "pandas"] |
345 | | - # requires-python = ">=3.8" |
346 | | - # /// |
347 | | -
|
348 | | - import numpy as np |
349 | | - """ |
350 | | - ).strip() |
351 | | - |
352 | | - filepath = tmp_path / "imports_and_metadata_only.py" |
353 | | - filepath.write_text(metadata_only) |
354 | | - |
355 | | - with pytest.raises( |
356 | | - load.UnknownPythonScriptError, match="is not a marimo notebook" |
357 | | - ): |
358 | | - load.get_notebook_status(str(filepath)) |
359 | | - |
360 | | - @staticmethod |
361 | | - def test_script_metadata_only_file(tmp_path) -> None: |
362 | | - """Test that files with only script metadata are allowed.""" |
363 | | - metadata_only = textwrap.dedent( |
364 | | - """ |
365 | | - # /// script |
366 | | - # dependencies = ["numpy", "pandas"] |
367 | | - # requires-python = ">=3.8" |
368 | | - # /// |
369 | | - """ |
370 | | - ).strip() |
371 | | - |
372 | | - filepath = tmp_path / "metadata_only.py" |
373 | | - filepath.write_text(metadata_only) |
374 | | - |
375 | | - assert load.get_notebook_status(str(filepath)) == "invalid" |
0 commit comments