From 92cebe7f52229b1cbf1dd8496e7c0640365d4bc8 Mon Sep 17 00:00:00 2001 From: Alejandro Barrera Date: Thu, 5 May 2016 16:02:20 -0400 Subject: [PATCH 1/2] Avoid type argument when adding boolean arguments --- cwltool/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cwltool/main.py b/cwltool/main.py index 1c502c508..79107306c 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -285,8 +285,10 @@ def generate_parser(toolparser, tool, namemap): _logger.debug(u"Can't make command line argument from %s", inptype) return None - toolparser.add_argument(flag + name, required=required, - help=ahelp, action=action, type=atype, default=default) + argument_kwargs = {'required': required, 'help': ahelp, 'action': action, 'default': default} + if inptype != "boolean": + argument_kwargs['type'] = atype + toolparser.add_argument(flag + name, **argument_kwargs) return toolparser From 6fa9a2b5680a9b304aa78a40141405d475e67d60 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Thu, 5 May 2016 13:47:00 -0700 Subject: [PATCH 2/2] add test for boolean type error --- cwltool/main.py | 9 ++++++--- tests/test_toolargparse.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cwltool/main.py b/cwltool/main.py index 79107306c..9ea819598 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -285,10 +285,13 @@ def generate_parser(toolparser, tool, namemap): _logger.debug(u"Can't make command line argument from %s", inptype) return None - argument_kwargs = {'required': required, 'help': ahelp, 'action': action, 'default': default} if inptype != "boolean": - argument_kwargs['type'] = atype - toolparser.add_argument(flag + name, **argument_kwargs) + typekw = { 'type': atype } + else: + typekw = {} + + toolparser.add_argument(flag + name, required=required, + help=ahelp, action=action, default=default, **typekw) return toolparser diff --git a/tests/test_toolargparse.py b/tests/test_toolargparse.py index 7504280ed..29bfeb34c 100644 --- a/tests/test_toolargparse.py +++ b/tests/test_toolargparse.py @@ -24,6 +24,24 @@ class ToolArgparse(unittest.TestCase): glob: test.txt stdout: test.txt baseCommand: [cat] +''' + + script2=''' +#!/usr/bin/env cwl-runner +cwlVersion: 'cwl:draft-3' +class: CommandLineTool +inputs: + - id: bdg + type: "boolean" +outputs: + - id: output + type: File + outputBinding: + glob: foo +baseCommand: + - echo + - "ff" +stdout: foo ''' def test_help(self): @@ -31,3 +49,12 @@ def test_help(self): f.write(self.script) f.flush() self.assertEquals(main([f.name, '--input', 'README.rst']), 0) + + def test_bool(self): + with NamedTemporaryFile() as f: + f.write(self.script2) + f.flush() + try: + self.assertEquals(main([f.name, '--help']), 0) + except SystemExit as e: + self.assertEquals(e.code, 0)