Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: windows csv test (#2650)

Myles Scolnick84ee889742c5
diff --git a/marimo/_output/utils.py b/marimo/_output/utils.py
index fa2a520e8a..65f7976ab5 100644
--- a/marimo/_output/utils.py
+++ b/marimo/_output/utils.py
@@ -8,6 +8,7 @@ from marimo._messaging.mimetypes import KnownMimeType
def build_data_url(mimetype: KnownMimeType, data: bytes) -> str:
+ assert mimetype is not None
# `data` must be base64 encoded
str_repr = data.decode("utf-8").replace("\n", "")
return f"data:{mimetype};base64,{str_repr}"
diff --git a/marimo/_runtime/virtual_file.py b/marimo/_runtime/virtual_file.py
index d27eefd01a..e13d5afe55 100644
--- a/marimo/_runtime/virtual_file.py
+++ b/marimo/_runtime/virtual_file.py
@@ -68,11 +68,9 @@ class VirtualFile:
if not as_data_url:
self.url = url or f"./@file/{len(buffer)}-{filename}"
else:
+ mimetype = mimetypes.guess_type(self.filename)[0] or "text/plain"
self.url = url or build_data_url(
- mimetype=cast(
- KnownMimeType,
- mimetypes.guess_type(self.filename)[0],
- ),
+ mimetype=cast(KnownMimeType, mimetype),
data=base64.b64encode(buffer),
)
diff --git a/tests/_plugins/ui/_impl/charts/test_altair_transformers.py b/tests/_plugins/ui/_impl/charts/test_altair_transformers.py
index 694e38460a..722bd21231 100644
--- a/tests/_plugins/ui/_impl/charts/test_altair_transformers.py
+++ b/tests/_plugins/ui/_impl/charts/test_altair_transformers.py
@@ -152,8 +152,13 @@ def test_to_marimo_inline_csv_large_dataset(df: IntoDataFrame):
# Verify the content of the inline CSV
base64_data = result["url"].split(",")[1]
decoded_data = base64.b64decode(base64_data).decode("utf-8")
- assert decoded_data.startswith("A,B\n0,value_0\n1,value_1\n")
- assert decoded_data.endswith("9998,value_9998\n9999,value_9999\n")
+ assert decoded_data.startswith("A,B")
+ assert (
+ decoded_data.endswith("9999,value_9999\n")
+ or
+ # for windows
+ decoded_data.endswith("9999,value_9999\r\n")
+ )
@pytest.mark.skipif(not HAS_DEPS, reason="optional dependencies not installed")