-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from NCAR/develop
Bringing fork up to date 4/17/2018
- Loading branch information
Showing
11 changed files
with
586 additions
and
17 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
internal_tests/pytests/produtil/test_produtil_regression.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.