Permalink
Browse files

Update mws (and tests) to by py26 compatible

Use "{0} {1}" instead of "{} {}", use tests.unit.unittest
to account for python2.6 unittest2 vs. python2.7 unittest
module.
  • Loading branch information...
1 parent 586d0d7 commit 2777702ea96ea2ef6dd8b075f448029236aa5286 @jamesls jamesls committed Jun 18, 2012
Showing with 43 additions and 45 deletions.
  1. +19 −19 boto/mws/connection.py
  2. +3 −3 boto/mws/exception.py
  3. +10 −11 boto/mws/response.py
  4. +11 −12 tests/integration/mws/test.py
@@ -65,7 +65,7 @@ def wrapper(self, *args, **kw):
kw[newkey + str(i + 1)] = kw[key][i]
kw.pop(key)
return func(self, *args, **kw)
- wrapper.__doc__ = "{}\nLists: {}".format(func.__doc__,
+ wrapper.__doc__ = "{0}\nLists: {1}".format(func.__doc__,
', '.join(fields))
return add_attrs_from(func, to=wrapper)
return decorator
@@ -77,7 +77,7 @@ def decorator(func):
def wrapper(*args, **kw):
if filter(lambda x: not x in kw, (field, 'content_type')):
- message = "{} requires {} and content_type arguments for " \
+ message = "{0} requires {1} and content_type arguments for " \
"building HTTP body".format(func.action, field)
raise KeyError(message)
kw['body'] = kw.pop(field)
@@ -86,8 +86,8 @@ def wrapper(*args, **kw):
'Content-MD5': content_md5(kw['body']),
}
return func(*args, **kw)
- wrapper.__doc__ = "{}\nRequired HTTP Body: " \
- "{}".format(func.__doc__, field)
+ wrapper.__doc__ = "{0}\nRequired HTTP Body: " \
+ "{1}".format(func.__doc__, field)
return add_attrs_from(func, to=wrapper)
return decorator
@@ -116,7 +116,7 @@ def wrapper(*args, **kw):
for field in filter(kw.has_key, fields):
destructure_object(kw.pop(field), into=kw, prefix=field)
return func(*args, **kw)
- wrapper.__doc__ = "{}\nObjects: {}".format(func.__doc__,
+ wrapper.__doc__ = "{0}\nObjects: {1}".format(func.__doc__,
', '.join(fields))
return add_attrs_from(func, to=wrapper)
return decorator
@@ -130,12 +130,12 @@ def wrapper(*args, **kw):
hasgroup = lambda x: len(x) == len(filter(kw.has_key, x))
if 1 != len(filter(hasgroup, groups)):
message = ' OR '.join(['+'.join(g) for g in groups])
- message = "{} requires {} argument(s)" \
+ message = "{0} requires {1} argument(s)" \
"".format(func.action, message)
raise KeyError(message)
return func(*args, **kw)
message = ' OR '.join(['+'.join(g) for g in groups])
- wrapper.__doc__ = "{}\nRequired: {}".format(func.__doc__,
+ wrapper.__doc__ = "{0}\nRequired: {1}".format(func.__doc__,
message)
return add_attrs_from(func, to=wrapper)
return decorator
@@ -147,11 +147,11 @@ def decorator(func):
def wrapper(*args, **kw):
if not filter(kw.has_key, fields):
- message = "{} requires at least one of {} argument(s)" \
+ message = "{0} requires at least one of {1} argument(s)" \
"".format(func.action, ', '.join(fields))
raise KeyError(message)
return func(*args, **kw)
- wrapper.__doc__ = "{}\nSome Required: {}".format(func.__doc__,
+ wrapper.__doc__ = "{0}\nSome Required: {1}".format(func.__doc__,
', '.join(fields))
return add_attrs_from(func, to=wrapper)
return decorator
@@ -165,7 +165,7 @@ def wrapper(*args, **kw):
for field in filter(lambda x: isinstance(kw.get(x), bool), fields):
kw[field] = str(kw[field]).lower()
return func(*args, **kw)
- wrapper.__doc__ = "{}\nBooleans: {}".format(func.__doc__,
+ wrapper.__doc__ = "{0}\nBooleans: {1}".format(func.__doc__,
', '.join(fields))
return add_attrs_from(func, to=wrapper)
return decorator
@@ -184,18 +184,18 @@ def decorator(func, quota=int(quota), restore=float(restore)):
def wrapper(self, *args, **kw):
kw.setdefault(accesskey, getattr(self, accesskey, None))
if kw[accesskey] is None:
- message = "{} requires {} argument. Set the " \
- "MWSConnection.{} attribute?" \
+ message = "{0} requires {1} argument. Set the " \
+ "MWSConnection.{2} attribute?" \
"".format(action, accesskey, accesskey)
raise KeyError(message)
kw['Action'] = action
kw['Version'] = version
return func(self, path, response, *args, **kw)
for attr in decorated_attrs:
setattr(wrapper, attr, locals().get(attr))
- wrapper.__doc__ = "MWS {}/{} API call; quota={} restore={:.2f}\n" \
- "{}".format(action, version, quota, restore,
- func.__doc__)
+ wrapper.__doc__ = "MWS {0}/{1} API call; quota={2} restore={3:.2f}\n" \
+ "{4}".format(action, version, quota, restore,
+ func.__doc__)
return wrapper
return decorator
@@ -291,9 +291,9 @@ def get_feed_submission_result(self, path, response, **kw):
def get_service_status(self, **kw):
"""Instruct the user on how to get service status.
"""
- message = "Use {}.get_(section)_service_status(), " \
+ message = "Use {0}.get_(section)_service_status(), " \
"where (section) is one of the following: " \
- "{}".format(self.__class__.__name__,
+ "{1}".format(self.__class__.__name__,
', '.join(map(str.lower, api_version_path.keys())))
raise AttributeError(message)
@@ -587,8 +587,8 @@ def list_orders(self, path, response, **kw):
'SellerOrderId': toggle.union(['BuyerEmail']),
}.items():
if do in kw and filter(kw.has_key, dont):
- message = "Don't include {} when specifying " \
- "{}".format(' or '.join(dont), do)
+ message = "Don't include {0} when specifying " \
+ "{1}".format(' or '.join(dont), do)
raise AssertionError(message)
return self.post_request(path, kw, response)
@@ -41,9 +41,9 @@ class ResponseError(BotoServerError):
retry = False
def __repr__(self):
- return '{}({}, {},\n\t{})'.format(self.__class__.__name__,
- self.status, self.reason,
- self.error_message)
+ return '{0}({1}, {2},\n\t{3})'.format(self.__class__.__name__,
+ self.status, self.reason,
+ self.error_message)
def __str__(self):
return 'MWS Response Error: {0.status} {0.__class__.__name__} {1}\n' \
View
@@ -25,7 +25,7 @@ class ComplexType(dict):
_value = 'Value'
def __repr__(self):
- return '{}{}'.format(getattr(self, self._value, None), self.copy())
+ return '{0}{1}'.format(getattr(self, self._value, None), self.copy())
def __str__(self):
return str(getattr(self, self._value, ''))
@@ -165,15 +165,14 @@ def connection(self):
return self._connection
def __repr__(self):
- render = lambda pair: '{!s}: {!r}'.format(*pair)
+ render = lambda pair: '{0!s}: {1!r}'.format(*pair)
do_show = lambda pair: not pair[0].startswith('_')
attrs = filter(do_show, self.__dict__.items())
name = self.__class__.__name__
if name == 'JITResponse':
- name = '^{}^'.format(self._name or '')
- return '{}{!r}({})'.format(name,
- self.copy(),
- ', '.join(map(render, attrs)))
+ name = '^{0}^'.format(self._name or '')
+ return '{0}{1!r}({2})'.format(
+ name, self.copy(), ', '.join(map(render, attrs)))
def _type_for(self, name, attrs):
return self._override.get(name, globals().get(name, ResponseElement))
@@ -333,7 +332,7 @@ class ComplexAmount(ResponseElement):
_amount = 'Value'
def __repr__(self):
- return '{} {}'.format(self.CurrencyCode, getattr(self, self._amount))
+ return '{0} {1}'.format(self.CurrencyCode, getattr(self, self._amount))
def __float__(self):
return float(getattr(self, self._amount))
@@ -344,7 +343,7 @@ def __str__(self):
@strip_namespace
def startElement(self, name, attrs, connection):
if name not in ('CurrencyCode', self._amount):
- message = 'Unrecognized tag {} in ComplexAmount'.format(name)
+ message = 'Unrecognized tag {0} in ComplexAmount'.format(name)
raise AssertionError(message)
return ResponseElement.startElement(self, name, attrs, connection)
@@ -361,7 +360,7 @@ class ComplexMoney(ComplexAmount):
class ComplexWeight(ResponseElement):
def __repr__(self):
- return '{} {}'.format(self.Value, self.Unit)
+ return '{0} {1}'.format(self.Value, self.Unit)
def __float__(self):
return float(self.Value)
@@ -372,7 +371,7 @@ def __str__(self):
@strip_namespace
def startElement(self, name, attrs, connection):
if name not in ('Unit', 'Value'):
- message = 'Unrecognized tag {} in ComplexWeight'.format(name)
+ message = 'Unrecognized tag {0} in ComplexWeight'.format(name)
raise AssertionError(message)
return ResponseElement.startElement(self, name, attrs, connection)
@@ -398,7 +397,7 @@ def __repr__(self):
@strip_namespace
def startElement(self, name, attrs, connection):
if name not in self._dimensions:
- message = 'Unrecognized tag {} in ComplexDimensions'.format(name)
+ message = 'Unrecognized tag {0} in ComplexDimensions'.format(name)
raise AssertionError(message)
setattr(self, name, Dimension(attrs.copy()))
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-from unittest import main, skip, skipUnless, TestCase
+from tests.unit import unittest
import sys
import os
import os.path
@@ -26,17 +26,16 @@
from boto.mws.connection import MWSConnection
-class MWSTestCase(TestCase):
+class MWSTestCase(unittest.TestCase):
- def __init__(self, *args, **kw):
- TestCase.__init__(self, *args, **kw)
+ def setUp(self):
self.mws = MWSConnection(Merchant=simple, debug=0)
- @skipUnless(simple and isolator, "skipping simple test")
+ @unittest.skipUnless(simple and isolator, "skipping simple test")
def test_feedlist(self):
self.mws.get_feed_submission_list()
- @skipUnless(simple and isolator, "skipping simple test")
+ @unittest.skipUnless(simple and isolator, "skipping simple test")
def test_inbound_status(self):
response = self.mws.get_inbound_service_status()
status = response.GetServiceStatusResult.Status
@@ -52,13 +51,13 @@ def marketplace(self):
def marketplace_id(self):
return self.marketplace.MarketplaceId
- @skipUnless(simple and isolator, "skipping simple test")
+ @unittest.skipUnless(simple and isolator, "skipping simple test")
def test_marketplace_participations(self):
response = self.mws.list_marketplace_participations()
result = response.ListMarketplaceParticipationsResult
self.assertTrue(result.ListMarketplaces.Marketplace[0].MarketplaceId)
- @skipUnless(simple and isolator, "skipping simple test")
+ @unittest.skipUnless(simple and isolator, "skipping simple test")
def test_get_product_categories_for_asin(self):
asin = '144930544X'
response = self.mws.get_product_categories_for_asin(\
@@ -67,15 +66,15 @@ def test_get_product_categories_for_asin(self):
result = response._result
self.assertTrue(int(result.Self.ProductCategoryId) == 21)
- @skipUnless(simple and isolator, "skipping simple test")
+ @unittest.skipUnless(simple and isolator, "skipping simple test")
def test_list_matching_products(self):
response = self.mws.list_matching_products(\
MarketplaceId=self.marketplace_id,
Query='boto')
products = response._result.Products
self.assertTrue(len(products))
- @skipUnless(simple and isolator, "skipping simple test")
+ @unittest.skipUnless(simple and isolator, "skipping simple test")
def test_get_matching_product(self):
asin = 'B001UDRNHO'
response = self.mws.get_matching_product(\
@@ -84,7 +83,7 @@ def test_get_matching_product(self):
product = response._result[0].Product
- @skipUnless(simple and isolator, "skipping simple test")
+ @unittest.skipUnless(simple and isolator, "skipping simple test")
def test_get_lowest_offer_listings_for_asin(self):
asin = '144930544X'
response = self.mws.get_lowest_offer_listings_for_asin(\
@@ -95,4 +94,4 @@ def test_get_lowest_offer_listings_for_asin(self):
self.assertTrue(product.LowestOfferListings)
if __name__ == "__main__":
- main()
+ unittest.main()

0 comments on commit 2777702

Please sign in to comment.