From f32f23642634e835c710606ec8fa38552f84934a Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Sun, 19 Jul 2015 22:34:21 +0530 Subject: Fix #137 --- src/mailman/bin/mailman.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mailman/bin/mailman.py b/src/mailman/bin/mailman.py index 3865fef19..828a80461 100644 --- a/src/mailman/bin/mailman.py +++ b/src/mailman/bin/mailman.py @@ -88,7 +88,8 @@ def main(): command.add(parser, command_parser) command_parser.set_defaults(func=command.process) args = parser.parse_args() - if len(args.__dict__) == 0: + print(args) + if len(args.__dict__) == 1: # No arguments or subcommands were given. parser.print_help() parser.exit() -- cgit v1.2.3-70-g09d2 From 19bf129d047d14556bf4afdaa5a7de429d77c5a2 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Tue, 21 Jul 2015 18:33:48 +0530 Subject: remove a print statement committed accidentally --- src/mailman/bin/mailman.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mailman/bin/mailman.py b/src/mailman/bin/mailman.py index 828a80461..daff81e94 100644 --- a/src/mailman/bin/mailman.py +++ b/src/mailman/bin/mailman.py @@ -88,7 +88,6 @@ def main(): command.add(parser, command_parser) command_parser.set_defaults(func=command.process) args = parser.parse_args() - print(args) if len(args.__dict__) == 1: # No arguments or subcommands were given. parser.print_help() -- cgit v1.2.3-70-g09d2 From 46b27396a8ecb0389729bd0f5abf0c930a50f6bc Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Mon, 3 Aug 2015 19:31:17 +0530 Subject: fix according to comments from barry --- src/mailman/bin/mailman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mailman/bin/mailman.py b/src/mailman/bin/mailman.py index daff81e94..fd8eb914e 100644 --- a/src/mailman/bin/mailman.py +++ b/src/mailman/bin/mailman.py @@ -88,7 +88,7 @@ def main(): command.add(parser, command_parser) command_parser.set_defaults(func=command.process) args = parser.parse_args() - if len(args.__dict__) == 1: + if len(args.__dict__) <= 1: # No arguments or subcommands were given. parser.print_help() parser.exit() -- cgit v1.2.3-70-g09d2 From 9a6270ec989b62f7716952a9a3ff8465ca9f1e31 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Mon, 3 Aug 2015 23:59:08 +0530 Subject: add tests for mailman command --- src/mailman/bin/tests/test_mailman.py | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/mailman/bin/tests/test_mailman.py diff --git a/src/mailman/bin/tests/test_mailman.py b/src/mailman/bin/tests/test_mailman.py new file mode 100644 index 000000000..0c9062787 --- /dev/null +++ b/src/mailman/bin/tests/test_mailman.py @@ -0,0 +1,42 @@ +# Copyright (C) 2015 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see . + +"""Test mailman command utilities.""" + +__all__ = [ + 'TestMailmanCommand', +] + +import sys +import unittest + +from io import StringIO +from mock import patch, MagicMock + +from mailman.bin.mailman import main + + + +class TestMailmanCommand(unittest.TestCase): + + def test_mailman_command__without_subscommnad_prints_help(self): + testargs = ['mailman'] + output = StringIO() + with patch('sys.argv', testargs), patch('sys.stdout', output): + with self.assertRaises(SystemExit) as cm: + main() + self.assertIn('usage', output.getvalue()) -- cgit v1.2.3-70-g09d2 From 022bdf8b5a07c412461851ea7b758cf96eb7f0a1 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 13 Aug 2015 20:34:59 -0400 Subject: Style cleanup. --- src/mailman/bin/tests/test_mailman.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mailman/bin/tests/test_mailman.py b/src/mailman/bin/tests/test_mailman.py index 0c9062787..8c5a3396b 100644 --- a/src/mailman/bin/tests/test_mailman.py +++ b/src/mailman/bin/tests/test_mailman.py @@ -19,24 +19,24 @@ __all__ = [ 'TestMailmanCommand', -] + ] + -import sys import unittest from io import StringIO -from mock import patch, MagicMock - +from mock import patch from mailman.bin.mailman import main class TestMailmanCommand(unittest.TestCase): - - def test_mailman_command__without_subscommnad_prints_help(self): + def test_mailman_command_without_subcommand_prints_help(self): + # Issue #137: Running `mailman` without a subcommand raises an + # AttributeError. testargs = ['mailman'] output = StringIO() with patch('sys.argv', testargs), patch('sys.stdout', output): - with self.assertRaises(SystemExit) as cm: + with self.assertRaises(SystemExit): main() self.assertIn('usage', output.getvalue()) -- cgit v1.2.3-70-g09d2