tests++
This commit is contained in:
parent
637a3be937
commit
c98c83190b
|
@ -120,13 +120,7 @@ def isMostlyBin(s):
|
|||
|
||||
|
||||
def isXML(s):
|
||||
for i in s:
|
||||
if i in "\n \t":
|
||||
continue
|
||||
elif i == "<":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return s.strip().startswith("<")
|
||||
|
||||
|
||||
def clean_hanging_newline(t):
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
# coding=utf-8
|
||||
import six
|
||||
|
||||
from netlib import strutils
|
||||
from netlib import strutils, tutils
|
||||
|
||||
|
||||
def test_native():
|
||||
with tutils.raises(TypeError):
|
||||
strutils.native(42)
|
||||
if six.PY2:
|
||||
assert strutils.native(u"foo") == b"foo"
|
||||
assert strutils.native(b"foo") == b"foo"
|
||||
else:
|
||||
assert strutils.native(u"foo") == u"foo"
|
||||
assert strutils.native(b"foo") == u"foo"
|
||||
|
||||
|
||||
def test_clean_bin():
|
||||
|
@ -29,6 +41,9 @@ def test_bytes_to_escaped_str():
|
|||
assert strutils.bytes_to_escaped_str(b"'") == r"\'"
|
||||
assert strutils.bytes_to_escaped_str(b'"') == r'"'
|
||||
|
||||
with tutils.raises(ValueError):
|
||||
strutils.bytes_to_escaped_str(u"such unicode")
|
||||
|
||||
|
||||
def test_escaped_str_to_bytes():
|
||||
assert strutils.escaped_str_to_bytes("foo") == b"foo"
|
||||
|
@ -39,6 +54,13 @@ def test_escaped_str_to_bytes():
|
|||
assert strutils.escaped_str_to_bytes(u"&!?=\\\\)") == br"&!?=\)"
|
||||
assert strutils.escaped_str_to_bytes(u"ü") == b'\xc3\xbc'
|
||||
|
||||
if six.PY2:
|
||||
with tutils.raises(ValueError):
|
||||
strutils.escaped_str_to_bytes(42)
|
||||
else:
|
||||
with tutils.raises(ValueError):
|
||||
strutils.escaped_str_to_bytes(b"very byte")
|
||||
|
||||
|
||||
def test_isBin():
|
||||
assert not strutils.isBin("testing\n\r")
|
||||
|
|
Loading…
Reference in New Issue