Skip to content

Commit

Permalink
add missing folder, refactor fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
iulusoy committed Oct 25, 2023
1 parent 160181c commit f369abc
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@ dmypy.json
doc/

# testmodels
testmodels/
testmodels/

# modified .powrconfig
powr/.powrconfig
2 changes: 1 addition & 1 deletion powr/powrconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# bash style for the PoWR scripts

# define the powr work directory
# export POWR_WORK=powr/
export POWR_WORK=
export POWR_INSTTYPE=local
# export POWR_INSTTYPE=potsdam
# export POWR_INSTTYPE=niscluster
Expand Down
2 changes: 1 addition & 1 deletion powr/proc.dir/makechain.com
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# source ~/.powrconfig || exit
source ~/.powrconfig || exit

# this script generates a new chain for PoWR with number "kn" given via call
# created by H. Todt 05.03.2008
Expand Down
2 changes: 1 addition & 1 deletion powr/proc.dir/submit.com
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# source ~/.powrconfig || exit
source ~/.powrconfig || exit

####################################################################
#
Expand Down
Binary file not shown.
36 changes: 19 additions & 17 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,40 @@ def set_vars():
powrdir = filedir.parents[0] / "powr"
os.environ["POWR_WORK"] = powrdir.as_posix()
os.environ["POWREXEPATH"] = (powrdir / "exe.dir").as_posix()
# create the tmp_2day folder if not exists
tmp_2day = powrdir / "tmp_2day"
if not os.path.exists(tmp_2day):
os.mkdir(tmp_2day)
return powrdir


# inject path into powrconfig
@pytest.fixture(scope="session")
def set_aliases(set_vars):
setup_file = "bash_setup" # this could be different on MacOS
# the aliases setup currently does not work as the aliases
# are destryed between subprocess sessions
# either we set them in the python script or
# run explicitly with passing the env as dict
full_file_path = "${POWR_WORK}/proc.dir/" + setup_file
subprocess.run(
full_file_path,
shell=True,
check=True,
executable="/bin/bash",
capture_output=True,
text=True,
)
def inject_path(set_vars):
powrconfig_file = set_vars / "powrconfig"
with open(powrconfig_file, "r") as f:
powrconfig = f.read()
# now insert path in correct spot
temp = powrconfig.split("export POWR_WORK=")
powrconfig = temp[0] + "export POWR_WORK=" + set_vars.as_posix() + temp[1]
powrconfig_file = set_vars / ".powrconfig"
with open(powrconfig_file, "w") as f:
f.write(powrconfig)


@pytest.fixture(scope="session")
def get_chain(set_aliases):
def get_chain(inject_path):
makechain_command = "${POWR_WORK}/proc.dir/makechain.com 1"
subprocess.run(
temp = subprocess.run(
makechain_command,
shell=True,
check=True,
executable="/bin/bash",
capture_output=True,
text=True,
)
print(temp.stdout)
print(temp.stderr)
yield "Created chain 1"
# teardown directories
# we need access to ${POWR_WORK} so shutil will not work
Expand Down
5 changes: 4 additions & 1 deletion test/test_colitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def run_colitest(get_chain):
os.system("cat ${POWR_WORK}/output/colitest1.cpr")
yield "ran colitest"
os.system("rm -rf ${POWR_WORK}/tmp_data")
os.system("rm -rf ${POWR_WORK}/tmp_2day/*")
return "Cleaned colitest tmp data"


Expand Down Expand Up @@ -69,6 +70,8 @@ def test_makechain(set_vars, get_chain):
wrdata1_content = [
"CARDS",
"DATOM",
"FEDAT",
"FEDAT_FORMAL",
"FGRID",
"FORMAL_CARDS",
"MODEL",
Expand Down Expand Up @@ -136,5 +139,5 @@ def test_colitest_run(set_vars, run_colitest):
def test_read_model(set_vars, run_colitest):
model_output = set_vars / "wrdata1" / "MODEL_STUDY_DONE"
data_np = np.fromfile(model_output, dtype=float)
assert len(data_np) == 2233856
assert len(data_np) == 2246784
assert np.allclose(data_np[256138:256149], MODEL_DATA_REF)

0 comments on commit f369abc

Please sign in to comment.