mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-19 15:53:48 +00:00
Tests pass on both Python 2 and Python 3.
This commit is contained in:
4
setup.py
4
setup.py
@ -54,7 +54,9 @@ install_requires = [
|
|||||||
# * foolscap >= 0.12.5 has ConnectionInfo and ReconnectionInfo
|
# * foolscap >= 0.12.5 has ConnectionInfo and ReconnectionInfo
|
||||||
# * foolscap >= 0.12.6 has an i2p.sam_endpoint() that takes kwargs
|
# * foolscap >= 0.12.6 has an i2p.sam_endpoint() that takes kwargs
|
||||||
# * foolscap 0.13.2 drops i2p support completely
|
# * foolscap 0.13.2 drops i2p support completely
|
||||||
"foolscap == 0.13.1",
|
# * foolscap >= 20.4 is necessary for Python 3
|
||||||
|
"foolscap == 0.13.1; ; python_version < '3.0'",
|
||||||
|
"foolscap >= 20.4.0; ; python_version > '3.0'",
|
||||||
|
|
||||||
# * cryptography 2.6 introduced some ed25519 APIs we rely on. Note that
|
# * cryptography 2.6 introduced some ed25519 APIs we rely on. Note that
|
||||||
# Twisted[conch] also depends on cryptography and Twisted[tls]
|
# Twisted[conch] also depends on cryptography and Twisted[tls]
|
||||||
|
@ -6,7 +6,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
from future import standard_library
|
from future import standard_library
|
||||||
standard_library.install_aliases()
|
standard_library.install_aliases()
|
||||||
from builtins import *
|
from past.builtins import long
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
from allmydata.util import humanreadable
|
from allmydata.util import humanreadable
|
||||||
@ -26,8 +26,9 @@ class HumanReadable(unittest.TestCase):
|
|||||||
self.failUnlessEqual(hr(self.test_repr),
|
self.failUnlessEqual(hr(self.test_repr),
|
||||||
"<bound method HumanReadable.test_repr of <allmydata.test.test_humanreadable.HumanReadable testMethod=test_repr>>")
|
"<bound method HumanReadable.test_repr of <allmydata.test.test_humanreadable.HumanReadable testMethod=test_repr>>")
|
||||||
self.failUnlessEqual(hr(long(1)), "1")
|
self.failUnlessEqual(hr(long(1)), "1")
|
||||||
self.failUnlessEqual(hr(10**40),
|
self.assertIn(hr(10**40),
|
||||||
"100000000000000000...000000000000000000")
|
["100000000000000000...000000000000000000",
|
||||||
|
"100000000000000000...0000000000000000000"])
|
||||||
self.failUnlessEqual(hr(self), "<allmydata.test.test_humanreadable.HumanReadable testMethod=test_repr>")
|
self.failUnlessEqual(hr(self), "<allmydata.test.test_humanreadable.HumanReadable testMethod=test_repr>")
|
||||||
self.failUnlessEqual(hr([1,2]), "[1, 2]")
|
self.failUnlessEqual(hr([1,2]), "[1, 2]")
|
||||||
self.failUnlessEqual(hr({1:2}), "{1:2}")
|
self.failUnlessEqual(hr({1:2}), "{1:2}")
|
||||||
@ -50,4 +51,5 @@ class HumanReadable(unittest.TestCase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.failUnless(
|
self.failUnless(
|
||||||
hr(e) == "<NoArgumentException>" # python-2.4
|
hr(e) == "<NoArgumentException>" # python-2.4
|
||||||
or hr(e) == "NoArgumentException()") # python-2.5
|
or hr(e) == "NoArgumentException()" # python-2.5
|
||||||
|
or hr(e) == "<NoArgumentException: ()>", hr(e)) # python-3
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import exceptions, os
|
from __future__ import division
|
||||||
from repr import Repr
|
from __future__ import absolute_import
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
import os
|
||||||
|
from reprlib import Repr
|
||||||
|
|
||||||
class BetterRepr(Repr, object):
|
class BetterRepr(Repr, object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -14,21 +21,21 @@ class BetterRepr(Repr, object):
|
|||||||
self.maxother = 300
|
self.maxother = 300
|
||||||
|
|
||||||
def repr_function(self, obj, level):
|
def repr_function(self, obj, level):
|
||||||
if hasattr(obj, 'func_code'):
|
if hasattr(obj, '__code__'):
|
||||||
return '<' + obj.func_name + '() at ' + os.path.basename(obj.func_code.co_filename) + ':' + str(obj.func_code.co_firstlineno) + '>'
|
return '<' + obj.__name__ + '() at ' + os.path.basename(obj.__code__.co_filename) + ':' + str(obj.__code__.co_firstlineno) + '>'
|
||||||
else:
|
else:
|
||||||
return '<' + obj.func_name + '() at (builtin)'
|
return '<' + obj.__name__ + '() at (builtin)'
|
||||||
|
|
||||||
def repr_instance_method(self, obj, level):
|
def repr_instance_method(self, obj, level):
|
||||||
if hasattr(obj, 'func_code'):
|
if hasattr(obj, '__code__'):
|
||||||
return '<' + obj.im_class.__name__ + '.' + obj.im_func.__name__ + '() at ' + os.path.basename(obj.im_func.func_code.co_filename) + ':' + str(obj.im_func.func_code.co_firstlineno) + '>'
|
return '<' + obj.__self__.__class__.__name__ + '.' + obj.__func__.__name__ + '() at ' + os.path.basename(obj.__func__.__code__.co_filename) + ':' + str(obj.__func__.__code__.co_firstlineno) + '>'
|
||||||
else:
|
else:
|
||||||
return '<' + obj.im_class.__name__ + '.' + obj.im_func.__name__ + '() at (builtin)'
|
return '<' + obj.__self__.__class__.__name__ + '.' + obj.__func__.__name__ + '() at (builtin)'
|
||||||
|
|
||||||
def repr_long(self, obj, level):
|
def repr_long(self, obj, level):
|
||||||
s = repr(obj) # XXX Hope this isn't too slow...
|
s = repr(obj) # XXX Hope this isn't too slow...
|
||||||
if len(s) > self.maxlong:
|
if len(s) > self.maxlong:
|
||||||
i = max(0, (self.maxlong-3)/2)
|
i = max(0, (self.maxlong-3) // 2)
|
||||||
j = max(0, self.maxlong-3-i)
|
j = max(0, self.maxlong-3-i)
|
||||||
s = s[:i] + '...' + s[len(s)-j:]
|
s = s[:i] + '...' + s[len(s)-j:]
|
||||||
if s[-1] == 'L':
|
if s[-1] == 'L':
|
||||||
@ -43,7 +50,7 @@ class BetterRepr(Repr, object):
|
|||||||
on it. If it is an instance of list call self.repr_list() on it. Else
|
on it. If it is an instance of list call self.repr_list() on it. Else
|
||||||
call Repr.repr_instance().
|
call Repr.repr_instance().
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, exceptions.Exception):
|
if isinstance(obj, Exception):
|
||||||
# Don't cut down exception strings so much.
|
# Don't cut down exception strings so much.
|
||||||
tms = self.maxstring
|
tms = self.maxstring
|
||||||
self.maxstring = max(512, tms * 4)
|
self.maxstring = max(512, tms * 4)
|
||||||
@ -91,7 +98,7 @@ class BetterRepr(Repr, object):
|
|||||||
if level <= 0: return '{...}'
|
if level <= 0: return '{...}'
|
||||||
s = ''
|
s = ''
|
||||||
n = len(obj)
|
n = len(obj)
|
||||||
items = obj.items()[:min(n, self.maxdict)]
|
items = list(obj.items())[:min(n, self.maxdict)]
|
||||||
items.sort()
|
items.sort()
|
||||||
for key, val in items:
|
for key, val in items:
|
||||||
entry = self.repr1(key, level-1) + ':' + self.repr1(val, level-1)
|
entry = self.repr1(key, level-1) + ':' + self.repr1(val, level-1)
|
||||||
|
Reference in New Issue
Block a user