@@ -81,10 +81,15 @@ def physical_source_path(self, backend_address, *, base_path):
8181 )
8282
8383
84+ @pytest .mark .parametrize ("backend" , ["disk" , "zarr" , "memory" ])
8485def test_preformatted_text_is_written_as_exact_utf8_bytes (
8586 tmp_path : Path ,
8687 monkeypatch ,
88+ backend : str ,
8789) -> None :
90+ from polystore import MemoryBackend
91+ from polystore .zarr import ZarrStorageBackend
92+
8893 content = "well,count\r \n A01,2\r \n "
8994 output_path = tmp_path / "summary.csv"
9095
@@ -93,9 +98,25 @@ def reject_platform_text_translation(*args, **kwargs):
9398 raise AssertionError ("text persistence must bypass platform newline translation" )
9499
95100 monkeypatch .setattr (Path , "write_text" , reject_platform_text_translation )
96- DiskBackend ().save (content , output_path )
97-
98- assert output_path .read_bytes () == content .encode (disk_module .DISK_TEXT_ENCODING )
101+ manager = FileManager ({
102+ "disk" : DiskBackend (), "zarr" : ZarrStorageBackend (), "memory" : MemoryBackend (),
103+ })
104+ manager .ensure_directory (tmp_path , backend )
105+ manager .save (content , output_path , backend )
106+ assert manager .load_text (output_path , backend ) == content
107+ if backend != "memory" :
108+ assert output_path .read_bytes () == content .encode (disk_module .DISK_TEXT_ENCODING )
109+
110+
111+ def test_text_read_refuses_structured_values (tmp_path ):
112+ from polystore import MemoryBackend
113+
114+ manager = FileManager ({"memory" : MemoryBackend ()})
115+ manager .ensure_directory (tmp_path , "memory" )
116+ path = tmp_path / "values.csv"
117+ manager .save ([{"count" : 2 }], path , "memory" )
118+ with pytest .raises (TypeError , match = "is not text" ):
119+ manager .load_text (path , "memory" )
99120
100121
101122def test_tiff_save_normalizes_external_array_payload (tmp_path , monkeypatch ) -> None :
0 commit comments