Bump unit tests for flow.py and dump.py

This commit is contained in:
Aldo Cortesi 2011-02-20 09:55:42 +13:00
parent 9c5c3c2b1a
commit d7ace1ce9e
3 changed files with 26 additions and 12 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
sys.path.insert(0, "..") sys.path.insert(0, "..")
print >> sys.stderr, "output"
sys.exit(1) sys.exit(1)

View File

@ -6,19 +6,21 @@ import utils
class uDumpMaster(libpry.AutoTree): class uDumpMaster(libpry.AutoTree):
def _cycle(self, m): def _cycle(self, m, content):
req = utils.treq() req = utils.treq()
req.content = content
cc = req.client_conn cc = req.client_conn
resp = utils.tresp(req) resp = utils.tresp(req)
resp.content = content
m.handle_clientconnect(cc) m.handle_clientconnect(cc)
m.handle_request(req) m.handle_request(req)
m.handle_response(resp) m.handle_response(resp)
def _dummy_cycle(self, filt, **options): def _dummy_cycle(self, filt, content, **options):
cs = StringIO() cs = StringIO()
o = dump.Options(**options) o = dump.Options(**options)
m = dump.DumpMaster(None, o, filt, outfile=cs) m = dump.DumpMaster(None, o, filt, outfile=cs)
self._cycle(m) self._cycle(m, content)
return cs.getvalue() return cs.getvalue()
def test_options(self): def test_options(self):
@ -27,16 +29,18 @@ class uDumpMaster(libpry.AutoTree):
libpry.raises(AttributeError, dump.Options, nonexistent = 2) libpry.raises(AttributeError, dump.Options, nonexistent = 2)
def test_filter(self): def test_filter(self):
assert not "GET" in self._dummy_cycle("~u foo", verbosity=1) assert not "GET" in self._dummy_cycle("~u foo", "", verbosity=1)
def test_basic(self): def test_basic(self):
for i in (1, 2, 3): for i in (1, 2, 3):
assert "GET" in self._dummy_cycle("~s", verbosity=i) assert "GET" in self._dummy_cycle("~s", "", verbosity=i)
assert "GET" in self._dummy_cycle("~s", "\x00\x00\x00", verbosity=i)
assert "GET" in self._dummy_cycle("~s", "ascii", verbosity=i)
def test_write(self): def test_write(self):
d = self.tmpdir() d = self.tmpdir()
p = os.path.join(d, "a") p = os.path.join(d, "a")
self._dummy_cycle(None, wfile=p, verbosity=0) self._dummy_cycle(None, "", wfile=p, verbosity=0)
assert len(list(flow.FlowReader(open(p)).stream())) == 1 assert len(list(flow.FlowReader(open(p)).stream())) == 1
def test_write_err(self): def test_write_err(self):
@ -44,33 +48,34 @@ class uDumpMaster(libpry.AutoTree):
dump.DumpError, dump.DumpError,
self._dummy_cycle, self._dummy_cycle,
None, None,
"",
wfile = "nonexistentdir/foo" wfile = "nonexistentdir/foo"
) )
def test_request_script(self): def test_request_script(self):
ret = self._dummy_cycle(None, request_script="scripts/a", verbosity=1) ret = self._dummy_cycle(None, "", request_script="scripts/a", verbosity=1)
assert "TESTOK" in ret assert "TESTOK" in ret
assert "DEBUG" in ret assert "DEBUG" in ret
libpry.raises( libpry.raises(
dump.DumpError, dump.DumpError,
self._dummy_cycle, None, request_script="nonexistent" self._dummy_cycle, None, "", request_script="nonexistent"
) )
libpry.raises( libpry.raises(
dump.DumpError, dump.DumpError,
self._dummy_cycle, None, request_script="scripts/err_data" self._dummy_cycle, None, "", request_script="scripts/err_return"
) )
def test_response_script(self): def test_response_script(self):
ret = self._dummy_cycle(None, response_script="scripts/a", verbosity=1) ret = self._dummy_cycle(None, "", response_script="scripts/a", verbosity=1)
assert "TESTOK" in ret assert "TESTOK" in ret
assert "DEBUG" in ret assert "DEBUG" in ret
libpry.raises( libpry.raises(
dump.DumpError, dump.DumpError,
self._dummy_cycle, None, response_script="nonexistent" self._dummy_cycle, None, "", response_script="nonexistent"
) )
libpry.raises( libpry.raises(
dump.DumpError, dump.DumpError,
self._dummy_cycle, None, response_script="scripts/err_data" self._dummy_cycle, None, "", response_script="scripts/err_return"
) )

View File

@ -51,6 +51,14 @@ class uFlow(libpry.AutoTree):
state = f.get_state() state = f.get_state()
assert f == flow.Flow.from_state(state) assert f == flow.Flow.from_state(state)
f2 = utils.tflow()
f2.error = proxy.Error(f, "e2")
assert not f == f2
f.load_state(f2.get_state())
assert f == f2
def test_kill(self): def test_kill(self):
f = utils.tflow() f = utils.tflow()
f.request = utils.treq() f.request = utils.treq()