Skip to content

Commit

Permalink
Fixes to pyutilib.misc config tests
Browse files Browse the repository at this point in the history
1. Hard-coding the test wrapping length, to ensure that tests pass
consistently.

2. Removing print() statements in tests, to make them less verbose.
  • Loading branch information
whart222 committed Nov 27, 2019
1 parent 12fddaf commit 65f2b70
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pyutilib/misc/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _display(obj, *args):
class Test(unittest.TestCase):

def setUp(self):
os.environ["COLUMNS"] = "80"
self.config = config = ConfigBlock(
"Basic configuration for Flushing models", implicit=True)
net = config.declare('network', ConfigBlock())
Expand Down Expand Up @@ -148,6 +149,8 @@ def setUp(self):
},
},
}
def tearDown(self):
del os.environ["COLUMNS"]

# Utility method for generating and validating a template description
def _validateTemplate(self, config, reference_template, **kwds):
Expand Down Expand Up @@ -892,7 +895,7 @@ def test_generate_documentation(self):
test = self.config.generate_documentation()
OUTPUT.write(test)
OUTPUT.close()
print(test)
#print(test)
self.assertFalse(
pyutilib.misc.comparison.compare_file(oFile, oFile[:-4] + '.txt')[
0])
Expand Down Expand Up @@ -1011,7 +1014,7 @@ def test_generate_custom_documentation(self):
item_body= "item{%s}\n",
item_end= "endItem{%s}\n",
)
print(test)
#print(test)
self.assertEqual(test, reference)

test = self.config.generate_documentation(
Expand All @@ -1027,7 +1030,7 @@ def test_generate_custom_documentation(self):
stripped_reference = re.sub('\{[^\}]*\}','',reference)
else:
stripped_reference = re.sub('\{[^\}]*\}','',reference,flags=re.M)
print(test)
#print(test)
self.assertEqual(test, stripped_reference)

def test_block_get(self):
Expand Down Expand Up @@ -1165,7 +1168,7 @@ def test_block_items(self):
self.assertFalse(itemiter is self.config['scenario'].iteritems())

def test_value(self):
print(self.config.value())
#print(self.config.value())
self.assertEqual(self._reference, self.config.value())

def test_list_manipulation(self):
Expand Down Expand Up @@ -1283,7 +1286,7 @@ def test_argparse_help(self):
parser = argparse.ArgumentParser(prog='tester')
self.config.initialize_argparse(parser)
help = parser.format_help()
print(help)
#print(help)
self.assertEqual(
"""usage: tester [-h] [--epanet-file EPANET] [--scenario-file STR] [--merlion]
Expand All @@ -1308,7 +1311,8 @@ def test_argparse_help_implicit_disable(self):
parser = argparse.ArgumentParser(prog='tester')
self.config.initialize_argparse(parser)
help = parser.format_help()
print(help)
#print(help)
self.maxDiff = None
self.assertEqual(
"""usage: tester [-h] [--epanet-file EPANET] [--scenario-file STR] [--merlion]
[--disable-epanet]
Expand Down Expand Up @@ -1380,7 +1384,7 @@ def test_argparse_subparsers(self):
self.config.initialize_argparse(parser)

help = parser.format_help()
print(help)
#print(help)
self.assertEqual(
"""usage: tester [-h] [--epanet-file EPANET] [--scenario-file STR] [--merlion]
{flushing} ...
Expand All @@ -1399,7 +1403,7 @@ def test_argparse_subparsers(self):
""", help)

help = subp.format_help()
print(help)
#print(help)
self.assertEqual(
"""usage: tester flushing [-h] [--feasible-nodes STR] [--infeasible-nodes STR]
[--duration FLOAT]
Expand Down

0 comments on commit 65f2b70

Please sign in to comment.