2012-09-23 23:21:48 +00:00
|
|
|
from netlib import utils
|
2015-04-29 21:04:22 +00:00
|
|
|
import tutils
|
|
|
|
|
|
|
|
|
|
|
|
def test_bidi():
|
|
|
|
b = utils.BiDi(a=1, b=2)
|
|
|
|
assert b.a == 1
|
2015-04-30 00:10:08 +00:00
|
|
|
assert b.get_name(1) == "a"
|
|
|
|
assert b.get_name(5) is None
|
2015-04-29 21:04:22 +00:00
|
|
|
tutils.raises(AttributeError, getattr, b, "c")
|
2015-04-30 00:10:08 +00:00
|
|
|
tutils.raises(ValueError, utils.BiDi, one=1, two=1)
|
2015-04-29 21:04:22 +00:00
|
|
|
|
2012-09-23 23:21:48 +00:00
|
|
|
|
|
|
|
def test_hexdump():
|
|
|
|
assert utils.hexdump("one\0"*10)
|
|
|
|
|
|
|
|
|
|
|
|
def test_cleanBin():
|
|
|
|
assert utils.cleanBin("one") == "one"
|
|
|
|
assert utils.cleanBin("\00ne") == ".ne"
|
|
|
|
assert utils.cleanBin("\nne") == "\nne"
|
|
|
|
assert utils.cleanBin("\nne", True) == ".ne"
|
2015-04-30 00:10:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_pretty_size():
|
|
|
|
assert utils.pretty_size(100) == "100B"
|
|
|
|
assert utils.pretty_size(1024) == "1kB"
|
|
|
|
assert utils.pretty_size(1024 + (1024/2.0)) == "1.5kB"
|
|
|
|
assert utils.pretty_size(1024*1024) == "1MB"
|