From b20a29fa2ac1fbd9923063458c5028c104e95ae9 Mon Sep 17 00:00:00 2001
From: Stefan Bienert <stefan.bienert@unibas.ch>
Date: Tue, 18 Aug 2015 13:38:52 +0200
Subject: [PATCH] Made description mandatory

---
 core/doc/helper.rst            |  4 ++--
 core/pymod/core/pm3argparse.py | 10 ++++-----
 core/tests/test_pm3argparse.py | 40 +++++++++++++++++++---------------
 3 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/core/doc/helper.rst b/core/doc/helper.rst
index 3af02dfc..93ea65eb 100644
--- a/core/doc/helper.rst
+++ b/core/doc/helper.rst
@@ -53,7 +53,7 @@ File Tests
   (fh, fn) = tempfile.mkstemp(suffix='.pdb')
   os.close(fh)
 
-  p = pm3argparse.PM3ArgumentParser()
+  p = pm3argparse.PM3ArgumentParser('Dummy')
   p.add_argument('file', type=str)
   opts = p.Parse([fn])
 
@@ -71,7 +71,7 @@ File Tests
   from promod3.core import helper
   from promod3.core import pm3argparse
 
-  p = pm3argparse.PM3ArgumentParser()
+  p = pm3argparse.PM3ArgumentParser(__doc__)
   p.add_argument('file', type=str)
   opts = p.Parse()
 
diff --git a/core/pymod/core/pm3argparse.py b/core/pymod/core/pm3argparse.py
index 9ba70772..8233e289 100644
--- a/core/pymod/core/pm3argparse.py
+++ b/core/pymod/core/pm3argparse.py
@@ -63,10 +63,14 @@ class PM3ArgumentParser(argparse.ArgumentParser):
 
     :type: :class:`bool`
     """
-    def __init__(self, action=True, description=None):
+    def __init__(self, description, action=True):
         """
         Create a new instance of :class:`~pm3argparse.PM3ArgumentParser`.
 
+        :param description: Help text for this script, handed down to
+                            |descattr|_ of |argpinit|_.
+        :type description: :class:`str`
+
         :param action: Indicates if the calling script is a |project| action.
                        This influences |progattr|_ of
                        :class:`~argparse.ArgumentParser` by clipping of the
@@ -75,10 +79,6 @@ class PM3ArgumentParser(argparse.ArgumentParser):
                        :class:`~argparse.ArgumentParser` kicks in.
         :type action: :class:`bool`
 
-        :param description: Help text for this script, handed down to
-                            |descattr|_ of |argpinit|_.
-        :type description: :class:`str`
-
         :returns: :class:`argparse.ArgumentParser`.
         """
         prog = None
diff --git a/core/tests/test_pm3argparse.py b/core/tests/test_pm3argparse.py
index 117b32fd..cc2f4aed 100644
--- a/core/tests/test_pm3argparse.py
+++ b/core/tests/test_pm3argparse.py
@@ -1,3 +1,7 @@
+"""
+Testing our own little argument parser.
+"""
+
 import unittest
 import ost
 from promod3.core import pm3argparse
@@ -30,7 +34,7 @@ class PM3ArgParseTests(unittest.TestCase):
         ost.PopLogSink()
 
     def testUnrecognisedArguments(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         with self.assertRaises(SystemExit) as ecd:
             parser.Parse(['-x'])
         self.assertEqual(ecd.exception.code, 2)
@@ -40,22 +44,24 @@ class PM3ArgParseTests(unittest.TestCase):
                           'arguments: -x'])
 
     def testActionSwitch(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         with self.assertRaises(SystemExit) as ecd:
             parser.Parse(['--help'])
         self.assertEqual(ecd.exception.code, 0)
         self.assertEqual(self.log.messages['SCRIPT'],
-                         ['usage: test_pm3argparse.py [-h]\n\noptional '+
+                         ['usage: test_pm3argparse.py [-h]\n\nTesting our '+
+                          'own little argument parser.\n\noptional '+
                           'arguments:\n  -h, --help  show this help message '+
                           'and exit'])
 
         self.log.messages = dict()
-        parser = pm3argparse.PM3ArgumentParser(action=True)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=True)
         with self.assertRaises(SystemExit) as ecd:
             parser.Parse(['--help'])
         self.assertEqual(ecd.exception.code, 0)
         self.assertEqual(self.log.messages['SCRIPT'],
-                         ['usage: t_pm3argparse.py [-h]\n\noptional '+
+                         ['usage: t_pm3argparse.py [-h]\n\nTesting our own '+
+                          'little argument parser.\n\noptional '+
                           'arguments:\n  -h, --help  show this help message '+
                           'and exit'])
 
@@ -74,7 +80,7 @@ class PM3ArgParseTests(unittest.TestCase):
     def testAddAlignemntNoTrgPfx(self):
         # checking that we fail on missing 'trg:' prefix for arguments of
         # --fasta
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -88,7 +94,7 @@ class PM3ArgParseTests(unittest.TestCase):
     def testAddAlignemntEmptyTrgPfx(self):
         # checking that we fail on empty 'trg:' prefix for arguments of
         # --fasta
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -101,7 +107,7 @@ class PM3ArgParseTests(unittest.TestCase):
     def testAddAlignemntSwapTrgPfx(self):
         # checking that we fail on empty 'trg:' prefix for arguments of
         # --fasta
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -113,7 +119,7 @@ class PM3ArgParseTests(unittest.TestCase):
 
     def testAddAlignmentNoFile(self):
         # check that we throw an error if a non-exisiting file is given
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -124,7 +130,7 @@ class PM3ArgParseTests(unittest.TestCase):
 
     def testAddAlignmentEmpty(self):
         # we want to fail if we get an empty FastA file
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -135,7 +141,7 @@ class PM3ArgParseTests(unittest.TestCase):
                          "wrong format: data/fasta/alignment.fas")
 
     def testAddAlignmentToMany(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -146,7 +152,7 @@ class PM3ArgParseTests(unittest.TestCase):
                          "more than 2 sequences.")
 
     def testAddAlignmentMissingTargetName(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -157,7 +163,7 @@ class PM3ArgParseTests(unittest.TestCase):
                          "found in the alignment.")
 
     def testAddAlignmentDifferentSeqLens(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         with self.assertRaises(SystemExit) as ecd:
@@ -168,7 +174,7 @@ class PM3ArgParseTests(unittest.TestCase):
                          "alignment have different length.")
 
     def testAddAlignmentGzipIn(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         opts = parser.Parse(['--fasta', 'trg:target',
@@ -197,7 +203,7 @@ class PM3ArgParseTests(unittest.TestCase):
                          'YHQMTAPLIGYYYYSKEAEAGNTKYAKVDGTKPV---AEVRADLEK\n')
 
     def testAddAlignmentSwitchSeqs(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         opts = parser.Parse(['--fasta', 'trg:target',
@@ -209,7 +215,7 @@ class PM3ArgParseTests(unittest.TestCase):
                          'DDQEETVRKRLVEYHQMTAPLL--YYYYKEAEAGNTKYAKVDGTKPVAEV'+
                          'RADLEKILG')
 
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         opts = parser.Parse(['--fasta', 'trg:target',
@@ -222,7 +228,7 @@ class PM3ArgParseTests(unittest.TestCase):
                          'RADLEKILG')
 
     def testAddAlignment(self):
-        parser = pm3argparse.PM3ArgumentParser(action=False)
+        parser = pm3argparse.PM3ArgumentParser(__doc__, action=False)
         parser.AddAlignment()
         parser.AssembleParser()
         opts = parser.Parse(['--fasta', 'trg:target',
-- 
GitLab