From fbbc43a5b24f24657bb7a9d6eff50b3db77e5e7f Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 12 Mar 2011 14:39:41 +1300 Subject: [PATCH] netstring.py 100% unit test coverage. --- libmproxy/netstring.py | 4 ---- test/test_netstring.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libmproxy/netstring.py b/libmproxy/netstring.py index a7b7a5372..669e19e35 100644 --- a/libmproxy/netstring.py +++ b/libmproxy/netstring.py @@ -23,8 +23,6 @@ class FileEncoder(object): 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(header(data)) write(data) @@ -81,8 +79,6 @@ class Decoder(object): 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.string_start = 0 while self.data_pos < len(data): diff --git a/test/test_netstring.py b/test/test_netstring.py index 482859600..3c56acd9a 100644 --- a/test/test_netstring.py +++ b/test/test_netstring.py @@ -46,6 +46,16 @@ class uNetstring(libpry.AutoTree): decoded_data.append(s) 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")) +