Move unit tests to nose.

This commit is contained in:
Aldo Cortesi 2013-12-10 15:12:39 +13:00
parent be4de938b5
commit ddc9783983
11 changed files with 59 additions and 59 deletions

5
.coveragerc Normal file
View File

@ -0,0 +1,5 @@
[rum]
branch = True
[report]
include = scurve/*

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ build
*.swo
tmp.*
tmp
.coverage

2
binvis
View File

@ -57,7 +57,7 @@ class ColorClass(_Color):
class ColorEntropy(_Color):
def getPoint(self, x):
e = utils.entropy(self.data, 256, x, len(self.symbol_map))
e = utils.entropy(self.data, 32, x, len(self.symbol_map))
# http://www.wolframalpha.com/input/?i=plot+%284%28x-0.5%29-4%28x-0.5%29**2%29**4+from+0.5+to+1
def curve(v):
f = (4*v - 4*v**2)**4

View File

@ -1,8 +1,7 @@
import libpry
from scurve import hcurve
class uHcurve(libpry.AutoTree):
class TestHcurve:
def test_xycor(self):
n = 4
h = hcurve.Hcurve(2, n)
@ -18,11 +17,3 @@ class uHcurve(libpry.AutoTree):
def test_traversal(self):
h = hcurve.Hcurve.fromSize(2, 16)
assert [i for i in h]
tests = [
uHcurve()
]

View File

@ -1,9 +1,9 @@
import math
import libpry
from scurve import hilbert, utils
import tutils
class uFunctions(libpry.AutoTree):
class TestFunctions:
def ispow2(self, i):
"""
Is i a power of two?
@ -79,7 +79,7 @@ class uFunctions(libpry.AutoTree):
assert hilbert.entry(1) == 0
class uHilbert(libpry.AutoTree):
class TestHilbert:
def test_index(self):
h = hilbert.Hilbert(2, 3)
assert h.index(h.point(4)) == 4
@ -99,7 +99,7 @@ class uHilbert(libpry.AutoTree):
h2 = hilbert.Hilbert.fromSize(3, len(h))
assert h.dimension == h2.dimension
assert h.order == h2.order
libpry.raises(ValueError, hilbert.Hilbert.fromSize, 3, 3)
tutils.raises(ValueError, hilbert.Hilbert.fromSize, 3, 3)
def ttest_bench(self):
h = hilbert.Hilbert(2, 7)
@ -107,10 +107,3 @@ class uHilbert(libpry.AutoTree):
h.index(i)
tests = [
uFunctions(),
uHilbert()
]

View File

@ -1,9 +1,8 @@
import libpry
from scurve import natural, utils
import tutils
class uNatural(libpry.AutoTree):
class TestNatural:
def test_point(self):
tutils.is_complete(natural.Natural(1, 1))
tutils.is_complete(natural.Natural(1, 3))
@ -33,7 +32,3 @@ class uNatural(libpry.AutoTree):
assert z.size == z2.size
tests = [
uNatural()
]

View File

@ -1,8 +1,7 @@
import scurve.progress as progress
import libpry
import StringIO
class uInplace(libpry.AutoTree):
class TestInplace:
def test_basic(self):
s = StringIO.StringIO()
c = progress.Inplace(stream=s)
@ -20,7 +19,7 @@ class uInplace(libpry.AutoTree):
c.clear()
class uProgress(libpry.AutoTree):
class TestProgress:
def test_basic(self):
s = StringIO.StringIO()
p = progress.Progress(100, stream=s)
@ -30,9 +29,3 @@ class uProgress(libpry.AutoTree):
assert p.prev == 0.5
p.full()
assert p.prev == 1.0
tests = [
uInplace(),
uProgress()
]

View File

@ -1,7 +1,7 @@
from scurve import utils
import libpry
import tutils
class uFunctions(libpry.AutoTree):
class TestFunctions:
def test_bits2int(self):
assert utils.bits2int([0, 0, 1]) == 1
assert utils.bits2int([0, 1, 1]) == 3
@ -61,14 +61,8 @@ class uFunctions(libpry.AutoTree):
checkbit(4, 5, 2, 2, 0)
def test_entropy(self):
libpry.raises(ValueError, utils.entropy, "foo", 64, 0)
tutils.raises(ValueError, utils.entropy, "foo", 64, 0)
assert utils.entropy("a"*64, 64, 1) == 0
d = "".join([chr(i) for i in range(256)])
assert utils.entropy(d, 64, 1) == 1
tests = [
uFunctions()
]

View File

@ -1,9 +1,8 @@
import libpry
from scurve import zigzag, utils
import tutils
class uZigZag(libpry.AutoTree):
class TestZigZag:
def test_point(self):
tutils.is_traversal(zigzag.ZigZag(1, 1))
tutils.is_traversal(zigzag.ZigZag(1, 3))
@ -32,7 +31,3 @@ class uZigZag(libpry.AutoTree):
assert z.dimension == z2.dimension
assert z.size == z2.size
tests = [
uZigZag()
]

View File

@ -1,9 +1,8 @@
import libpry
from scurve import zorder, utils
import tutils
class uZOrder(libpry.AutoTree):
class TestZOrder:
def test_dimensions(self):
z = zorder.ZOrder(2, 2)
assert z.dimensions()[0] == (2**2)
@ -33,8 +32,3 @@ class uZOrder(libpry.AutoTree):
assert z.dimension == z2.dimension
assert z.bits == z2.bits
tests = [
uZOrder()
]

View File

@ -2,6 +2,45 @@
Some common test routines.
"""
def raises(exc, obj, *args, **kwargs):
"""
Assert that a callable raises a specified exception.
:exc An exception class or a string. If a class, assert that an
exception of this type is raised. If a string, assert that the string
occurs in the string representation of the exception, based on a
case-insenstivie match.
:obj A callable object.
:args Arguments to be passsed to the callable.
:kwargs Arguments to be passed to the callable.
"""
try:
apply(obj, args, kwargs)
except Exception, v:
if isinstance(exc, basestring):
if exc.lower() in str(v).lower():
return
else:
raise AssertionError(
"Expected %s, but caught %s"%(
repr(str(exc)), v
)
)
else:
if isinstance(v, exc):
return
else:
raise AssertionError(
"Expected %s, but caught %s %s"%(
exc.__name__, v.__class__.__name__, str(v)
)
)
raise AssertionError("No exception raised.")
def is_complete(lst):
"""
Does this list of points visit every vertex on the n-dimensional