Skip to content

Commit

Permalink
python3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Oct 10, 2017
1 parent f04afb5 commit 170bba5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion scripts/Tools/case.build
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _main_func(description):
if cleanlist is not None or clean_all:
build.clean(case, cleanlist, clean_all)
elif(testname is not None):
logging.warn("Building test for {} in directory {}".format(testname,
logging.warning("Building test for {} in directory {}".format(testname,
caseroot))
try:
# The following line can throw exceptions if the testname is
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/CIME/BuildTools/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _generate_env_mach_specific(output_dir, machobj, compiler, mpilib, debug,
"""
ems_path = os.path.join(output_dir, "env_mach_specific.xml")
if os.path.exists(ems_path):
logger.warn("{} already exists, delete to replace".format(ems_path))
logger.warning("{} already exists, delete to replace".format(ems_path))
return
ems_file = EnvMachSpecific(output_dir, unit_testing=unit_testing)
ems_file.populate(machobj)
Expand Down
4 changes: 2 additions & 2 deletions scripts/lib/CIME/BuildTools/macrowriterbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def write_line(self, line):
A trailing newline is added, whether or not the input has one.
"""
self.output.write(unicode(self.indent_string() + line + "\n"))
self.output.write(str(self.indent_string() + line + "\n"))

@abstractmethod
def environment_variable_string(self, name):
Expand Down Expand Up @@ -208,7 +208,7 @@ def write_macros_file_v1(macros, compiler, os_, machine, macros_file="Macros", o
# A few things can be used from environ if not in XML
for item in ["MPI_PATH", "NETCDF_PATH"]:
if not item in macros and item in os.environ:
logger.warn("Setting {} from Environment".format(item))
logger.warning("Setting {} from Environment".format(item))
macros[item] = os.environ[item]

with open(macros_file, "w") as fd:
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/CIME/XML/generic_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def validate_xml_file(self, filename, schema):
logger.debug("Checking file {} against schema {}".format(filename, schema))
run_cmd_no_fail("{} --noout --schema {} {}".format(xmllint, schema, filename))
else:
logger.warn("xmllint not found, could not validate file {}".format(filename))
logger.warning("xmllint not found, could not validate file {}".format(filename))

def get_element_text(self, element_name, attributes=None, root=None, xpath=None):
element_node = self.get_optional_node(element_name, attributes, root, xpath)
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/CIME/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_model():
>>> del os.environ["CIME_MODEL"]
>>> set_model('rocky')
>>> get_model()
u'rocky'
'rocky'
>>> reset_cime_config()
"""
model = os.environ.get("CIME_MODEL")
Expand Down
8 changes: 6 additions & 2 deletions scripts/lib/update_acme_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,15 @@ def sort_by_time(test_one, test_two):
"""
rec1, rec2 = get_recommended_test_time(test_one), get_recommended_test_time(test_two)
if rec1 == rec2:
return cmp(test_one, test_two)
return (test_one > test_two) - (test_two < test_one)
else:
if rec2 is None:
return -1
elif rec1 is None:
return 1
else:
return cmp(convert_to_seconds(rec2), convert_to_seconds(rec1))
a = convert_to_seconds(rec2)
b = convert_to_seconds(rec1)
return (a < b) - (b < a)


28 changes: 14 additions & 14 deletions scripts/tests/scripts_regression_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import io, glob, os, re, shutil, signal, sys, tempfile, \
threading, time, logging, unittest, getpass, string
threading, time, logging, unittest, getpass

from xml.etree.ElementTree import ParseError

Expand Down Expand Up @@ -340,7 +340,7 @@ def test_d_create_clone_new_user(self):
run_cmd_assert_result(self, "./xmlchange USER=this_is_not_a_user",
from_dir=prevtestdir)

fakeoutputroot = string.replace(cls._testroot, os.environ.get("USER"), "this_is_not_a_user")
fakeoutputroot = cls._testroot.replace(os.environ.get("USER"), "this_is_not_a_user")
run_cmd_assert_result(self, "./xmlchange CIME_OUTPUT_ROOT=%s"%fakeoutputroot,
from_dir=prevtestdir)

Expand Down Expand Up @@ -1692,7 +1692,7 @@ def get_macros(macro_maker, build_xml, build_system):
"""
# Build.write_macros expects file-like objects as input, so
# we need to wrap the strings in StringIO objects.
xml = io.StringIO(unicode(build_xml))
xml = io.StringIO(str(build_xml))
output = io.StringIO()
output_format = None
if build_system == "Makefile":
Expand Down Expand Up @@ -1938,7 +1938,7 @@ def test_script_rejects_bad_build_system(self):
"""The macro writer rejects a bad build system string."""
maker = Compilers(MockMachines("mymachine", "SomeOS"), version="2.0")
bad_string = "argle-bargle."
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
SystemExit,
"Unrecognized build system provided to write_macros: " + bad_string):
get_macros(maker, "This string is irrelevant.", bad_string)
Expand Down Expand Up @@ -2040,7 +2040,7 @@ def test_reject_duplicate_defaults(self):
"""The macro writer dies if given many defaults."""
xml1 = """<compiler><MPI_PATH>/path/to/default</MPI_PATH></compiler>"""
xml2 = """<compiler><MPI_PATH>/path/to/other_default</MPI_PATH></compiler>"""
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
SystemExit,
"Variable MPI_PATH is set ambiguously in config_build.xml."):
self.xml_to_tester(xml1+xml2)
Expand All @@ -2049,7 +2049,7 @@ def test_reject_duplicates(self):
"""The macro writer dies if given many matches for a given configuration."""
xml1 = """<compiler><MPI_PATH MPILIB="mpich">/path/to/mpich</MPI_PATH></compiler>"""
xml2 = """<compiler><MPI_PATH MPILIB="mpich">/path/to/mpich2</MPI_PATH></compiler>"""
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
SystemExit,
"Variable MPI_PATH is set ambiguously in config_build.xml."):
self.xml_to_tester(xml1+xml2)
Expand All @@ -2058,7 +2058,7 @@ def test_reject_ambiguous(self):
"""The macro writer dies if given an ambiguous set of matches."""
xml1 = """<compiler><MPI_PATH MPILIB="mpich">/path/to/mpich</MPI_PATH></compiler>"""
xml2 = """<compiler><MPI_PATH DEBUG="FALSE">/path/to/mpi-debug</MPI_PATH></compiler>"""
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
SystemExit,
"Variable MPI_PATH is set ambiguously in config_build.xml."):
self.xml_to_tester(xml1+xml2)
Expand Down Expand Up @@ -2190,7 +2190,7 @@ def test_env_and_shell_command(self):
tester.assert_variable_equals("FFLAGS", "-O2 -fast", env={"OPT_LEVEL": "2"})
xml1 = """<compiler><FFLAGS><base>-O$SHELL{echo $ENV{OPT_LEVEL}} -fast</base></FFLAGS></compiler>"""
err_msg = "Nesting not allowed.*"
with self.assertRaisesRegexp(SystemExit, err_msg):
with self.assertRaisesRegex(SystemExit, err_msg):
self.xml_to_tester(xml1)

def test_config_variable_insertion(self):
Expand Down Expand Up @@ -2220,25 +2220,25 @@ def test_config_reject_self_references(self):
# references.
xml1 = """<MPI_LIB_NAME><var>MPI_LIB_NAME</var></MPI_LIB_NAME>"""
err_msg = ".* has bad <var> references."
with self.assertRaisesRegexp(SystemExit, err_msg):
with self.assertRaisesRegex(SystemExit, err_msg):
self.xml_to_tester("<compiler>"+xml1+"</compiler>")

xml1 = """<MPI_LIB_NAME>${MPI_LIB_NAME}</MPI_LIB_NAME>"""
err_msg = ".* has bad <var> references."
with self.assertRaisesRegexp(SystemExit, err_msg):
with self.assertRaisesRegex(SystemExit, err_msg):
self.xml_to_tester("<compiler>"+xml1+"</compiler>")

def test_config_reject_cyclical_references(self):
"""Test that cyclical <var> references are rejected."""
xml1 = """<MPI_LIB_NAME><var>MPI_PATH</var></MPI_LIB_NAME>"""
xml2 = """<MPI_PATH><var>MPI_LIB_NAME</var></MPI_PATH>"""
err_msg = ".* has bad <var> references."
with self.assertRaisesRegexp(SystemExit, err_msg):
with self.assertRaisesRegex(SystemExit, err_msg):
self.xml_to_tester("<compiler>"+xml1+xml2+"</compiler>")
xml1 = """<MPI_LIB_NAME>${MPI_PATH}</MPI_LIB_NAME>"""
xml2 = """<MPI_PATH>${MPI_LIB_NAME}</MPI_PATH>"""
err_msg = ".* has bad <var> references."
with self.assertRaisesRegexp(SystemExit, err_msg):
with self.assertRaisesRegex(SystemExit, err_msg):
self.xml_to_tester("<compiler>"+xml1+xml2+"</compiler>")

def test_variable_insertion_with_machine_specific_setting(self):
Expand All @@ -2247,14 +2247,14 @@ def test_variable_insertion_with_machine_specific_setting(self):
xml2 = """<compiler MACH="{}"><MPI_LIB_NAME><var>MPI_PATH</var></MPI_LIB_NAME></compiler>""".format(self.test_machine)
xml3 = """<compiler><MPI_PATH><var>MPI_LIB_NAME</var></MPI_PATH></compiler>"""
err_msg = ".* has bad <var> references."
with self.assertRaisesRegexp(SystemExit, err_msg):
with self.assertRaisesRegex(SystemExit, err_msg):
self.xml_to_tester(xml1+xml2+xml3)

xml1 = """<compiler><MPI_LIB_NAME>something</MPI_LIB_NAME></compiler>"""
xml2 = """<compiler MACH="{}"><MPI_LIB_NAME><var>MPI_PATH</var></MPI_LIB_NAME></compiler>""".format(self.test_machine)
xml3 = """<compiler><MPI_PATH>${MPI_LIB_NAME}</MPI_PATH></compiler>"""
err_msg = ".* has bad <var> references."
with self.assertRaisesRegexp(SystemExit, err_msg):
with self.assertRaisesRegex(SystemExit, err_msg):
self.xml_to_tester(xml1+xml2+xml3)


Expand Down

0 comments on commit 170bba5

Please sign in to comment.