<s> '''<STR_LIT>''' <EOL> import tempfile <EOL> import shutil <EOL> from os import path <EOL> from glob import iglob <EOL> import re <EOL> from numpy . testing import assert_equal , assert_allclose , run_module_suite <EOL> import numpy as np <EOL> from scipy . io import FortranFile <EOL> DATA_PATH = path . join ( path . dirname ( __file__ ) , '<STR_LIT:data>' ) <EOL> def test_fortranfiles_read ( ) : <EOL> for filename in iglob ( path . join ( DATA_PATH , "<STR_LIT>" ) ) : <EOL> m = re . search ( '<STR_LIT>' , filename , re . I ) <EOL> if not m : <EOL> raise RuntimeError ( "<STR_LIT>" % filename ) <EOL> dims = ( int ( m . group ( <NUM_LIT:2> ) ) , int ( m . group ( <NUM_LIT:3> ) ) , int ( m . group ( <NUM_LIT:4> ) ) ) <EOL> f = FortranFile ( filename , '<STR_LIT:r>' , '<STR_LIT>' ) <EOL> data = f . read_record ( dtype = m . group ( <NUM_LIT:1> ) . replace ( '<STR_LIT:s>' , '<STR_LIT:<>' ) ) . reshape ( dims ) <EOL> f . close ( ) <EOL> counter = <NUM_LIT:0> <EOL> for k in range ( dims [ <NUM_LIT:2> ] ) : <EOL> for j in range ( dims [ <NUM_LIT:1> ] ) : <EOL> for i in range ( dims [ <NUM_LIT:0> ] ) : <EOL> assert_equal ( counter , data [ i , j , k ] ) <EOL> counter += <NUM_LIT:1> <EOL> def test_fortranfiles_mixed_record ( ) : <EOL> filename = path . join ( DATA_PATH , "<STR_LIT>" ) <EOL> with FortranFile ( filename , '<STR_LIT:r>' , '<STR_LIT>' ) as f : <EOL> record = f . read_record ( '<STR_LIT>' ) <EOL> assert_equal ( record [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <NUM_LIT:1> ) <EOL> assert_allclose ( record [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( record [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <NUM_LIT:4> ) <EOL> assert_allclose ( record [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_fortranfiles_write ( ) : <EOL> for filename in iglob ( path . join ( DATA_PATH , "<STR_LIT>" ) ) : <EOL> m = re . search ( '<STR_LIT>' , filename , re . I ) <EOL> if not m : <EOL> raise RuntimeError ( "<STR_LIT>" % filename ) <EOL> dims = ( int ( m . group ( <NUM_LIT:2> ) ) , int ( m . group ( <NUM_LIT:3> ) ) , int ( m . group ( <NUM_LIT:4> ) ) ) <EOL> counter = <NUM_LIT:0> <EOL> data = np . zeros ( dims , dtype = m . group ( <NUM_LIT:1> ) . replace ( '<STR_LIT:s>' , '<STR_LIT:<>' ) ) <EOL> for k in range ( dims [ <NUM_LIT:2> ] ) : <EOL> for j in range ( dims [ <NUM_LIT:1> ] ) : <EOL> for i in range ( dims [ <NUM_LIT:0> ] ) : <EOL> data [ i , j , k ] = counter <EOL> counter += <NUM_LIT:1> <EOL> tmpdir = tempfile . mkdtemp ( ) <EOL> try : <EOL> testFile = path . join ( tmpdir , path . basename ( filename ) ) <EOL> f = FortranFile ( testFile , '<STR_LIT:w>' , '<STR_LIT>' ) <EOL> f . write_record ( data ) <EOL> f . close ( ) <EOL> originalfile = open ( filename , '<STR_LIT:rb>' ) <EOL> newfile = open ( testFile , '<STR_LIT:rb>' ) <EOL> assert_equal ( originalfile . read ( ) , newfile . read ( ) , <EOL> err_msg = filename ) <EOL> originalfile . close ( ) <EOL> newfile . close ( ) <EOL> finally : <EOL> shutil . rmtree ( tmpdir ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run_module_suite ( ) </s>
