def test_syntaxerr(self): libpry.raises( "invalid expression", cubictemp._Expression, "for x", "@", 0, self.s, {} )
def test_simple(self): assert utils.parse_size("1") == 1 assert utils.parse_size("1k") == 1024 assert utils.parse_size("1m") == 1024**2 assert utils.parse_size("1g") == 1024**3 libpry.raises(ValueError, utils.parse_size, "1f") libpry.raises(ValueError, utils.parse_size, "ak")
def test_dirtystate(self): self.application.testing = 0 self.application.debug = 1 io = cStringIO.StringIO() self.application.logErr = io p = model.BasePage() libpry.raises("Dirty state", self.application.pre, p)
def test_fromBytes_err(self): libpry.raises( ValueError, IPAddress.fromBytes, "\xff\xff\xff\x00\x01") libpry.raises( ValueError, IPAddress.fromBytes, "\x00\x00\x00")
def test_subtheme(self): t = self._sub() assert t.border_width == 2 assert t["sub"].border_width == 3 assert t["sub"]["sub"].border_width == 4 assert t["sub"]["sub"].opacity == 0.5 libpry.raises(KeyError, t.__getitem__, "nonexistent")
def test_init_doublelist_final(self): spec = [ tinytree.Tree(), [ tinytree.Tree() ], [ tinytree.Tree() ] ] libpry.raises(ValueError, tinytree.Tree, spec)
def test_handlerError(self): """ Test handler raising an error. """ def errHandler(*args): raise TestError libpry.raises(TestError, self.l.loop, 5, errHandler)
def test_bad_init(self): libpry.raises( packet.pcap.PcapError, packet.pcap.BPFProgram, self.l, "intentionally erroneous" )
def test_write_err(self): libpry.raises(dump.DumpError, self._dummy_cycle, 1, None, "", wfile="nonexistentdir/foo")
def test_replay(self): cs = StringIO() o = dump.Options(server_replay="nonexistent", kill=True) libpry.raises(dump.DumpError, dump.DumpMaster, None, o, None, outfile=cs) t = self.tmpdir() p = os.path.join(t, "rep") f = open(p, "w") fw = flow.FlowWriter(f) t = tutils.tflow_full() t.response = tutils.tresp(t.request) fw.add(t) f.close() o = dump.Options(server_replay=p, kill=True) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "content") self._cycle(m, "content") o = dump.Options(server_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "nonexistent") o = dump.Options(client_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs)
def test_replay(self): cs = StringIO() o = dump.Options(server_replay="nonexistent", kill=True) libpry.raises(dump.DumpError, dump.DumpMaster, None, o, None, outfile=cs) with tutils.tmpdir() as t: p = os.path.join(t, "rep") self._flowfile(p) o = dump.Options(server_replay=p, kill=True) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "content") self._cycle(m, "content") o = dump.Options(server_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "nonexistent") o = dump.Options(client_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs)
def test_ambiguouschild2(self): r = model.BaseRoot( [ testpages.TPage("one", structural=True), [testpages.TPage("test"), testpages.TPage("X", structural=False), [testpages.TPage("test")]], ] ) libpry.raises(model.ApplicationError, testpages.TestApplication, r)
def test_write_err(self): libpry.raises( dump.DumpError, self._dummy_cycle, None, "", wfile = "nonexistentdir/foo" )
def test_script(self): ret = self._dummy_cycle(1, None, "", script=tutils.test_data.path("scripts/all.py"), verbosity=0, eventlog=True) assert "XCLIENTCONNECT" in ret assert "XREQUEST" in ret assert "XRESPONSE" in ret assert "XCLIENTDISCONNECT" in ret libpry.raises(dump.DumpError, self._dummy_cycle, 1, None, "", script="nonexistent") libpry.raises(dump.DumpError, self._dummy_cycle, 1, None, "", script="starterr.py")
def test_format_execution(self): s = """ <!--(block foo)--> @!bar!@ <!--(end)--> @!foo!@ """ libpry.raises("line 3", unicode, cubictemp.Template(s))
def test_fromSize(self): h = hilbert.Hilbert.fromSize(2, 256*256) assert h.dimensions() == [256, 256] h = hilbert.Hilbert(3, 1) h2 = hilbert.Hilbert.fromSize(3, len(h)) assert h.dimension == h2.dimension assert h.order == h2.order libpry.raises(ValueError, hilbert.Hilbert.fromSize, 3, 3)
def test_compile(self): packet.pcap.BPFProgram(self.l, "icmp") libpry.raises( packet.pcap.PcapError, packet.pcap.BPFProgram, self.l, "asdf" )
def test_init(self): a = address.Address("192.168.0.1") assert isinstance(address.AddressFromBytes(a.bytes), address.IPAddress) a = address.Address("ffff::") assert isinstance(address.AddressFromBytes(a.bytes), address.IP6Address) a = address.Address("00:00:00:00:00:00") assert isinstance(address.AddressFromBytes(a.bytes), address.EthernetAddress) libpry.raises("not a valid address", address.AddressFromBytes, "foo")
def test_fromSize(self): h = hilbert.Hilbert.fromSize(2, 256 * 256) assert h.dimensions() == [256, 256] h = hilbert.Hilbert(3, 1) h2 = hilbert.Hilbert.fromSize(3, len(h)) assert h.dimension == h2.dimension assert h.order == h2.order libpry.raises(ValueError, hilbert.Hilbert.fromSize, 3, 3)
def test_unbalanced(self): s = """ <!--(end)--> @!foo!@ <!--(end)--> @!foo!@ one """ libpry.raises("unbalanced block", cubictemp.Template, s)
def test_addChildrenFromList_err(self): nodes = [ Node("one"), [ Node("two"), ], [ Node("six"), ] ] libpry.raises("not a tree object", Node, "root", nodes)
def test_measurebox(self): libpry.raises("out of range", self.c.widget["measure"].update, 200) libpry.raises("out of range", self.c.widget["measure"].update, -1) self.c.widget["measure"].update(0) self.c.widget["measure"].update(10) self.c.widget["measure"].update(30) self.c.widget["measure"].update(50) self.c.widget["measure"].update(80) self.c.widget["measure"].update(100)
def test_error(self): sio = StringIO() sio.write("bogus") sio.seek(0) r = flow.FlowReader(sio) libpry.raises(flow.FlowReadError, list, r.stream()) f = flow.FlowReadError("foo") assert f.strerror == "foo"
def test_nonexistent(self): s = tools.Splitter() libpry.raises( "no such file", s, ["nonexistent"], 4, self.tmpdir(), )
def test_err(self): libpry.raises( "malformed ethernet", address.EthernetAddress, "00:00:00:00:00" ) libpry.raises( "must have 6 bytes", address.EthernetAddress.fromBytes, "\xaa" )
def test_index(self): nodes = [ Node("one"), Node("two"), Node("three"), ] t = Node("root", nodes) assert t["one"].index() == 0 assert t["two"].index() == 1 libpry.raises("node with no parent", t.index)
def test_read(self): with tutils.tmpdir() as t: p = os.path.join(t, "read") self._flowfile(p) assert "GET" in self._dummy_cycle(0, None, "", verbosity=1, rfile=p) libpry.raises(dump.DumpError, self._dummy_cycle, 0, None, "", verbosity=1, rfile="/nonexistent") # We now just ignore errors self._dummy_cycle(0, None, "", verbosity=1, rfile=tutils.test_data.path("test_dump.py"))
def test_read(self): t = self.tmpdir() p = os.path.join(t, "read") self._flowfile(p) assert "GET" in self._dummy_cycle(0, None, "", verbosity=1, rfile=p) libpry.raises( dump.DumpError, self._dummy_cycle, 0, None, "", verbosity=1, rfile="/nonexistent" )
def test_versioncheck(self): f = tutils.tflow() d = f._get_state() d["version"] = (0, 0) sio = StringIO() tnetstring.dump(d, sio) sio.seek(0) r = flow.FlowReader(sio) libpry.raises("version", list, r.stream())
def test_init(self): libpry.raises( "unknown key", libqtile.manager.Key, [], "unknown", libqtile.command._Call("base", None, "foo") ) libpry.raises( "unknown modifier", libqtile.manager.Key, ["unknown"], "x", libqtile.command._Call("base", None, "foo") )
def test_replace(self): nodes = [ Node("one"), Node("two"), Node("three"), ] t = Node("root", nodes) n = t["two"] n.replace(Node("four"), Node("five")) assert len(t.children) == 4 libpry.raises(KeyError, t.__getitem__, "two")
def test_select_window(self): win = self.testWindow("test") wid = self.c.window.info()["id"] assert self.c.window.group.info()["name"] == "a" libpry.raises("no object", self.c.window.group["a"].info) assert len(self.c.window.layout.info()["stacks"]) == 1 assert len(self.c.window.layout[1].info()["stacks"]) == 2 assert self.c.window.screen.info()["index"] == 0 libpry.raises("no object", self.c.window.screen[0].info)
def test_request_script(self): ret = self._dummy_cycle(None, "", request_script="scripts/a", verbosity=1) assert "TESTOK" in ret assert "DEBUG" in ret libpry.raises( dump.DumpError, self._dummy_cycle, None, "", request_script="nonexistent" ) libpry.raises( dump.DumpError, self._dummy_cycle, None, "", request_script="scripts/err_return" )
def test_togroup(self): self.testWindow("one") libpry.raises("no such group", self.c.window.togroup, "nonexistent") assert self.c.groups()["a"]["focus"] == "one" self.c.window.togroup("a") assert self.c.groups()["a"]["focus"] == "one" self.c.window.togroup("b") assert self.c.groups()["b"]["focus"] == "one" assert self.c.groups()["a"]["focus"] == None self.c.to_screen(1) self.c.window.togroup("c") assert self.c.groups()["c"]["focus"] == "one"
def test_init(self): libpry.raises( "unknown link layer type", packet.pcap.Interpreter, "nonexistent", None, None ) p = packet.pcap.Interpreter( 1, None, packet.packet.Ethernet ) assert p.pclass == packet.packet.Ethernet
def test_adddelgroup(self): self.testWindow("one") self.c.addgroup("testgroup") assert "testgroup" in self.c.groups().keys() self.c.window.togroup("testgroup") self.c.delgroup("testgroup") assert not "testgroup" in self.c.groups().keys() # Assert that the test window is still a member of some group. assert sum([len(i["windows"]) for i in self.c.groups().values()]) for i in self.c.groups().keys()[:-1]: self.c.delgroup(i) libpry.raises("Can't delete all groups", self.c.delgroup, self.c.groups().keys()[0])
def test_read(self): t = self.tmpdir() p = os.path.join(t, "read") self._flowfile(p) assert "GET" in self._dummy_cycle(0, None, "", verbosity=1, rfile=p) libpry.raises(dump.DumpError, self._dummy_cycle, 0, None, "", verbosity=1, rfile="/nonexistent")
def test_format_compiletime(self): s = """ <!--(block foo)--> @!foo!@ <!--(end)--> @![!@ <!--(block barbar)--> @!foo!@ <!--(end)--> """ libpry.raises("line 5", cubictemp.Template, s) s = """ @![!@ """ libpry.raises("line 2", cubictemp.Template, s) s = """ <!--(block foo)--> @!]!@ <!--(end)--> @!foo!@ """ libpry.raises("line 3", cubictemp.Template, s) s = "@!]!@" libpry.raises("line 1", cubictemp.Template, s)
def test_simple(self): libpry.raises(proxy.ProxyError, proxy.parse_request_line, "") u = "GET ... HTTP/1.1" libpry.raises("invalid url", proxy.parse_request_line, u) u = "GET http://foo.com:8888/test HTTP/1.1" m, s, h, po, pa, minor = proxy.parse_request_line(u) assert m == "GET" assert s == "http" assert h == "foo.com" assert po == 8888 assert pa == "/test" assert minor == 1
def test_basic(self): self.testVal = None def test(x): self.testVal = x libpry.raises("unknown event", libqtile.hook.fire, "unkown") libqtile.manager.hook.subscribe.group_window_add(test) libqtile.manager.hook.fire("group_window_add", 1) assert self.testVal == 1 assert libqtile.manager.hook.subscriptions libqtile.manager.hook.clear() assert not libqtile.manager.hook.subscriptions
def test_alreadyClosedError(self): self.l.close() libpry.raises(packet.pcap.PcapError, self.l.datalink) libpry.raises(packet.pcap.PcapError, self.l.close) libpry.raises(packet.pcap.PcapError, self.l.dispatch, 2, nullFunc) libpry.raises(packet.pcap.PcapError, self.l.loop, 2, nullFunc) del self.l
def test_set(self): libpry.raises(ValueError, setattr, self.data["ipv6"], "src", "::1::1") libpry.raises(ValueError, setattr, self.data["ipv6"], "src", "::123422") libpry.raises(ValueError, setattr, self.data["ipv6"], "src", "::123422") libpry.raises(ValueError, setattr, self.data["ipv6"], "src", "1:1:1:1:1::1:1:1:1")
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"))