Skip to content

Commit

Permalink
update string formating in unitTest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tgastine committed May 29, 2024
1 parent b58ce12 commit f4c3a03
Show file tree
Hide file tree
Showing 25 changed files with 656 additions and 661 deletions.
42 changes: 21 additions & 21 deletions samples/boussBenchSat/unitTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
import subprocess as sp

def cleanDir(dir):
if os.path.exists('%s/pscond.dat' % dir):
os.remove('%s/pscond.dat' % dir)
if os.path.exists('%s/scond.dat' % dir):
os.remove('%s/scond.dat' % dir)
if os.path.exists('%s/run_magic.sh' % dir):
os.remove('%s/run_magic.sh' % dir)
if os.path.exists('%s/run_magic_mpi.sh' % dir):
os.remove('%s/run_magic_mpi.sh' % dir)
for f in glob.glob('%s/*_BIS' % dir):
if os.path.exists('{}/pscond.dat'.format(dir)):
os.remove('{}/pscond.dat'.format(dir))
if os.path.exists('{}/scond.dat'.format(dir)):
os.remove('{}/scond.dat'.format(dir))
if os.path.exists('{}/run_magic.sh'.format(dir)):
os.remove('{}/run_magic.sh'.format(dir))
if os.path.exists('{}/run_magic_mpi.sh'.format(dir)):
os.remove('{}/run_magic_mpi.sh'.format(dir))
for f in glob.glob('{}/*_BIS'.format(dir)):
os.remove(f)
for f in glob.glob('%s/*.test' % dir):
for f in glob.glob('{}/*.test'.format(dir)):
os.remove(f)
if os.path.exists('%s/stdout.out' % dir):
os.remove('%s/stdout.out' % dir)
for f in glob.glob('%s/*.pyc' % dir):
if os.path.exists('{}/stdout.out'.format(dir)):
os.remove('{}/stdout.out'.format(dir))
for f in glob.glob('{}/*.pyc'.format(dir)):
os.remove(f)
if os.path.exists('%s/__pycache__' % dir):
shutil.rmtree('%s/__pycache__' % dir)
if os.path.exists('{}/__pycache__'.format(dir)):
shutil.rmtree('{}/__pycache__'.format(dir))


def readData(file):
Expand All @@ -48,12 +48,12 @@ def list2reason(self, exc_list):

def setUp(self):
# Cleaning when entering
print('\nDirectory : %s' % self.dir)
print('Description : %s' % self.description)
print('\nDirectory : {}'.format(self.dir))
print('Description : {}'.format(self.description))
self.startTime = time.time()
cleanDir(self.dir)
os.chdir(self.dir)
cmd = '%s %s/input.nml' % (self.execCmd, self.dir)
cmd = '{} {}/input.nml'.format(self.execCmd, self.dir)
sp.call(cmd, shell=True, stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))

Expand All @@ -64,7 +64,7 @@ def tearDown(self):

t = time.time()-self.startTime
st = time.strftime("%M:%S", time.gmtime(t))
print('Time used : %s' % st)
print('Time used : {}'.format(st))

if hasattr(self, '_outcome'): # python 3.4+
if hasattr(self._outcome, 'errors'): # python 3.4-3.10
Expand Down Expand Up @@ -93,7 +93,7 @@ def tearDown(self):
print(result.failures[-1][-1])

def outputFileDiff(self):
datRef = readData('%s/reference.out' % self.dir)
datTmp = readData('%s/e_kin.test' % self.dir)
datRef = readData('{}/reference.out'.format(self.dir))
datTmp = readData('{}/e_kin.test'.format(self.dir))
np.testing.assert_allclose(datRef, datTmp, rtol=self.precision,
atol=1e-20)
48 changes: 24 additions & 24 deletions samples/couetteAxi/unitTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
import subprocess as sp

