Skip to content

Commit

Permalink
Merge pull request #17 from NCAR/develop
Browse files Browse the repository at this point in the history
Bringing fork up to date 4/17/2018
  • Loading branch information
malloryprow authored Apr 17, 2018
2 parents 59b9b35 + 59da8f9 commit e6fcbe2
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 17 deletions.
28 changes: 28 additions & 0 deletions internal_tests/pytests/logging/logging_test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Configuration file for testing logging in MET+
## Override any key-values from the metplus_system.conf and metplus_data.conf files.
## ***NOTE***: Values are set to what is on DTC host 'eyewall'

[config]
# Logging levels: DEBUG, INFO, WARN, ERROR (most verbose is DEBUG)
LOG_LEVEL = DEBUG
LOG_DIR = {OUTPUT_BASE}/logs
LOG_FILENAME = {LOG_DIR}/master_metplus.log ;; NOTE: current YYYYMMDD is inserted before the rightmost . filename extension


[dir]
# These should be located at some test directory
PROJ_DIR = /d1/minnawin/logging_test_output
MET_INSTALL_DIR = /usr/local/met-6.1
METPLUS_BASE = /home/minnawin/latest
OUTPUT_BASE = /d1/minnawin/logging_test_output
TMP_DIR = /d1/minnawin/logging_test_output/tmp

[exe]
WGRIB2 = /usr/local/bin/wgrib2
RM_EXE = /bin/rm
CUT_EXE = /usr/bin/cut
TR_EXE = /usr/bin/tr
NCAP2_EXE =/usr/local/nco/bin/ncap2
CONVERT_EXE =/usr/bin/convert
NCDUMP_EXE = /usr/local/bin/ncdump
EGREP_EXE = /bin/egrep
95 changes: 95 additions & 0 deletions internal_tests/pytests/logging/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python

from __future__ import print_function

import logging
import re
import os
import pytest
import met_util as util
import config_metplus

#
# -----------Mandatory-----------
# configuration and fixture to support METplus configuration files beyond
# the metplus_data, metplus_system, and metplus_runtime conf files.
#


# Add a test configuration
def pytest_addoption(parser):
parser.addoption("-c", action="store", help=" -c <test config file>")


# @pytest.fixture
def cmdopt(request):
return request.config.getoption("-c")

@pytest.fixture
def get_test_config():
config_instance = config_metplus.setup()
return config_instance


@pytest.fixture
def get_test_logger():
# Create a logger object based on the logging_test.conf
config_instance = get_test_config()
fixture_logger = util.get_logger(config_instance)
return fixture_logger

# --------------Tests go here ------------


def test_log_level():
# Verify that the log level is set to what we indicated in the config file.
fixture_logger = get_test_logger()
# Expecting log level = DEBUG as set in the test config file.
level = logging.getLevelName('DEBUG')
assert fixture_logger.isEnabledFor(level)


def test_log_level_key():
# Verify that the LOG_LEVEL key is in the config file
config_instance = get_test_config()
section = 'config'
option = 'LOG_LEVEL'
assert config_instance.has_option(section, option)


def test_logdir_exists():
# Verify that the expected log dir exists.
config = get_test_config()
log_dir = config.get('config', 'LOG_DIR')
# Verify that a logfile exists in the log dir, with a filename
# like {LOG_DIR}/master_metplus.YYYYMMDD.log
assert os.path.exists(log_dir)


def test_logfile_exists():
# Verify that a logfile with format master_metplus.YYYYMMDD.log exists
# We are assuming that there can be numerous files in the log directory.
config = get_test_config()
log_dir = config.get('config', 'LOG_DIR')

# Only check for the log file if the log directory is present
if os.path.exists(log_dir):
files = [f for f in os.listdir(log_dir)]
match = re.match(r'master_metplus.[0-9]{8}.log', files[0])
if match:
# Check the first file
assert match.group(0)
else:
# This file doesn't match the expected file name format.
assert False
else:
# There is no log directory
assert False








