11from  __future__ import  annotations 
22
33import  os 
4+ import  sys 
45import  tarfile 
56
67import  numpy  as  np 
@@ -60,7 +61,6 @@ def test_read_si2(self):
6061            for  varname , float_ref  in  ref_float_values .items ():
6162                value  =  data .read_value (varname )
6263                assert_allclose (value , float_ref )
63-             # assert 0 
6464
6565            # Reading non-existent variables or dims should raise 
6666            # a subclass of NetcdReaderError 
@@ -83,36 +83,31 @@ def test_read_si2(self):
8383            # xc = data.read_abinit_xcfunc() 
8484            # assert xc == "LDA" 
8585
86-     @pytest .mark .skipif (netCDF4  is  None  or  True , reason = "Requires Netcdf4" ) 
87-     def  test_read_fe (self ):
88-         with  tarfile .open (f"{ TEST_DIR }  , mode = "r:xz" ) as  t :
86+     @pytest .mark .skipif (netCDF4  is  None , reason = "Requires NetCDF4" ) 
87+     @pytest .mark .xfail ( 
88+         sys .platform .startswith ("linux" ) and  os .getenv ("CI" ) and  netCDF4 .__version__  >=  "1.6.5" , 
89+         reason = "Fails with netCDF4 >= 1.6.5 on Ubuntu CI" , 
90+     ) 
91+     @pytest .mark .parametrize ( 
92+         ("tarname" , "expected" ), 
93+         [ 
94+             ("Fe_magmoms_collinear_GSR.tar.xz" , [- 0.5069359730980665 ]), 
95+             ("Fe_magmoms_noncollinear_GSR.tar.xz" , [[0.357939487 , 0.357939487 , 0 ]]), 
96+         ], 
97+     ) 
98+     def  test_read_fe (self , tarname , expected ):
99+         with  tarfile .open (os .path .join (TEST_DIR , tarname ), mode = "r:xz" ) as  t :
89100            # TODO: remove attr check after only 3.12+ 
90101            if  hasattr (tarfile , "data_filter" ):
91102                t .extractall ("." , filter = "data" )
92103            else :
93104                t .extractall ("." )  # noqa: S202 
94105
95-             ref_magmom_collinear  =  [- 0.5069359730980665 ]
96-             path  =  os .path .join ("." , "Fe_magmoms_collinear_GSR.nc" )
97- 
98-             # TODO: PR4128, EtsfReader would fail in Ubuntu CI with netCDF4 > 1.6.5 
99-             # Need someone with knowledge in netCDF4 to fix it 
100-             with  EtsfReader (path ) as  data :
101-                 structure  =  data .read_structure ()
102-                 assert  structure .site_properties ["magmom" ] ==  ref_magmom_collinear 
103- 
104-         with  tarfile .open (f"{ TEST_DIR }  , mode = "r:xz" ) as  t :
105-             # TODO: remove attr check after only 3.12+ 
106-             if  hasattr (tarfile , "data_filter" ):
107-                 t .extractall ("." , filter = "data" )
108-             else :
109-                 t .extractall ("." )  # noqa: S202 
110-             ref_magmom_noncollinear  =  [[0.357939487 , 0.357939487 , 0 ]]
111-             path  =  os .path .join ("." , "Fe_magmoms_noncollinear_GSR.nc" )
106+             path  =  os .path .basename (tarname ).replace (".tar.xz" , ".nc" )
112107
113108            with  EtsfReader (path ) as  data :
114109                structure  =  data .read_structure ()
115-                 assert  structure .site_properties ["magmom" ] ==  ref_magmom_noncollinear 
110+                 assert  structure .site_properties ["magmom" ] ==  expected 
116111
117112
118113class  TestAbinitHeader (MatSciTest ):
0 commit comments