Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions tests/_lint/test_generated_with_comparison.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright 2025 Marimo. All rights reserved.

from marimo._lint.linter import _contents_differ_excluding_generated_with


def test_contents_differ_excluding_generated_with():
"""Test that __generated_with differences are ignored in content comparison."""

# Test case 1: Only __generated_with differs
original = """import marimo

__generated_with = "0.8.0"
app = marimo.App()

@app.cell
def test():
return

if __name__ == "__main__":
app.run()
"""

generated = """import marimo

__generated_with = "0.9.0"
app = marimo.App()

@app.cell
def test():
return

if __name__ == "__main__":
app.run()
"""

# Should return False (no meaningful differences)
assert not _contents_differ_excluding_generated_with(original, generated)


def test_contents_differ_with_real_changes():
"""Test that real code differences are detected."""

original = """import marimo

__generated_with = "0.8.0"
app = marimo.App()

@app.cell
def test():
x = 1
return

if __name__ == "__main__":
app.run()
"""

generated = """import marimo

__generated_with = "0.9.0"
app = marimo.App()

@app.cell
def test():
x = 2 # Changed value
return

if __name__ == "__main__":
app.run()
"""

# Should return True (real differences exist)
assert _contents_differ_excluding_generated_with(original, generated)


def test_contents_no_generated_with():
"""Test comparison when no __generated_with line exists."""

original = """import marimo

app = marimo.App()

@app.cell
def test():
return
"""

generated = """import marimo

app = marimo.App()

@app.cell
def test():
return
"""

# Should return False (identical content)
assert not _contents_differ_excluding_generated_with(original, generated)


def test_contents_mixed_generated_with():
"""Test when only one file has __generated_with."""

original = """import marimo

app = marimo.App()

@app.cell
def test():
return
"""

generated = """import marimo

__generated_with = "0.9.0"
app = marimo.App()

@app.cell
def test():
return
"""

# Should return True (one has __generated_with, one doesn't)
assert _contents_differ_excluding_generated_with(original, generated)
64 changes: 64 additions & 0 deletions tests/_lint/test_ignore_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2025 Marimo. All rights reserved.

from marimo._lint import run_check


def test_ignore_scripts_flag(tmp_path):
"""Test that --ignore-scripts suppresses errors for non-marimo files."""

# Create a temporary non-marimo Python file
temp_file = tmp_path / "test_script.py"
temp_file.write_text("""#!/usr/bin/env python3

# This is a regular Python script, not a marimo notebook
import os
import sys

def main():
print("Hello, world!")
return 0

if __name__ == "__main__":
sys.exit(main())
""")

# Test without ignore_scripts flag - should error
linter_with_error = run_check((str(temp_file),), ignore_scripts=False)
assert linter_with_error.errored is True
assert len(linter_with_error.files) == 1
assert linter_with_error.files[0].failed is True
assert "not a valid notebook" in linter_with_error.files[0].message

# Test with ignore_scripts flag - should not error
linter_ignore = run_check((str(temp_file),), ignore_scripts=True)
assert linter_ignore.errored is False
assert len(linter_ignore.files) == 1
assert linter_ignore.files[0].skipped is True
assert "not a marimo notebook" in linter_ignore.files[0].message


def test_ignore_scripts_still_processes_marimo_files(tmp_path):
"""Test that --ignore-scripts still processes valid marimo files."""

# Create a temporary marimo file
temp_file = tmp_path / "test_notebook.py"
temp_file.write_text("""import marimo

__generated_with = "0.15.5"
app = marimo.App()

@app.cell
def _():
import marimo as mo
return (mo,)

if __name__ == "__main__":
app.run()
""")

# Test with ignore_scripts flag - should still process marimo files
linter = run_check((str(temp_file),), ignore_scripts=True)
assert linter.errored is False
assert len(linter.files) == 1
assert linter.files[0].failed is False
assert linter.files[0].skipped is False
Loading