diff --git a/core/tests/test_pm3argparse.py b/core/tests/test_pm3argparse.py index 7a5943ea15ed188a15689e3b9f43d4a6d8eae7a6..d2101615d3955a6937fffcaa46a599ce67b0e07b 100644 --- a/core/tests/test_pm3argparse.py +++ b/core/tests/test_pm3argparse.py @@ -295,11 +295,11 @@ class PM3ArgParseTests(unittest.TestCase): self.assertEqual(ecd.exception.code, 2) self.assertEqual(len(self.log.messages['ERROR']), 2) self.assertEqual(len(self.log.messages['ERROR']), 2) - self.assertEqual(self.log.messages['ERROR'][0], - 'usage: test_pm3argparse.py [-h] (-f trg:<NAME> '+ - '<FILE> | -j <OBJECT>|<FILE>)', - 'test_pm3argparse.py: error: one of the arguments '+ - '-f/--fasta -j/--json is required') + self.assertEqual(self.log.messages['ERROR'], + ['usage: test_pm3argparse.py [-h] (-f trg:<NAME> '+ + '<FILE> | -j <OBJECT>|<FILE>)', + 'test_pm3argparse.py: error: one of the arguments '+ + '-f/--fasta -j/--json is required']) def testAddAlignmentFastaAndJson(self): # testing that --fasta and --json DO NOT work together @@ -311,11 +311,11 @@ class PM3ArgParseTests(unittest.TestCase): '--json', 'foo']) self.assertEqual(ecd.exception.code, 2) self.assertEqual(len(self.log.messages['ERROR']), 2) - self.assertEqual(self.log.messages['ERROR'][0], - 'usage: test_pm3argparse.py [-h] (-f trg:<NAME> '+ - '<FILE> | -j <OBJECT>|<FILE>)', - 'test_pm3argparse.py: error: argument -j/--json: '+ - 'not allowed with argument -f/--fasta') + self.assertEqual(self.log.messages['ERROR'], + ['usage: test_pm3argparse.py [-h] (-f trg:<NAME> '+ + '<FILE> | -j <OBJECT>|<FILE>)', + 'test_pm3argparse.py: error: argument -j/--json: '+ + 'not allowed with argument -f/--fasta']) def testAddAlignmentJsonMulti(self): # passing --json multiple times is not allowed @@ -327,11 +327,36 @@ class PM3ArgParseTests(unittest.TestCase): parser.Parse(['--json', 'foo', '--json', 'bar']) self.assertEqual(ecd.exception.code, 2) self.assertEqual(len(self.log.messages['ERROR']), 2) - self.assertEqual(self.log.messages['ERROR'][0], - 'usage: test_pm3argparse.py [-h] (-f trg:<NAME> '+ - '<FILE> | -j <OBJECT>|<FILE>)', - 'test_pm3argparse.py: error: argument -j/--json: '+ - 'may only be used once.') + self.assertEqual(self.log.messages['ERROR'], + ['usage: test_pm3argparse.py [-h] (-f trg:<NAME> '+ + '<FILE> | -j <OBJECT>|<FILE>)', + 'test_pm3argparse.py: error: argument -j/--json: '+ + 'may only be used once.']) + + def testAddAlignmentJsonNoArg(self): + # make sure --json always needs an argument + parser = pm3argparse.PM3ArgumentParser(__doc__, action=False) + parser.AddAlignment() + parser.AssembleParser() + with self.assertRaises(SystemExit) as ecd: + parser.Parse(['--json']) + self.assertEqual(ecd.exception.code, 2) + self.assertEqual(len(self.log.messages['ERROR']), 2) + self.assertEqual(self.log.messages['ERROR'], + ['usage: test_pm3argparse.py [-h] (-f trg:<NAME> '+ + '<FILE> | -j <OBJECT>|<FILE>)', + 'test_pm3argparse.py: error: argument -j/--json: '+ + 'expected one argument']) + + def testAddAlignmentJsonWorkingFile(self): + # positive test: everything works! + parser = pm3argparse.PM3ArgumentParser(__doc__, action=False) + parser.AddAlignment() + parser.AssembleParser() + parser.Parse(['--json', 'foo bar']) + +# test that json always needs an argument +# test json with sth that is not a file and not a JSON object if __name__ == "__main__": from ost import testutils