Browse files

Add Python 2.6 support

  • Loading branch information...
1 parent cb7d797 commit a39cf3b0e3ec24c80f800b2ce4f6b448c69358a5 @DasIch committed Apr 1, 2012
Showing with 44 additions and 27 deletions.
  1. +14 −14 awwparse/__init__.py
  2. +4 −1 awwparse/testsuite/__init__.py
  3. +20 −10 awwparse/testsuite/types.py
  4. +1 −1 awwparse/utils.py
  5. +5 −1 tox.ini
View
28 awwparse/__init__.py
@@ -214,46 +214,46 @@ def option_prefixes(self):
"""
A set of all option name prefixes.
"""
- return {option.name_prefix for option in self.options.values()}
+ return set(option.name_prefix for option in self.options.values())
@property
def abbreviated_option_prefixes(self):
"""
A set of all abbreviated option name prefixes.
"""
- return {
+ return set(
option.abbreviation_prefix for option in self.options.values()
- }
+ )
@property
def option_shorts(self):
"""
A mapping of all abbreviated option argument names to options.
"""
- return {
- option.short: option for option in self.options.values()
+ return dict(
+ (option.short, option) for option in self.options.values()
if option.short is not None
- }
+ )
@property
def option_longs(self):
"""
A mapping of all complete option argument names to options.
"""
- return {
- option.long: option for option in self.options.values()
+ return dict(
+ (option.long, option) for option in self.options.values()
if option.long is not None
- }
+ )
@property
def defaults(self):
"""
A mapping of option names to option default values.
"""
- return {
- name: option.default for name, option in self.options.items()
+ return dict(
+ (name, option.default) for name, option in self.options.items()
if option.default is not missing
- }
+ )
def get_usage(self, arguments=None):
result = [] if arguments is None else arguments.trace[:-1]
@@ -754,14 +754,14 @@ def copy(self):
return option
def get_usage(self, using="short"):
- if using not in {"short", "long", "both"}:
+ if using not in set(["short", "long", "both"]):
raise ValueError(
"using has to be 'short', 'long' or 'both'; not %r" % using
)
if using == "both" and self.short and self.long:
caller = u("%s, %s") % (self.short, self.long)
elif (using == "short" and self.short or
- using in {"long", "both"} and not self.long):
+ using in set(["long", "both"]) and not self.long):
caller = self.short
else:
caller = self.long
View
5 awwparse/testsuite/__init__.py
@@ -8,7 +8,10 @@
"""
import re
import sys
-import unittest
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
import textwrap
from functools import wraps
from itertools import chain
View
30 awwparse/testsuite/types.py
@@ -95,7 +95,7 @@ def test_parse_and_store(self):
command.add_option("foo", Option("a", Set(String())))
self.assert_equal(
command.run(["-a", "foo", "-a", "bar"]),
- {"foo": {u("foo"), u("bar")}}
+ {"foo": set([u("foo"), u("bar")])}
)
@@ -227,7 +227,13 @@ def test_convert(self):
with self.assert_raises(UserTypeError):
floating.convert("1j")
- _parse_test = (
+
+class FloatTestCase(FloatingTestCaseMixin, TestCase):
+ type = Float
+ floating_type = float
+
+ test_parse = make_parse_test(
+ Float,
[(["1.0"], 1.0)],
[(["1.0", "2.0", "3.0"], [1.0, 2.0, 3.0])],
[
@@ -237,18 +243,22 @@ def test_convert(self):
)
-class FloatTestCase(FloatingTestCaseMixin, TestCase):
- type = Float
- floating_type = float
-
- test_parse = make_parse_test(Float, *FloatingTestCaseMixin._parse_test)
-
-
class DecimalTestCase(FloatingTestCaseMixin, TestCase):
type = Decimal
floating_type = decimal.Decimal
- test_parse = make_parse_test(Decimal, *FloatingTestCaseMixin._parse_test)
+ test_parse = make_parse_test(
+ Decimal,
+ [(["1.0"], decimal.Decimal("1.0"))],
+ [(
+ ["1.0", "2.0", "3.0"],
+ [decimal.Decimal("1.0"), decimal.Decimal("2.0"), decimal.Decimal("3.0")]
+ )],
+ [
+ (["1.0"], [decimal.Decimal("1.0")]),
+ (["1.0", "2.0"], [decimal.Decimal("1.0"), decimal.Decimal("2.0")])
+ ]
+ )
class ComplexTestCase(TestCase):
View
2 awwparse/utils.py
@@ -37,7 +37,7 @@ def set_attributes_from_kwargs(object, kwargs, defaults):
"""
set_attributes(
object,
- {key: kwargs.pop(key, value) for key, value in defaults.items()}
+ dict((key, kwargs.pop(key, value)) for key, value in defaults.items())
)
if kwargs:
raise TypeError(
View
6 tox.ini
@@ -1,5 +1,9 @@
[tox]
-envlist=py27,py32,pypy
+envlist=py26,py27,pypy,py32
[testenv]
commands=python run-tests.py
+
+[testenv:py26]
+deps=unittest2
+commands=python run-tests.py

0 comments on commit a39cf3b

Please sign in to comment.