Skip to content

Commit

Permalink
full printout report of failures and keep testing, please (create_tes…
Browse files Browse the repository at this point in the history
…t_conda_env.yml edit). ignore files ending in *tags created by papiex_tooler tests. adjust to some more pythonic conventions inother test scripts
  • Loading branch information
ilaflott committed Oct 4, 2024
1 parent ae4e9e0 commit 63aecbe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/create_test_conda_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ jobs:
# unittests for data_lineage
cd data_lineage && python -m unittest discover -s test -v || echo "data_lineage unittest failed."; cd -;
# pytest unittests for regrid-xy
cd app/regrid-xy && pytest -v -v -rx ./t || echo "pytest unittests for regrid-xy failed"; cd -;

# pytest unittests for make-timeseries
cd app/make-timeseries && pytest -v -v -x ./test || echo "pytest for make-timeseries failed"; cd -;
cd app/make-timeseries && pytest -v -v -rx ./test || echo "pytest for make-timeseries failed"; cd -;

# pytest unittests for remap-pp-components
cd app/remap-pp-components && pytest -v -v -x ./t/ || echo "pytest for remap-pp-components failed"; cd -;
cd app/remap-pp-components && pytest -v -v -rx ./t/ || echo "pytest for remap-pp-components failed"; cd -;

# pytest unittests for other things in this repository
pytest -v -v -x ./tests;
pytest -v -v -rx ./tests || echo "pytest unittests for root directory failed :-(";
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
*~
tests/test_files_papiex_tooler/*tags
22 changes: 11 additions & 11 deletions tests/test_PPANHandler.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
''' tests for PP/AN specific job_runner_handler class '''

def test_import():
def test_import(capfd):
''' check that ppan_handler can be imported.'''
#print(f'__name__=={__name__}')
from lib.python.ppan_handler import PPANHandler
test_handler=PPANHandler()

assert(test_handler.test_import() == 0)
assert test_handler.test_import() == 0


def test_tool_ops_import_in_handler():
def test_tool_ops_import_in_handler(capfd):
''' check that ppan_handler can import tool_ops_w_papiex'''
#print(f'__name__=={__name__}')
from lib.python.ppan_handler import PPANHandler
test_handler=PPANHandler()

assert(test_handler.test_tool_ops_import() == 0)
assert test_handler.test_tool_ops_import() == 0

def test_submit():
def test_submit(capfd):
''' check ppan_handler submit behavior with dry_run=True '''
#print(f'__name__=={__name__}')
from lib.python.ppan_handler import PPANHandler
test_handler=PPANHandler()

from pathlib import Path
job_file_path='./tests/test_files_papiex_tooler/am5_c96L33_amip_job_stage-history'
job_file_path='./tests/test_files_papiex_tooler/am5_c96L33_amip_mask-atmos-plevel_atmos_scalar_job'

# check for existing test output, remove in order to recreate
if Path(job_file_path+'.notags').exists():
Expand All @@ -37,10 +37,10 @@ def test_submit():
job_file_path = job_file_path,
submit_opts = submit_opts,
dry_run = True, tool_ops = True)
assert(all([ ret_code == 0,
ret_out == "HELLO\n",
ret_err == "",
Path(job_file_path+'.notags').exists(),
Path(job_file_path).exists() ]))
assert all ( [ ret_code == 0,
ret_out == "HELLO\n",
ret_err == "",
Path(job_file_path+'.notags').exists(),
Path(job_file_path).exists() ] )


38 changes: 17 additions & 21 deletions tests/test_papiex_tooler.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
''' tests for PP/AN specific ops-tooling of job scripts for PAPIEX'''
from subprocess import Popen, PIPE, DEVNULL
from pathlib import Path
import filecmp as fc
import difflib as dl
import pytest

def test_import():
''' check that tool_ops_w_papiex functions can be imported '''
from lib.python.tool_ops_w_papiex import test_import
assert(test_import() == 0)
assert test_import() == 0

def test_import_papiex_ops():
''' check that op list data can be imported '''
import lib.python.papiex_ops as po
assert ( all( [ po.op_list is not None,
len(po.op_list) > 0 ] ) )
assert all( [ po.op_list is not None,
len(po.op_list) > 0 ] )

def test_simple_failing_command():
''' check that setting/unsetting PAPIEX_TAGS around an op
will not touch the exit status of that op '''
from pathlib import Path
control_script_targ=str(Path.cwd())+'/tests/test_files_papiex_tooler/simple_failing_command.bash'
control_script_targ = str(Path.cwd()) + \
'/tests/test_files_papiex_tooler/simple_failing_command.bash'
assert Path(control_script_targ).exists() #quick check

# import subprocess and run "control" process for later comparison
from subprocess import Popen, PIPE, DEVNULL
control_proc=None
control_proc = None
try:
control_proc=Popen( args=['/bin/bash' ,control_script_targ],
control_proc = Popen( args=['/bin/bash' ,control_script_targ],
bufsize=0,
executable=None,
stdin=DEVNULL, stdout=PIPE, stderr=PIPE,
Expand All @@ -33,13 +36,14 @@ def test_simple_failing_command():
assert False

# grab control output
control_out, control_err= None,None
control_ret_code=None
control_out, control_err = None, None
control_ret_code = None
try:
control_out, control_err = (
f.decode() for f in control_proc.communicate(DEVNULL) )
control_ret_code = control_proc.wait()
print(f'control_out, control_err, control_ret_code = \n {control_out}, \n {control_err}, \n {control_ret_code}')
print(f'control_out, control_err, control_ret_code = ' + \
'\n {control_out}, \n {control_err}, \n {control_ret_code}')
assert all( [ control_out is not None,
control_err is not None,
control_ret_code is not None ] )
Expand Down Expand Up @@ -94,20 +98,17 @@ def test_check_simple_failing_command_for_diff():
prev test, which could in theory succeed if tool_ops_w_papiex copies
the script but without adding tooling.'''

from pathlib import Path
control_script_targ=str(Path.cwd())+'/tests/test_files_papiex_tooler/simple_failing_command.bash'
script_targ=control_script_targ+'.tags'
assert Path(control_script_targ).exists() #quick check
assert Path(script_targ).exists() #quick check

# check quickly that they are different in some manner.
import filecmp as fc
is_different=not fc.cmp( control_script_targ, script_targ,
shallow=False)
print(f'different? {is_different}\n\n')

# now we will explicitly check for those differencves
import difflib as dl
the_infile = open(control_script_targ)
infile_contents=the_infile.readlines()
the_infile.close()
Expand Down Expand Up @@ -135,8 +136,8 @@ def test_check_simple_failing_command_for_diff():


def test_rose_task_run_for_diff():
from pathlib import Path
control_script_targ=str(Path.cwd())+'/tests/test_files_papiex_tooler/am5_c96L33_amip_mask-atmos-plevel_atmos_scalar_job'
control_script_targ = str(Path.cwd()) + \
'/tests/test_files_papiex_tooler/am5_c96L33_amip_mask-atmos-plevel_atmos_scalar_job'


# if we're testing over and over and '.notags' version exists,
Expand All @@ -159,13 +160,11 @@ def test_rose_task_run_for_diff():
assert Path(script_targ).exists() #quick check

# check quickly that they are different in some manner.
import filecmp as fc
is_different=not fc.cmp( control_script_targ, script_targ,
shallow=False)
print(f'different? {is_different}\n\n')

# now we will explicitly check for those differences
import difflib as dl
the_infile = open(control_script_targ)
infile_contents=the_infile.readlines()
the_infile.close()
Expand Down Expand Up @@ -197,7 +196,6 @@ def test_rose_task_run_for_diff():


def test_pp_starter_for_no_diff():
from pathlib import Path
control_script_targ=str(Path.cwd())+'/tests/test_files_papiex_tooler/test_pp-starter'

# if we're testing over and over and '.notags' version exists,
Expand All @@ -220,13 +218,11 @@ def test_pp_starter_for_no_diff():
assert Path(script_targ).exists() #quick check

# check quickly that they are different in some manner.
import filecmp as fc
is_different=not fc.cmp( control_script_targ, script_targ,
shallow=False)
print(f'different? {is_different}\n\n')

# now we will explicitly check for those differences
import difflib as dl
the_infile = open(control_script_targ)
infile_contents=the_infile.readlines()
the_infile.close()
Expand Down

0 comments on commit 63aecbe

Please sign in to comment.