21 changes: 7 additions & 14 deletions internal_tests/pytests/pb2nc/test_pb2nc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ def test_config(key, value):
assert (pb_key == value)


@pytest.mark.parametrize(
'key, value', [
('NC_FILE_TMPL', 'nam.t{init?fmt=%HH}z.prepbufr.tm{lead?fmt=%HH}'),
('NC_FILE_TMPL', 'prepbufr.gdas.{valid?fmt=%Y%m%d%HH}')
]
)
#@pytest.mark.parametrize(
# 'key, value', [
# ('NC_FILE_TMPL', 'nam.t{init?fmt=%HH}z.prepbufr.tm{lead?fmt=%HH}'),
# ('NC_FILE_TMPL', 'prepbufr.gdas.{valid?fmt=%Y%m%d%HH}')
# ]
#)
# def test_set_attribute_after_wrapper_creation(key, value):
# # Test that we can change the attribute defined in the config file
# pb = pb2nc_wrapper()
Expand Down Expand Up @@ -509,12 +509,5 @@ def test_config(key, value):
# assert True
#
#
# def test_refactor():
# pb = pb2nc_wrapper()
# relevant = pb.get_files_by_time()
# assert True is True
#
def test_run():
pb = pb2nc_wrapper()
pb.run_all_times()
assert True

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ POINT_STAT_OUTPUT_DIR = {OUTPUT_BASE}/{OBS_NAME}
## PROCESS_LIST.
LOOP_METHOD = processes

# Time method by which to perform validation, either by init time or by valid
# time. Indicate by either BY_VALID or BY_INIT
TIME_METHOD = BY_VALID

# MET point_stat config file
#POINT_STAT_CONFIG_FILE ={PARM_BASE}/met_config/Mallory_PointStatConfig_conus_sfc
POINT_STAT_CONFIG_FILE ={PARM_BASE}/met_config/PointStatConfig_conus_sfc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ POINT_STAT_OUTPUT_DIR = {OUTPUT_BASE}/{MODEL_NAME}
## PROCESS_LIST.
LOOP_METHOD = processes

# Time method by which to perform validation, either by init time or by valid
# time. Indicate by either BY_VALID or BY_INIT
TIME_METHOD = BY_VALID

# MET point_stat config file
POINT_STAT_CONFIG_FILE = {PARM_BASE}/met_config/PointStatConfig_upper_air

Expand Down
156 changes: 156 additions & 0 deletions internal_tests/pytests/produtil/test_produtil_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import subprocess
#import produtil.setup
import produtil
import sys
import logging
import pytest
import config_metplus
import config_launcher as launcher
import met_util as util


#
# These are tests (not necessarily unit tests) for the
# MET Point-Stat Wrapper, PointStatWrapper.py
# NOTE: This test requires pytest, which is NOT part of the standard Python
# library.
# These tests require one configuration file in addition to the three
# required METplus configuration files: point_stat_test.conf. This contains
# the information necessary for running all the tests. Each test can be
# customized to replace various settings if needed.
#

#
# -----------Mandatory-----------
# configuration and fixture to support METplus configuration files beyond
# the metplus_data, metplus_system, and metplus_runtime conf files.
#


# Add a test configuration
# def pytest_addoption(parser):
# parser.addoption("-c", action="store", help=" -c <test config file>")
#
#
# # @pytest.fixture
# def cmdopt(request):
# return request.config.getoption("-c")


# ------------------------

def get_config_obj():
"""! Create the configuration object that is used by all tests"""
file_list = ["METplus/internal_tests/pytests/produtil"]
config_obj = config_metplus.setup(file_list[0])

return config_obj


def test_getstr_ok(regtest):
"""! Test that the expected string is retrieved via produtil's getstr
method
"""
conf_obj = get_config_obj()
str_value = conf_obj.getstr('config', 'STRING_VALUE')
expected_str_value = "someStringValue!#@$%"
# print(str_value, file=regtest)
regtest.write("done")


