netstring.py 100% unit test coverage.
This commit is contained in:
parent
2f457e041e
commit
fbbc43a5b2
|
@ -23,8 +23,6 @@ class FileEncoder(object):
|
||||||
|
|
||||||
data -- A string to be encoded and written
|
data -- A string to be encoded and written
|
||||||
"""
|
"""
|
||||||
if not isinstance(data, str):
|
|
||||||
raise ValueError("data should be of type 'str'")
|
|
||||||
write = self.file_out.write
|
write = self.file_out.write
|
||||||
write(header(data))
|
write(header(data))
|
||||||
write(data)
|
write(data)
|
||||||
|
@ -81,8 +79,6 @@ class Decoder(object):
|
||||||
|
|
||||||
data -- A string containing complete or partial netstring data
|
data -- A string containing complete or partial netstring data
|
||||||
"""
|
"""
|
||||||
if not isinstance(data, str):
|
|
||||||
raise ValueError("data should be of type 'str'")
|
|
||||||
self.data_pos = 0
|
self.data_pos = 0
|
||||||
self.string_start = 0
|
self.string_start = 0
|
||||||
while self.data_pos < len(data):
|
while self.data_pos < len(data):
|
||||||
|
|
|
@ -46,6 +46,16 @@ class uNetstring(libpry.AutoTree):
|
||||||
decoded_data.append(s)
|
decoded_data.append(s)
|
||||||
assert decoded_data == self.test_data.split()
|
assert decoded_data == self.test_data.split()
|
||||||
|
|
||||||
|
def test_errors(self):
|
||||||
|
d = netstring.Decoder()
|
||||||
|
libpry.raises("Illegal digit", list, d.feed("1:foo"))
|
||||||
|
d = netstring.Decoder()
|
||||||
|
libpry.raises("Preceding zero", list, d.feed("01:f"))
|
||||||
|
d = netstring.Decoder(5)
|
||||||
|
libpry.raises("Maximum size", list, d.feed("500:f"))
|
||||||
|
d = netstring.Decoder()
|
||||||
|
libpry.raises("Illegal digit", list, d.feed(":f"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue