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
Branches
Tags 3.2.1
No related merge requests found
......@@ -90,36 +90,29 @@ class PM3ArgParseTests(unittest.TestCase):
with self.assertRaises(SystemExit) as ecd:
parser.Parse(['--help'])
self.assertEqual(ecd.exception.code, 0)
self.assertEqual(ecd.exception.code, 0)
if sys.version_info >= (3,11):
self.assertEqual(self.log.messages['SCRIPT'],
['usage: test_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: test_pm3argparse.py [-h]\n\nTesting our '+
'own little argument parser.\n\noptional '+
'arguments:\n -h, --help show this help '+
'message and exit'])
# output of self.log.messages['SCRIPT'] depends on version of argparse
# module observed output:
#
# 'usage: test_pm3argparse.py [-h]\n\nTesting our '+
# 'own little argument parser.\n\noptions:\n -h, '+
# '--help show this help message and exit'
#
# 'usage: test_pm3argparse.py [-h]\n\nTesting our '+
# 'own little argument parser.\n\noptional '+
# 'arguments:\n -h, --help show this help '+
# 'message and exit'
#
# we just check whether it starts with "usage: "
self.assertTrue(self.log.messages['SCRIPT'][0].startswith("usage: "))
self.log.messages = dict()
parser = pm3argparse.PM3ArgumentParser(__doc__, action=True)
with self.assertRaises(SystemExit) as ecd:
parser.Parse(['--help'])
self.assertEqual(ecd.exception.code, 0)
if sys.version_info >= (3,11):
self.assertEqual(self.log.messages['SCRIPT'],
['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'])
# see long comment above...
self.assertTrue(self.log.messages['SCRIPT'][0].startswith("usage: "))
def testDescription(self):
parser = pm3argparse.PM3ArgumentParser(action=False,
......@@ -127,16 +120,8 @@ class PM3ArgParseTests(unittest.TestCase):
with self.assertRaises(SystemExit) as ecd:
parser.Parse(['--help'])
self.assertEqual(ecd.exception.code, 0)
if sys.version_info >= (3,11):
self.assertEqual(self.log.messages['SCRIPT'],
['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'])
tmp = ''.join(self.log.messages['SCRIPT'])
self.assertTrue(tmp.find("This is a test")!=-1)
def testAddAlignmentNoFileArg(self):
# 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