@@ -167,7 +167,7 @@ def test_convert_invalid_file(tmp_path: Path) -> None:
167167 text = True ,
168168 )
169169 assert p .returncode != 0
170- assert "File must be an .ipynb or .md file" in p .stderr
170+ assert "File must be an .ipynb, .md, or .py file" in p .stderr
171171
172172 @staticmethod
173173 def test_convert_remote_ipynb (http_server : MockHTTPServer ) -> None :
@@ -255,7 +255,7 @@ def test_convert_remote_invalid_file(http_server: MockHTTPServer) -> None:
255255 text = True ,
256256 )
257257 assert p .returncode != 0
258- assert "File must be an .ipynb or .md file" in p .stderr
258+ assert "File must be an .ipynb, .md, or .py file" in p .stderr
259259
260260 @staticmethod
261261 def test_convert_nonexistent_remote_file (
@@ -274,3 +274,82 @@ def test_convert_nonexistent_remote_file(
274274 assert p .returncode != 0
275275 # The error message will be from urllib.error.HTTPError
276276 assert "HTTP Error 404" in p .stderr or "Not Found" in p .stderr
277+
278+ @staticmethod
279+ def test_convert_existing_marimo_notebook (tmp_path : Path ) -> None :
280+ """Test that converting an existing marimo notebook prints a message."""
281+ marimo_path = tmp_path / "existing_marimo.py"
282+ marimo_content = """import marimo
283+
284+ __generated_with = "0.10.0"
285+ app = marimo.App()
286+
287+
288+ @app.cell
289+ def __():
290+ print("Hello from marimo!")
291+ return
292+
293+
294+ if __name__ == "__main__":
295+ app.run()
296+ """
297+ marimo_path .write_text (marimo_content )
298+
299+ p = subprocess .run (
300+ ["marimo" , "convert" , str (marimo_path )],
301+ capture_output = True ,
302+ text = True ,
303+ )
304+ assert p .returncode == 0
305+ assert "File is already a valid marimo notebook." in p .stdout
306+
307+ @staticmethod
308+ def test_convert_unknown_python_script (tmp_path : Path ) -> None :
309+ """Test converting an unknown Python script."""
310+ script_path = tmp_path / "script.py"
311+ script_content = '''"""A simple Python script."""
312+
313+ import sys
314+
315+ def main():
316+ print("Hello, World!")
317+
318+ if __name__ == "__main__":
319+ main()
320+ sys.exit(0)
321+ '''
322+ script_path .write_text (script_content )
323+
324+ p = subprocess .run (
325+ ["marimo" , "convert" , str (script_path )],
326+ capture_output = True ,
327+ text = True ,
328+ )
329+ assert p .returncode == 0 , p .stderr
330+ output = p .stdout
331+ output = re .sub (r"__generated_with = .*" , "" , output )
332+ snapshot ("python_script_to_marimo.txt" , output )
333+
334+ @staticmethod
335+ def test_convert_python_script_no_main (tmp_path : Path ) -> None :
336+ """Test converting a Python script without main block."""
337+ script_path = tmp_path / "simple_script.py"
338+ script_content = '''"""Simple calculation script."""
339+
340+ x = 5
341+ y = 10
342+ result = x + y
343+ print(f"Result: {result}")
344+ '''
345+ script_path .write_text (script_content )
346+
347+ p = subprocess .run (
348+ ["marimo" , "convert" , str (script_path )],
349+ capture_output = True ,
350+ text = True ,
351+ )
352+ assert p .returncode == 0 , p .stderr
353+ output = p .stdout
354+ output = re .sub (r"__generated_with = .*" , "" , output )
355+ snapshot ("python_script_no_main_to_marimo.txt" , output )
0 commit comments