@@ -309,22 +309,41 @@ def test_grdecl_rle(tmp_path, testdata_path):
309309 testdata_path / TESTFILE13B , name = "SATNUM" , grid = gg
310310 )
311311
312+ def _section_tokens (tokens , keyword ):
313+ try :
314+ start = tokens .index (keyword ) + 1
315+ end = tokens .index ("/" , start )
316+ except ValueError as exc :
317+ pytest .fail (f"{ keyword } section missing or unterminated: { exc } " )
318+ return tokens [start :end ]
319+
312320 gg .to_file (tmp_path / "grid_rle.grdecl" , fformat = "grdecl" , rle = True )
313321 po .to_file (tmp_path / "grid_satnum_rle.grdecl" , fformat = "grdecl" , rle = True )
314322
315- # Ensure compression in grid (ACTNUM)
323+ # Ensure compression in grid (ZCORN and ACTNUM)
316324 with open (tmp_path / "grid_rle.grdecl" ) as f :
317- fields = f .read ().split ()
318- assert len (fields ) == 289 , "Incorrect field length, fail in compression"
319- assert "*" in fields [- 10 ]
320- assert "*" in fields [- 8 ]
321- assert "*" in fields [- 6 ]
325+ tokens = f .read ().split ()
326+ assert len (tokens ) == 171 , "Expected 171 fields with compression enabled"
327+
328+ zcorn_tokens = _section_tokens (tokens , "ZCORN" )
329+ actnum_tokens = _section_tokens (tokens , "ACTNUM" )
330+
331+ assert any ("*" in token for token in zcorn_tokens ), (
332+ "expected compression marker in ZCORN section"
333+ )
334+ assert any ("*" in token for token in actnum_tokens ), (
335+ "expected compression marker in ACTNUM section"
336+ )
322337
323338 # Ensure compression in grid property (SATNUM)
324339 with open (tmp_path / "grid_satnum_rle.grdecl" ) as f :
325- content = f .read ()
326- assert "*" in content
327- assert len (content .split ()) == 3 , "Incorrect field length, fail in compression"
340+ tokens = f .read ().split ()
341+ satnum_tokens = _section_tokens (tokens , "SATNUM" )
342+
343+ assert len (tokens ) == 3 , "Expected 3 fields with compression enabled"
344+ assert any ("*" in token for token in satnum_tokens ), (
345+ "expected compression marker in SATNUM section"
346+ )
328347
329348 grid = xtgeo .grid_from_file (tmp_path / "grid_rle.grdecl" )
330349 assert np .array_equal (grid .actnum_array , gg .actnum_array )
0 commit comments