def cleanDir(dir):
if os.path.exists('%s/pscond.dat' % dir):
os.remove('%s/pscond.dat' % dir)
if os.path.exists('%s/scond.dat' % dir):
os.remove('%s/scond.dat' % dir)
if os.path.exists('%s/run_magic.sh' % dir):
os.remove('%s/run_magic.sh' % dir)
if os.path.exists('%s/run_magic_mpi.sh' % dir):
os.remove('%s/run_magic_mpi.sh' % dir)
for f in glob.glob('%s/*_BIS' % dir):
if os.path.exists('{}/pscond.dat'.format(dir)):
os.remove('{}/pscond.dat'.format(dir))
if os.path.exists('{}/scond.dat'.format(dir)):
os.remove('{}/scond.dat'.format(dir))
if os.path.exists('{}/run_magic.sh'.format(dir)):
os.remove('{}/run_magic.sh'.format(dir))
if os.path.exists('{}/run_magic_mpi.sh'.format(dir)):
os.remove('{}/run_magic_mpi.sh'.format(dir))
for f in glob.glob('{}/*_BIS'.format(dir)):
os.remove(f)
for f in glob.glob('%s/*.test' % dir):
for f in glob.glob('{}/*.test'.format(dir)):
os.remove(f)
if os.path.exists('%s/stdout.out' % dir):
os.remove('%s/stdout.out' % dir)
for f in glob.glob('%s/*.pyc' % dir):
if os.path.exists('{}/stdout.out'.format(dir)):
os.remove('{}/stdout.out'.format(dir))
for f in glob.glob('{}/*.pyc'.format(dir)):
os.remove(f)
if os.path.exists('%s/__pycache__' % dir):
shutil.rmtree('%s/__pycache__' % dir)
if os.path.exists('{}/__pycache__'.format(dir)):
shutil.rmtree('{}/__pycache__'.format(dir))

def readStack(file):
f = open(file, 'r')
Expand Down Expand Up @@ -54,33 +54,33 @@ def list2reason(self, exc_list):

def setUp(self):
# Cleaning when entering
print('\nDirectory : %s' % self.dir)
print('Description : %s' % self.description)
print('\nDirectory : {}'.format(self.dir))
print('Description : {}'.format(self.description))
self.startTime = time.time()
cleanDir(self.dir)
for f in glob.glob('%s/*.start' % self.dir):
for f in glob.glob('{}/*.start'.format(self.dir)):
os.remove(f)

inpFile = 'input.nml'

os.chdir(self.dir)
cmd = '%s %s/inputStart.nml' % (self.execCmd, self.dir)
cmd = '{} {}/inputStart.nml'.format(self.execCmd, self.dir)
sp.call(cmd, shell=True, stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))
cmd = '%s %s/%s' % (self.execCmd, self.dir, inpFile)
cmd = '{} {}/{}'.format(self.execCmd, self.dir, inpFile)
sp.call(cmd, shell=True, stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))

def tearDown(self):
# Cleaning when leaving
os.chdir(self.startDir)
cleanDir(self.dir)
for f in glob.glob('%s/*.start' % self.dir):
for f in glob.glob('{}/*.start'.format(self.dir)):
os.remove(f)

t = time.time()-self.startTime
st = time.strftime("%M:%S", time.gmtime(t))
print('Time used : %s' % st)
print('Time used : {}'.format(st))

if hasattr(self, '_outcome'): # python 3.4+
if hasattr(self._outcome, 'errors'): # python 3.4-3.10
Expand Down Expand Up @@ -109,6 +109,6 @@ def tearDown(self):
print(result.failures[-1][-1])

def outputFileDiff(self):
datRef = readStack('%s/reference.out' % self.dir)
datTmp = readStack('%s/e_kin.test' % self.dir)
datRef = readStack('{}/reference.out'.format(self.dir))
datTmp = readStack('{}/e_kin.test'.format(self.dir))
np.testing.assert_allclose(datRef, datTmp, rtol=self.precision, atol=1e-20)
46 changes: 22 additions & 24 deletions samples/doubleDiffusion/unitTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@
import subprocess as sp

def cleanDir(dir):
if os.path.exists('%s/pscond.dat' % dir):
os.remove('%s/pscond.dat' % dir)
if os.path.exists('%s/scond.dat' % dir):
os.remove('%s/scond.dat' % dir)
if os.path.exists('%s/xicond.dat' % dir):
os.remove('%s/xicond.dat' % dir)
if os.path.exists('%s/run_magic.sh' % dir):
os.remove('%s/run_magic.sh' % dir)
if os.path.exists('%s/run_magic_mpi.sh' % dir):
os.remove('%s/run_magic_mpi.sh' % dir)
for f in glob.glob('%s/*_BIS' % dir):
if os.path.exists('{}/pscond.dat'.format(dir)):
os.remove('{}/pscond.dat'.format(dir))
if os.path.exists('{}/scond.dat'.format(dir)):
os.remove('{}/scond.dat'.format(dir))
if os.path.exists('{}/run_magic.sh'.format(dir)):
os.remove('{}/run_magic.sh'.format(dir))
if os.path.exists('{}/run_magic_mpi.sh'.format(dir)):
os.remove('{}/run_magic_mpi.sh'.format(dir))
for f in glob.glob('{}/*_BIS'.format(dir)):
os.remove(f)
for f in glob.glob('%s/*.test*' % dir):
for f in glob.glob('{}/*.test'.format(dir)):
os.remove(f)
if os.path.exists('%s/stdout.out' % dir):
os.remove('%s/stdout.out' % dir)
for f in glob.glob('%s/*.pyc' % dir):
if os.path.exists('{}/stdout.out'.format(dir)):
os.remove('{}/stdout.out'.format(dir))
for f in glob.glob('{}/*.pyc'.format(dir)):
os.remove(f)
if os.path.exists('%s/__pycache__' % dir):
shutil.rmtree('%s/__pycache__' % dir)
if os.path.exists('{}/__pycache__'.format(dir)):
shutil.rmtree('{}/__pycache__'.format(dir))


def readData(file):
Expand All @@ -50,16 +48,16 @@ def list2reason(self, exc_list):

def setUp(self):
# Cleaning when entering
print('\nDirectory : %s' % self.dir)
print('Description : %s' % self.description)
print('\nDirectory : {}'.format(self.dir))
print('Description : {}'.format(self.description))
self.startTime = time.time()
cleanDir(self.dir)
os.chdir(self.dir)
cmd = '%s %s/input.nml' % (self.execCmd, self.dir)
cmd = '{} {}/input.nml'.format(self.execCmd, self.dir)
sp.call(cmd, shell=True, stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))

cmd = '%s %s/input_FD.nml' % (self.execCmd, self.dir)
cmd = '{} {}/input_FD.nml'.format(self.execCmd, self.dir)
sp.call(cmd, shell=True, stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))

Expand All @@ -73,7 +71,7 @@ def tearDown(self):

t = time.time()-self.startTime
st = time.strftime("%M:%S", time.gmtime(t))
print('Time used : %s' % st)
print('Time used : {}'.format(st))

if hasattr(self, '_outcome'): # python 3.4+
if hasattr(self._outcome, 'errors'): # python 3.4-3.10
Expand Down Expand Up @@ -102,8 +100,8 @@ def tearDown(self):
print(result.failures[-1][-1])

def outputFileDiff(self):
datRef = readData('%s/reference.out' % self.dir)
datTmp = readData('%s/e_kin.test' % self.dir)
datRef = readData('{}/reference.out'.format(self.dir))
datTmp = readData('{}/e_kin.test'.format(self.dir))
np.testing.assert_allclose(datRef, datTmp, rtol=self.precision,
atol=1e-20)

46 changes: 23 additions & 23 deletions samples/dynamo_benchmark/unitTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
import subprocess as sp

def cleanDir(dir):
if os.path.exists('%s/pscond.dat' % dir):
os.remove('%s/pscond.dat' % dir)
if os.path.exists('%s/scond.dat' % dir):
os.remove('%s/scond.dat' % dir)
if os.path.exists('%s/run_magic.sh' % dir):
os.remove('%s/run_magic.sh' % dir)
if os.path.exists('%s/run_magic_mpi.sh' % dir):
os.remove('%s/run_magic_mpi.sh' % dir)
for f in glob.glob('%s/*_BIS' % dir):
if os.path.exists('{}/pscond.dat'.format(dir)):
os.remove('{}/pscond.dat'.format(dir))
if os.path.exists('{}/scond.dat'.format(dir)):
os.remove('{}/scond.dat'.format(dir))
if os.path.exists('{}/run_magic.sh'.format(dir)):
os.remove('{}/run_magic.sh'.format(dir))
if os.path.exists('{}/run_magic_mpi.sh'.format(dir)):
os.remove('{}/run_magic_mpi.sh'.format(dir))
for f in glob.glob('{}/*_BIS'.format(dir)):
os.remove(f)
for f in glob.glob('%s/*.test' % dir):
for f in glob.glob('{}/*.test'.format(dir)):
os.remove(f)
if os.path.exists('%s/stdout.out' % dir):
os.remove('%s/stdout.out' % dir)
for f in glob.glob('%s/*.pyc' % dir):
if os.path.exists('{}/stdout.out'.format(dir)):
os.remove('{}/stdout.out'.format(dir))
for f in glob.glob('{}/*.pyc'.format(dir)):
os.remove(f)
if os.path.exists('%s/__pycache__' % dir):
shutil.rmtree('%s/__pycache__' % dir)
if os.path.exists('{}/__pycache__'.format(dir)):
shutil.rmtree('{}/__pycache__'.format(dir))


def readData(file):
Expand All @@ -48,12 +48,12 @@ def list2reason(self, exc_list):

def setUp(self):
# Cleaning when entering
print('\nDirectory : %s' % self.dir)
print('Description : %s' % self.description)
print('\nDirectory : {}'.format(self.dir))
print('Description : {}'.format(self.description))
self.startTime = time.time()
cleanDir(self.dir)
os.chdir(self.dir)
cmd = '%s %s/input.nml' % (self.execCmd, self.dir)
cmd = '{} {}/input.nml'.format(self.execCmd, self.dir)
sp.call(cmd, shell=True, stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))

Expand All @@ -64,7 +64,7 @@ def tearDown(self):

t = time.time()-self.startTime
st = time.strftime("%M:%S", time.gmtime(t))
print('Time used : %s' % st)
print('Time used : {}'.format(st))

if hasattr(self, '_outcome'): # python 3.4+
if hasattr(self._outcome, 'errors'): # python 3.4-3.10
Expand Down Expand Up @@ -96,11 +96,11 @@ def tearDown(self):

def outputFileDiff(self):
# Kinetic energy
datRef = readData('%s/reference.out' % self.dir)
datTmp = readData('%s/e_kin.test' % self.dir)
datRef = readData('{}/reference.out'.format(self.dir))
datTmp = readData('{}/e_kin.test'.format(self.dir))
np.testing.assert_allclose(datRef, datTmp, rtol=self.precision, atol=1e-20)

# Magnetic energy
datRef = readData('%s/referenceMag.out' % self.dir)
datTmp = readData('%s/e_mag_oc.test' % self.dir)
datRef = readData('{}/referenceMag.out'.format(self.dir))
datTmp = readData('{}/e_mag_oc.test'.format(self.dir))
np.testing.assert_allclose(datRef, datTmp, rtol=self.precision, atol=1e-20)
Loading

0 comments on commit f4c3a03

Please sign in to comment.