def test_12(self): """TestCmnCmdOpts.test_12(): use of CmnCmdOpts.argParser() and adding scale option as a list of integers.""" myP = CmnCmdOpts.argParser("Description", "Program", "Version") myP.add_argument( "-s", "--scale", action="append", type=int, dest="scales", default=[], help="Scale of X axis to use (additive). [default: []].") myNs = myP.parse_args([]) self.assertEqual([], myNs.scales) myNs = myP.parse_args('-s 47'.split()) self.assertEqual([ 47, ], myNs.scales) myNs = myP.parse_args('-s 47 --scale=49'.split()) self.assertEqual([47, 49], myNs.scales) try: print() myNs = myP.parse_args('-s WTF'.split()) self.fail('SystemExit not raised.') except SystemExit: pass
def test_01(self): """TestCmnCmdOpts.test_01(): basic use of CmnCmdOpts.argParser().""" myP = CmnCmdOpts.argParser("Description", "Program", "Version") myNs = myP.parse_args() # print() # print(myNs) self.assertEqual(CmnCmdOpts.DEFAULT_OPT_MP_JOBS, myNs.jobs) self.assertEqual(CmnCmdOpts.DEFAULT_OPT_LOG_LEVEL, myNs.logLevel) self.assertFalse(myNs.keepGoing)
def test_05(self): """TestCmnCmdOpts.test_05(): use of --version.""" myP = CmnCmdOpts.argParser("Description of the program", "PROG", version="v0.1.3rc4") try: print() myNs = myP.parse_args(['--version',]) self.fail('SystemExit not raised: %s' % myNs) except SystemExit: pass
def test_04(self): """TestCmnCmdOpts.test_04(): use of -h with minimal parser creation.""" myP = CmnCmdOpts.argParser("Description of the program only, no program name, no version") try: print() myNs = myP.parse_args(['-h',]) self.fail('SystemExit not raised: %s' % myNs) except SystemExit: pass
def test_03(self): """TestCmnCmdOpts.test_03(): use of --help.""" myP = CmnCmdOpts.argParser("Description of the program", "Name of the program", "0.1.3rc4") try: print() myNs = myP.parse_args(['--help',]) self.fail('SystemExit not raised: %s' % myNs) except SystemExit: pass
def test_07(self): """TestCmnCmdOpts.test_06(): use of --version minimal parser creation should fail with unrecognised arguments.""" myP = CmnCmdOpts.argParser("Description of the program only, no program name, no version") try: print() myNs = myP.parse_args(['--version',]) self.fail('SystemExit not raised: %s' % myNs) except SystemExit: pass
def test_10(self): """TestCmnCmdOpts.test_10(): use of CmnCmdOpts.argParser() and adding a list option.""" myP = CmnCmdOpts.argParser("Description", "Program", "Version") myP.add_argument( "-I", "--INCLUDE", action="append", dest="includes", default=[], help="Include paths (additive). [default: %default]", ) myNs = myP.parse_args([]) self.assertEqual([], myNs.includes) myNs = myP.parse_args(['-I', '123', '--INCLUDE', '4']) # print() # print(myNs) self.assertEqual(['123', '4',], myNs.includes)
def test_11(self): """TestCmnCmdOpts.test_11(): use of CmnCmdOpts.argParser() and adding a enumerated option with choices.""" myP = CmnCmdOpts.argParser("Description", "Program", "Version") myP.add_argument( "-f", "--file-type", choices=['LAS', 'LIS', 'AUTO'], ) myNs = myP.parse_args([]) self.assertTrue(myNs.file_type is None) myNs = myP.parse_args('-f LIS'.split()) self.assertEqual('LIS', myNs.file_type) try: print() myNs = myP.parse_args('-f WTF'.split()) self.fail('SystemExit not raised.') except SystemExit: pass