def test_getint_ok(regtest):
"""! Test that the expected int in the produtil_test.conf file has been
retrieved correctly.
"""
conf_obj = get_config_obj()
expected_int_value = int(2908887)
int_value = conf_obj.getint('config', 'INT_VALUE')
# print(int_value, file=regtest)
regtest.write("done")


def test_getraw_ok(regtest):
"""! Test that the raw value in the produtil_test.conf file has been
retrieved correctly.
"""
conf_obj = get_config_obj()
expected_raw = 'GRIB_lvl_type = 100'
raw_value = conf_obj.getraw('config', 'RAW_VALUE')
# print(raw_value, file=regtest)
# regtest.write("done")


def test_getdir_ok(regtest):
"""! Test that the directory in the produtil_test.conf file has been
correctly retrieved.
"""
conf_obj = get_config_obj()
expected_dir = "/tmp/some_dir"
dir_retrieved = conf_obj.getdir('DIR_VALUE')
# print(dir_retrieved, file=regtest)


def test_getdir_compound_ok(regtest):
"""! Test that directories created from other directories, ie.
BASE_DIR = /base/dir
SPECIFIC_DIR = {BASE_DIR}/specific/dir
correctly returns the directory path for SPECIFIC_DIR
"""
expected_specific_dir = "/tmp/specific_place"
conf_obj = get_config_obj()
specific_dir = conf_obj.getdir('SPECIFIC_DIR')
print(specific_dir, file=regtest)


def test_no_value_as_string(regtest):
"""! Tests that a key with no value returns an empty string."""

conf_obj = get_config_obj()
expected_unassigned = ''
unassigned = conf_obj.getstr('config', 'UNASSIGNED_VALUE')
# print(unassigned, file=regtest)


def test_no_value_as_list(regtest):
"""! Tests that a key with no list of strings returns an empty list."""

conf_obj = get_config_obj()
expected_unassigned = []
unassigned = util.getlist(conf_obj.getstr('config', 'UNASSIGNED_VALUE'))
assert unassigned == expected_unassigned
# print(unassigned, file=regtest)


def test_new_lines_in_conf(regtest):
"""! Test that any newlines in the configuration file are handled
properly
"""

conf_obj = get_config_obj()
expected_string = \
"very long line requiring newline character to be tested 12345\n67890 end of the line."
long_line = conf_obj.getstr('config', 'NEW_LINES')
assert long_line == expected_string
# print(long_line, file=regtest)


def test_get_exe_ok(regtest):
"""! Test that executables are correctly retrieved."""
conf_obj = get_config_obj()
expected_exe = '/usr/local/bin/wgrib2'
executable = conf_obj.getexe('WGRIB2')
assert executable == expected_exe
# print(executable, file=regtest)


def test_get_bool(regtest):
"""! Test that boolean values are correctly retrieved."""
conf_obj = get_config_obj()
bool_val = conf_obj.getbool('config', 'BOOL_VALUE')
assert bool_val is True
# print(bool_val, file=regtest)

4 changes: 2 additions & 2 deletions parm/use_cases/hwt/grid2grid_hwt_env.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ OBS_REFC_0_THRESH = 25, 30, 35, 40, 45, 50

[filename_templates]
# HRRRe
FCST_GRID_STAT_INPUT_TEMPLATE = {ENV[FCST_INPUT_TEMPLATE_IN]}
FCST_GRID_STAT_INPUT_TEMPLATE = $FCST_INPUT_TEMPLATE_IN

# MRMS REFC
OBS_GRID_STAT_INPUT_TEMPLATE = {ENV[OBS_INPUT_TEMPLATE_IN]}
OBS_GRID_STAT_INPUT_TEMPLATE = $OBS_INPUT_TEMPLATE_IN
Loading

0 comments on commit e6fcbe2

Please sign in to comment.