Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 7, 2025
1 parent ba12086 commit 45f1439
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions tests/_server/test_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_utf8() -> None:
# Test with UTF8 supported
with patch("marimo._server.print.UTF8_SUPPORTED", True):
assert _utf8("🌊🍃") == "🌊🍃"

# Test with UTF8 not supported
with patch("marimo._server.print.UTF8_SUPPORTED", False):
assert _utf8("🌊🍃") == ""
Expand All @@ -32,11 +32,11 @@ def test_colorized_url() -> None:
# Test with a simple URL
result = _colorized_url("http://localhost:8000")
assert "localhost:8000" in result

# Test with a URL with a path
result = _colorized_url("http://localhost:8000/path")
assert "localhost:8000/path" in result

# Test with a URL with a query string
result = _colorized_url("http://localhost:8000/path?query=value")
assert "localhost:8000/path" in result
Expand All @@ -52,7 +52,7 @@ def test_get_network_url() -> None:
mock_gethostbyname.return_value = "192.168.1.100"
result = _get_network_url("http://localhost:8000")
assert result == "http://192.168.1.100:8000"

# Test with socket.gethostbyname raising an exception
with patch("socket.gethostname") as mock_gethostname:
mock_gethostname.return_value = "test-host"
Expand All @@ -77,7 +77,7 @@ def test_print_startup() -> None:
assert "Edit test.py in your browser" in output
assert "URL" in output
assert "localhost:8000" in output

# Test with file_name and run
with io.StringIO() as buf, redirect_stdout(buf):
print_startup(
Expand All @@ -91,7 +91,7 @@ def test_print_startup() -> None:
assert "Running test.py" in output
assert "URL" in output
assert "localhost:8000" in output

# Test with new=True
with io.StringIO() as buf, redirect_stdout(buf):
print_startup(
Expand All @@ -105,7 +105,7 @@ def test_print_startup() -> None:
assert "Create a new notebook" in output
assert "URL" in output
assert "localhost:8000" in output

# Test with file_name=None and new=False
with io.StringIO() as buf, redirect_stdout(buf):
print_startup(
Expand All @@ -119,10 +119,12 @@ def test_print_startup() -> None:
assert "Create or edit notebooks" in output
assert "URL" in output
assert "localhost:8000" in output

# Test with network=True
with io.StringIO() as buf, redirect_stdout(buf):
with patch("marimo._server.print._get_network_url") as mock_get_network_url:
with patch(
"marimo._server.print._get_network_url"
) as mock_get_network_url:
mock_get_network_url.return_value = "http://192.168.1.100:8000"
print_startup(
file_name=None,
Expand All @@ -137,11 +139,15 @@ def test_print_startup() -> None:
assert "localhost:8000" in output
assert "Network" in output
assert "192.168.1.100:8000" in output
mock_get_network_url.assert_called_once_with("http://localhost:8000")

mock_get_network_url.assert_called_once_with(
"http://localhost:8000"
)

# Test with network=True and _get_network_url raising an exception
with io.StringIO() as buf, redirect_stdout(buf):
with patch("marimo._server.print._get_network_url") as mock_get_network_url:
with patch(
"marimo._server.print._get_network_url"
) as mock_get_network_url:
mock_get_network_url.side_effect = Exception("Test exception")
print_startup(
file_name=None,
Expand All @@ -155,7 +161,9 @@ def test_print_startup() -> None:
assert "URL" in output
assert "localhost:8000" in output
assert "Network" not in output
mock_get_network_url.assert_called_once_with("http://localhost:8000")
mock_get_network_url.assert_called_once_with(
"http://localhost:8000"
)


def test_print_shutdown() -> None:
Expand All @@ -174,7 +182,7 @@ def test_print_experimental_features() -> None:
print_experimental_features(config)
output = buf.getvalue()
assert output == ""

# Test with experimental features that have been released
with io.StringIO() as buf, redirect_stdout(buf):
config = merge_default_config(
Expand All @@ -183,12 +191,10 @@ def test_print_experimental_features() -> None:
print_experimental_features(config)
output = buf.getvalue()
assert output == ""

# Test with experimental features that have not been released
with io.StringIO() as buf, redirect_stdout(buf):
config = merge_default_config(
{"experimental": {"new_feature": True}}
)
config = merge_default_config({"experimental": {"new_feature": True}})
print_experimental_features(config)
output = buf.getvalue()
assert "Experimental features" in output
Expand Down

0 comments on commit 45f1439

Please sign in to comment.