33See also test_cellbudgetfile.py for similar tests.
44"""
55
6+ import warnings
67from itertools import repeat
78
89import numpy as np
@@ -104,6 +105,8 @@ def test_headfile_build_index(example_data_path):
104105 assert hds .ncol == 20
105106 assert hds .nlay == 3
106107 assert not hasattr (hds , "nper" )
108+ assert hds .text == "head"
109+ assert hds .text_bytes == b"HEAD" .rjust (16 )
107110 assert hds .totalbytes == 10_676_004
108111 assert len (hds .recordarray ) == 3291
109112 assert type (hds .recordarray ) == np .ndarray
@@ -150,7 +153,80 @@ def test_headfile_build_index(example_data_path):
150153 )
151154
152155
153- def test_concentration_build_index (example_data_path ):
156+ @pytest .mark .parametrize (
157+ "pth, expected" ,
158+ [
159+ pytest .param (
160+ "mf6-freyberg/freyberg.hds" ,
161+ {
162+ "precision" : "double" ,
163+ "nlay, nrow, ncol" : (1 , 40 , 20 ),
164+ "text" : "head" ,
165+ "text_bytes" : b"HEAD" .ljust (16 ),
166+ "len(obj)" : 1 ,
167+ },
168+ id = "freyberg.hds" ,
169+ ),
170+ pytest .param (
171+ "mf6/create_tests/test_transport/expected_output/gwt_mst03.ucn" ,
172+ {
173+ "precision" : "double" ,
174+ "nlay, nrow, ncol" : (1 , 1 , 1 ),
175+ "text" : "concentration" ,
176+ "text_bytes" : b"CONCENTRATION" .ljust (16 ),
177+ "len(obj)" : 28 ,
178+ },
179+ id = "gwt_mst03.ucn" ,
180+ ),
181+ pytest .param (
182+ "mfusg_test/03A_conduit_unconfined/output/ex3A.cln.hds" ,
183+ {
184+ "precision" : "single" ,
185+ "nlay, nrow, ncol" : (1 , 1 , 2 ),
186+ "text" : "cln_heads" ,
187+ "text_bytes" : b"CLN HEADS" .rjust (16 ),
188+ "len(obj)" : 1 ,
189+ },
190+ id = "ex3A.cln.hds" ,
191+ ),
192+ pytest .param (
193+ "mfusg_test/03A_conduit_unconfined/output/ex3A.ddn" ,
194+ {
195+ "precision" : "single" ,
196+ "nlay, nrow, ncol" : (2 , 100 , 100 ),
197+ "text" : "drawdown" ,
198+ "text_bytes" : b"DRAWDOWN" .rjust (16 ),
199+ "len(obj)" : 2 ,
200+ },
201+ id = "ex3A.ddn" ,
202+ ),
203+ ],
204+ )
205+ def test_headfile_examples (example_data_path , pth , expected ):
206+ with HeadFile (example_data_path / pth ) as obj :
207+ assert obj .precision == expected ["precision" ]
208+ assert (obj .nlay , obj .nrow , obj .ncol ) == expected ["nlay, nrow, ncol" ]
209+ assert obj .text == expected ["text" ]
210+ assert obj .text_bytes == expected ["text_bytes" ]
211+ assert len (obj ) == expected ["len(obj)" ]
212+
213+
214+ @pytest .mark .parametrize (
215+ "pth" ,
216+ [
217+ "mt3d_test/mf96mt3d/P01/case1b/MT3D001.UCN" ,
218+ "unstructured/headu.githds" ,
219+ ],
220+ )
221+ def test_not_headfile (example_data_path , pth ):
222+ # These examples pass get_headfile_precision, but are not HeadFiles
223+ with pytest .raises (ValueError , match = "cannot read file with HeadFile" ):
224+ with warnings .catch_warnings ():
225+ warnings .simplefilter ("ignore" )
226+ HeadFile (example_data_path / pth )
227+
228+
229+ def test_ucnfile_build_index (example_data_path ):
154230 # test low-level BinaryLayerFile._build_index() method with UCN file
155231 pth = example_data_path / "mt3d_test/mf2005mt3d/P07/MT3D001.UCN"
156232 with UcnFile (pth ) as ucn :
@@ -159,6 +235,8 @@ def test_concentration_build_index(example_data_path):
159235 assert ucn .ncol == 21
160236 assert ucn .nlay == 8
161237 assert not hasattr (ucn , "nper" )
238+ assert ucn .text == "concentration"
239+ assert ucn .text_bytes == b"CONCENTRATION" .ljust (16 )
162240 assert ucn .totalbytes == 10_432
163241 assert len (ucn .recordarray ) == 8
164242 assert type (ucn .recordarray ) == np .ndarray
@@ -296,6 +374,8 @@ def test_headu_file_data(function_tmpdir, example_data_path):
296374 headobj = HeadUFile (fname )
297375 assert isinstance (headobj , HeadUFile )
298376 assert headobj .nlay == 3
377+ assert headobj .text == "headu"
378+ assert headobj .text_bytes == b"HEADU" .rjust (16 )
299379
300380 # ensure recordarray is has correct data
301381 ra = headobj .recordarray
0 commit comments