Move existing base32 tests out of test_util.py.
This commit is contained in:
parent
15f01c93bf
commit
f27cba181e
|
@ -0,0 +1,27 @@
|
|||
"""
|
||||
Tests for allmydata.util.base32.
|
||||
"""
|
||||
|
||||
import base64
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata.util import base32
|
||||
|
||||
|
||||
class Base32(unittest.TestCase):
|
||||
def test_b2a_matches_Pythons(self):
|
||||
y = "\x12\x34\x45\x67\x89\x0a\xbc\xde\xf0"
|
||||
x = base64.b32encode(y)
|
||||
while x and x[-1] == '=':
|
||||
x = x[:-1]
|
||||
x = x.lower()
|
||||
self.failUnlessEqual(base32.b2a(y), x)
|
||||
def test_b2a(self):
|
||||
self.failUnlessEqual(base32.b2a("\x12\x34"), "ci2a")
|
||||
def test_b2a_or_none(self):
|
||||
self.failUnlessEqual(base32.b2a_or_none(None), None)
|
||||
self.failUnlessEqual(base32.b2a_or_none("\x12\x34"), "ci2a")
|
||||
def test_a2b(self):
|
||||
self.failUnlessEqual(base32.a2b("ci2a"), "\x12\x34")
|
||||
self.failUnlessRaises(AssertionError, base32.a2b, "b0gus")
|
|
@ -14,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, mathutil, hashutil
|
||||
from allmydata.util import idlib, mathutil, hashutil
|
||||
from allmydata.util import fileutil, deferredutil, abbreviate
|
||||
from allmydata.util import limiter, time_format, pollmixin
|
||||
from allmydata.util import statistics, dictutil, pipeline, yamlutil
|
||||
|
@ -36,25 +36,6 @@ def sha256(data):
|
|||
return binascii.hexlify(hashlib.sha256(data).digest())
|
||||
|
||||
|
||||
class Base32(unittest.TestCase):
|
||||
def test_b2a_matches_Pythons(self):
|
||||
import base64
|
||||
y = "\x12\x34\x45\x67\x89\x0a\xbc\xde\xf0"
|
||||
x = base64.b32encode(y)
|
||||
while x and x[-1] == '=':
|
||||
x = x[:-1]
|
||||
x = x.lower()
|
||||
self.failUnlessEqual(base32.b2a(y), x)
|
||||
def test_b2a(self):
|
||||
self.failUnlessEqual(base32.b2a("\x12\x34"), "ci2a")
|
||||
def test_b2a_or_none(self):
|
||||
self.failUnlessEqual(base32.b2a_or_none(None), None)
|
||||
self.failUnlessEqual(base32.b2a_or_none("\x12\x34"), "ci2a")
|
||||
def test_a2b(self):
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue