From ca821918408319e7161c422cde45c21ba4130c3f Mon Sep 17 00:00:00 2001
From: Stefan Bienert <stefan.bienert@unibas.ch>
Date: Thu, 27 Aug 2015 14:49:32 +0200
Subject: [PATCH] Fixed some tests

---
 core/tests/test_pm3argparse.py | 55 ++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/core/tests/test_pm3argparse.py b/core/tests/test_pm3argparse.py
index 7a5943ea..d2101615 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
-- 
GitLab