Skip to content

Commit

Permalink
Add Python 2.6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
DasIch committed Apr 1, 2012
1 parent cb7d797 commit a39cf3b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
28 changes: 14 additions & 14 deletions awwparse/__init__.py
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion awwparse/testsuite/__init__.py
Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions awwparse/testsuite/types.py
Expand Up @@ -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")])}
)


Expand Down Expand Up @@ -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])],
[
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion awwparse/utils.py
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion 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.