Skip to content
Snippets Groups Projects
Commit 925d6b9a authored by Studer Gabriel's avatar Studer Gabriel
Browse files

fix unit test

pm3_argparse explicitely checks for expected output. That output may
differ for different argparse versions. The fix reduces the checks
to certain key elements.
parent fbdf7fd2
No related branches found
No related tags found
No related merge requests found
...@@ -90,36 +90,29 @@ class PM3ArgParseTests(unittest.TestCase): ...@@ -90,36 +90,29 @@ class PM3ArgParseTests(unittest.TestCase):
with self.assertRaises(SystemExit) as ecd: with self.assertRaises(SystemExit) as ecd:
parser.Parse(['--help']) parser.Parse(['--help'])
self.assertEqual(ecd.exception.code, 0) self.assertEqual(ecd.exception.code, 0)
self.assertEqual(ecd.exception.code, 0)
if sys.version_info >= (3,11): # output of self.log.messages['SCRIPT'] depends on version of argparse
self.assertEqual(self.log.messages['SCRIPT'], # module observed output:
['usage: test_pm3argparse.py [-h]\n\nTesting our '+ #
'own little argument parser.\n\noptions:\n -h, '+ # 'usage: test_pm3argparse.py [-h]\n\nTesting our '+
'--help show this help message and exit']) # 'own little argument parser.\n\noptions:\n -h, '+
else: # '--help show this help message and exit'
self.assertEqual(self.log.messages['SCRIPT'], #
['usage: test_pm3argparse.py [-h]\n\nTesting our '+ # 'usage: test_pm3argparse.py [-h]\n\nTesting our '+
'own little argument parser.\n\noptional '+ # 'own little argument parser.\n\noptional '+
'arguments:\n -h, --help show this help '+ # 'arguments:\n -h, --help show this help '+
'message and exit']) # 'message and exit'
#
# we just check whether it starts with "usage: "
self.assertTrue(self.log.messages['SCRIPT'][0].startswith("usage: "))
self.log.messages = dict() self.log.messages = dict()
parser = pm3argparse.PM3ArgumentParser(__doc__, action=True) parser = pm3argparse.PM3ArgumentParser(__doc__, action=True)
with self.assertRaises(SystemExit) as ecd: with self.assertRaises(SystemExit) as ecd:
parser.Parse(['--help']) parser.Parse(['--help'])
self.assertEqual(ecd.exception.code, 0) self.assertEqual(ecd.exception.code, 0)
if sys.version_info >= (3,11): # see long comment above...
self.assertEqual(self.log.messages['SCRIPT'], self.assertTrue(self.log.messages['SCRIPT'][0].startswith("usage: "))
['usage: t_pm3argparse.py [-h]\n\nTesting our '+
'own little argument parser.\n\noptions:\n '+
'-h, --help show this help message and exit'])
else:
self.assertEqual(self.log.messages['SCRIPT'],
['usage: t_pm3argparse.py [-h]\n\nTesting our '+
'own little argument parser.\n\noptional '+
'arguments:\n -h, --help show this help '+
'message and exit'])
def testDescription(self): def testDescription(self):
parser = pm3argparse.PM3ArgumentParser(action=False, parser = pm3argparse.PM3ArgumentParser(action=False,
...@@ -127,16 +120,8 @@ class PM3ArgParseTests(unittest.TestCase): ...@@ -127,16 +120,8 @@ class PM3ArgParseTests(unittest.TestCase):
with self.assertRaises(SystemExit) as ecd: with self.assertRaises(SystemExit) as ecd:
parser.Parse(['--help']) parser.Parse(['--help'])
self.assertEqual(ecd.exception.code, 0) self.assertEqual(ecd.exception.code, 0)
if sys.version_info >= (3,11): tmp = ''.join(self.log.messages['SCRIPT'])
self.assertEqual(self.log.messages['SCRIPT'], self.assertTrue(tmp.find("This is a test")!=-1)
['usage: test_pm3argparse.py [-h]\n\nThis is a '+
'test.\n\noptions:\n -h, --help '+
'show this help message and exit'])
else:
self.assertEqual(self.log.messages['SCRIPT'],
['usage: test_pm3argparse.py [-h]\n\nThis is a '+
'test.\n\noptional arguments:\n -h, --help '+
'show this help message and exit'])
def testAddAlignmentNoFileArg(self): def testAddAlignmentNoFileArg(self):
# check failure on missing file argument # check failure on missing file argument
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment