Fix a few stylistic issues.

This commit is contained in:
Kale Kundert 2016-03-14 11:29:45 -07:00
parent 861265411f
commit 9e7206a1cf
1 changed files with 9 additions and 7 deletions

View File

@ -1466,8 +1466,10 @@ class approx(object):
def __eq__(self, actual): def __eq__(self, actual):
from collections import Iterable from collections import Iterable
if not isinstance(actual, Iterable): actual = [actual] if not isinstance(actual, Iterable):
if len(actual) != len(self.expected): return False actual = [actual]
if len(actual) != len(self.expected):
return False
return all(a == x for a, x in zip(actual, self.expected)) return all(a == x for a, x in zip(actual, self.expected))
def __ne__(self, actual): def __ne__(self, actual):
@ -1521,16 +1523,16 @@ class ApproxNonIterable(object):
except ValueError: except ValueError:
vetted_tolerance = '???' vetted_tolerance = '???'
repr = u'{0} \u00b1 {1}'.format(self.expected, vetted_tolerance) plus_minus = u'{0} \u00b1 {1}'.format(self.expected, vetted_tolerance)
# In python2, __repr__() must return a string (i.e. not a unicode # In python2, __repr__() must return a string (i.e. not a unicode
# object). In python3, __repr__() must return a unicode object # object). In python3, __repr__() must return a unicode object
# (although now strings are unicode objects and bytes are what # (although now strings are unicode objects and bytes are what
# strings were). # strings were).
if sys.version_info[0] == 2: if sys.version_info[0] == 2:
return repr.encode('utf-8') return plus_minus.encode('utf-8')
else: else:
return repr return plus_minus
def __eq__(self, actual): def __eq__(self, actual):
# Short-circuit exact equality. # Short-circuit exact equality.
@ -1571,11 +1573,11 @@ class ApproxNonIterable(object):
if self.abs is not None: if self.abs is not None:
return absolute_tolerance return absolute_tolerance
# Figure out what the absolute tolerance should be. ``self.rel`` is # Figure out what the relative tolerance should be. ``self.rel`` is
# either None or a value specified by the user. This is done after # either None or a value specified by the user. This is done after
# we've made sure the user didn't ask for an absolute tolerance only, # we've made sure the user didn't ask for an absolute tolerance only,
# because we don't want to raise errors about the relative tolerance if # because we don't want to raise errors about the relative tolerance if
# it isn't even being used. # we aren't even going to use it.
relative_tolerance = set_default(self.rel, 1e-6) * abs(self.expected) relative_tolerance = set_default(self.rel, 1e-6) * abs(self.expected)
if relative_tolerance < 0: if relative_tolerance < 0: