mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-08 03:14:21 +00:00
Split out tests for humanreadable into their own module, so we can port just
humanreadable.py in isolation.
This commit is contained in:
parent
ffd24b9c7f
commit
b7f88b278f
46
src/allmydata/test/test_humanreadable.py
Normal file
46
src/allmydata/test/test_humanreadable.py
Normal file
@ -0,0 +1,46 @@
|
||||
"""Tests for allmydata.util.humanreadable."""
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata.util import humanreadable
|
||||
|
||||
|
||||
|
||||
|
||||
def foo(): pass # keep the line number constant
|
||||
|
||||
|
||||
class NoArgumentException(Exception):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
class HumanReadable(unittest.TestCase):
|
||||
def test_repr(self):
|
||||
hr = humanreadable.hr
|
||||
self.failUnlessEqual(hr(foo), "<foo() at test_humanreadable.py:10>")
|
||||
self.failUnlessEqual(hr(self.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(10**40),
|
||||
"100000000000000000...000000000000000000")
|
||||
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}")
|
||||
try:
|
||||
raise ValueError
|
||||
except Exception as e:
|
||||
self.failUnless(
|
||||
hr(e) == "<ValueError: ()>" # python-2.4
|
||||
or hr(e) == "ValueError()") # python-2.5
|
||||
try:
|
||||
raise ValueError("oops")
|
||||
except Exception as e:
|
||||
self.failUnless(
|
||||
hr(e) == "<ValueError: 'oops'>" # python-2.4
|
||||
or hr(e) == "ValueError('oops',)") # python-2.5
|
||||
try:
|
||||
raise NoArgumentException
|
||||
except Exception as e:
|
||||
self.failUnless(
|
||||
hr(e) == "<NoArgumentException>" # python-2.4
|
||||
or hr(e) == "NoArgumentException()") # python-2.5
|
@ -1,8 +1,5 @@
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
def foo(): pass # keep the line number constant
|
||||
|
||||
import binascii
|
||||
import six
|
||||
import hashlib
|
||||
@ -17,7 +14,7 @@ from twisted.internet import defer, reactor
|
||||
from twisted.python.failure import Failure
|
||||
from twisted.python import log
|
||||
|
||||
from allmydata.util import base32, idlib, humanreadable, mathutil, hashutil
|
||||
from allmydata.util import base32, idlib, mathutil, hashutil
|
||||
from allmydata.util import assertutil, fileutil, deferredutil, abbreviate
|
||||
from allmydata.util import limiter, time_format, pollmixin
|
||||
from allmydata.util import statistics, dictutil, pipeline, yamlutil
|
||||
@ -57,44 +54,13 @@ class Base32(unittest.TestCase):
|
||||
self.failUnlessEqual(base32.a2b("ci2a"), "\x12\x34")
|
||||
self.failUnlessRaises(AssertionError, base32.a2b, "b0gus")
|
||||
|
||||
|
||||
class IDLib(unittest.TestCase):
|
||||
def test_nodeid_b2a(self):
|
||||
self.failUnlessEqual(idlib.nodeid_b2a("\x00"*20), "a"*32)
|
||||
|
||||
class NoArgumentException(Exception):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
class HumanReadable(unittest.TestCase):
|
||||
def test_repr(self):
|
||||
hr = humanreadable.hr
|
||||
self.failUnlessEqual(hr(foo), "<foo() at test_util.py:4>")
|
||||
self.failUnlessEqual(hr(self.test_repr),
|
||||
"<bound method HumanReadable.test_repr of <allmydata.test.test_util.HumanReadable testMethod=test_repr>>")
|
||||
self.failUnlessEqual(hr(long(1)), "1")
|
||||
self.failUnlessEqual(hr(10**40),
|
||||
"100000000000000000...000000000000000000")
|
||||
self.failUnlessEqual(hr(self), "<allmydata.test.test_util.HumanReadable testMethod=test_repr>")
|
||||
self.failUnlessEqual(hr([1,2]), "[1, 2]")
|
||||
self.failUnlessEqual(hr({1:2}), "{1:2}")
|
||||
try:
|
||||
raise ValueError
|
||||
except Exception as e:
|
||||
self.failUnless(
|
||||
hr(e) == "<ValueError: ()>" # python-2.4
|
||||
or hr(e) == "ValueError()") # python-2.5
|
||||
try:
|
||||
raise ValueError("oops")
|
||||
except Exception as e:
|
||||
self.failUnless(
|
||||
hr(e) == "<ValueError: 'oops'>" # python-2.4
|
||||
or hr(e) == "ValueError('oops',)") # python-2.5
|
||||
try:
|
||||
raise NoArgumentException
|
||||
except Exception as e:
|
||||
self.failUnless(
|
||||
hr(e) == "<NoArgumentException>" # python-2.4
|
||||
or hr(e) == "NoArgumentException()") # python-2.5
|
||||
class Abbreviate(unittest.TestCase):
|
||||
|
||||
def test_abbrev_time_1s(self):
|
||||
diff = timedelta(seconds=1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user