Commit 698a18aa authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 78586-78593 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78586 | benjamin.peterson | 2010-03-02 16:03:03 -0600 (Tue, 02 Mar 2010) | 1 line

  remove coding cookie as mandated by PEP 8
........
  r78587 | benjamin.peterson | 2010-03-02 16:05:59 -0600 (Tue, 02 Mar 2010) | 1 line

  set svn:eol-style
........
  r78588 | benjamin.peterson | 2010-03-02 16:08:40 -0600 (Tue, 02 Mar 2010) | 1 line

  remove another coding cookie
........
  r78589 | georg.brandl | 2010-03-02 16:17:38 -0600 (Tue, 02 Mar 2010) | 1 line

  Add some x-refs.
........
  r78590 | benjamin.peterson | 2010-03-02 16:20:10 -0600 (Tue, 02 Mar 2010) | 1 line

  enable running of argparse tests and fix two that failed in the new environment
........
  r78591 | benjamin.peterson | 2010-03-02 16:23:33 -0600 (Tue, 02 Mar 2010) | 1 line

  prevent warning filter adjustment from altering other tests
........
  r78592 | benjamin.peterson | 2010-03-02 16:24:30 -0600 (Tue, 02 Mar 2010) | 1 line

  use test_main() in __main__ section
........
  r78593 | benjamin.peterson | 2010-03-02 16:26:25 -0600 (Tue, 02 Mar 2010) | 1 line

  convert deprecated fail* methods to assert* variants
........
parent a988e422
This diff is collapsed.
# -*- coding: utf-8 -*- # Copyright 2006-2009 Steven J. Bethard <steven.bethard@gmail.com>.
# Copyright © 2006-2009 Steven J. Bethard <steven.bethard@gmail.com>.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may not # Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy # use this file except in compliance with the License. You may obtain a copy
......
# -*- coding: utf-8 -*- # Copyright 2006-2009 Steven J. Bethard <steven.bethard@gmail.com>.
# Copyright © 2006-2009 Steven J. Bethard <steven.bethard@gmail.com>.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may not # Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy # use this file except in compliance with the License. You may obtain a copy
...@@ -21,8 +19,11 @@ import sys ...@@ -21,8 +19,11 @@ import sys
import textwrap import textwrap
import tempfile import tempfile
import unittest import unittest
import warnings
import argparse import argparse
from test import support
try: try:
from StringIO import StringIO from StringIO import StringIO
except ImportError: except ImportError:
...@@ -44,29 +45,6 @@ except NameError: ...@@ -44,29 +45,6 @@ except NameError:
result.reverse() result.reverse()
return result return result
# silence Python 2.6 buggy warnings about Exception.message
if sys.version_info[:2] == (2, 6):
import warnings
warnings.filterwarnings(
action='ignore',
message='BaseException.message has been deprecated as of Python 2.6',
category=DeprecationWarning)
# silence warnings about version argument - these are expected
import warnings
warnings.filterwarnings(
action='ignore',
message='The "version" argument to ArgumentParser is deprecated.',
category=DeprecationWarning)
warnings.filterwarnings(
action='ignore',
message='The format_version method is deprecated',
category=DeprecationWarning)
warnings.filterwarnings(
action='ignore',
message='The print_version method is deprecated',
category=DeprecationWarning)
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
...@@ -1953,6 +1931,8 @@ class TestParentParsers(TestCase): ...@@ -1953,6 +1931,8 @@ class TestParentParsers(TestCase):
group.add_argument('-a', action='store_true') group.add_argument('-a', action='store_true')
group.add_argument('-b', action='store_true') group.add_argument('-b', action='store_true')
self.main_program = os.path.basename(sys.argv[0])
def test_single_parent(self): def test_single_parent(self):
parser = ErrorRaisingArgumentParser(parents=[self.wxyz_parent]) parser = ErrorRaisingArgumentParser(parents=[self.wxyz_parent])
self.assertEqual(parser.parse_args('-y 1 2 --w 3'.split()), self.assertEqual(parser.parse_args('-y 1 2 --w 3'.split()),
...@@ -2045,7 +2025,7 @@ class TestParentParsers(TestCase): ...@@ -2045,7 +2025,7 @@ class TestParentParsers(TestCase):
parser = ErrorRaisingArgumentParser(parents=parents) parser = ErrorRaisingArgumentParser(parents=parents)
parser_help = parser.format_help() parser_help = parser.format_help()
self.assertEqual(parser_help, textwrap.dedent('''\ self.assertEqual(parser_help, textwrap.dedent('''\
usage: test_argparse.py [-h] [-b B] [--d D] [--w W] [-y Y] a z usage: {} [-h] [-b B] [--d D] [--w W] [-y Y] a z
positional arguments: positional arguments:
a a
...@@ -2061,7 +2041,7 @@ class TestParentParsers(TestCase): ...@@ -2061,7 +2041,7 @@ class TestParentParsers(TestCase):
x: x:
-y Y -y Y
''')) '''.format(self.main_program)))
def test_groups_parents(self): def test_groups_parents(self):
parent = ErrorRaisingArgumentParser(add_help=False) parent = ErrorRaisingArgumentParser(add_help=False)
...@@ -2078,7 +2058,7 @@ class TestParentParsers(TestCase): ...@@ -2078,7 +2058,7 @@ class TestParentParsers(TestCase):
parser_help = parser.format_help() parser_help = parser.format_help()
self.assertEqual(parser_help, textwrap.dedent('''\ self.assertEqual(parser_help, textwrap.dedent('''\
usage: test_argparse.py [-h] [-w W] [-x X] [-y Y | -z Z] usage: {} [-h] [-w W] [-x X] [-y Y | -z Z]
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
...@@ -2090,7 +2070,7 @@ class TestParentParsers(TestCase): ...@@ -2090,7 +2070,7 @@ class TestParentParsers(TestCase):
-w W -w W
-x X -x X
''')) '''.format(self.main_program)))
# ============================== # ==============================
# Mutually exclusive group tests # Mutually exclusive group tests
...@@ -4201,6 +4181,30 @@ class TestImportStar(TestCase): ...@@ -4201,6 +4181,30 @@ class TestImportStar(TestCase):
for name in argparse.__all__: for name in argparse.__all__:
self.assertTrue(hasattr(argparse, name)) self.assertTrue(hasattr(argparse, name))
def test_main():
with warnings.catch_warnings():
# silence Python 2.6 buggy warnings about Exception.message
warnings.filterwarnings(
action='ignore',
message='BaseException.message has been deprecated as of'
'Python 2.6',
category=DeprecationWarning)
# silence warnings about version argument - these are expected
warnings.filterwarnings(
action='ignore',
message='The "version" argument to ArgumentParser is deprecated.',
category=DeprecationWarning)
warnings.filterwarnings(
action='ignore',
message='The format_version method is deprecated',
category=DeprecationWarning)
warnings.filterwarnings(
action='ignore',
message='The print_version method is deprecated',
category=DeprecationWarning)
support.run_unittest(__name__)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() test_main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment