예제 #1
0
 def test_syntaxerr(self):
     libpry.raises(
         "invalid expression",
         cubictemp._Expression,
         "for x", "@",
         0, self.s, {}
     )
예제 #2
0
 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")
예제 #3
0
 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)
예제 #4
0
 def test_fromBytes_err(self):
     libpry.raises(  ValueError,
                             IPAddress.fromBytes,
                             "\xff\xff\xff\x00\x01")
     libpry.raises(  ValueError,
                             IPAddress.fromBytes,
                             "\x00\x00\x00")
예제 #5
0
파일: test_manager.py 프로젝트: kanru/qtile
 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")
예제 #6
0
 def test_init_doublelist_final(self):
     spec = [
         tinytree.Tree(),
         [ tinytree.Tree() ],
         [ tinytree.Tree() ]
     ]
     libpry.raises(ValueError, tinytree.Tree, spec)
예제 #7
0
 def test_handlerError(self):
     """
         Test handler raising an error.
     """
     def errHandler(*args):
         raise TestError
     libpry.raises(TestError, self.l.loop, 5, errHandler)
예제 #8
0
 def test_syntaxerr(self):
     libpry.raises(
         "invalid expression",
         cubictemp._Expression,
         "for x", "@",
         0, self.s, {}
     )
예제 #9
0
 def test_bad_init(self):
     libpry.raises(
         packet.pcap.PcapError,
         packet.pcap.BPFProgram,
         self.l,
         "intentionally erroneous"
     )
예제 #10
0
 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")
예제 #11
0
 def test_write_err(self):
     libpry.raises(dump.DumpError,
                   self._dummy_cycle,
                   1,
                   None,
                   "",
                   wfile="nonexistentdir/foo")
예제 #12
0
    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)
예제 #13
0
 def test_init_doublelist_final(self):
     spec = [
         tinytree.Tree(),
         [ tinytree.Tree() ],
         [ tinytree.Tree() ]
     ]
     libpry.raises(ValueError, tinytree.Tree, spec)
예제 #14
0
    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)
예제 #15
0
 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)
예제 #16
0
 def test_write_err(self):
     libpry.raises(
         dump.DumpError,
         self._dummy_cycle,
         None,
         "", 
         wfile = "nonexistentdir/foo"
     )
예제 #17
0
파일: test_dump.py 프로젝트: npk/mitmproxy
 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")
예제 #18
0
 def test_format_execution(self):
     s = """
         <!--(block foo)-->
             @!bar!@
         <!--(end)-->
         @!foo!@
     """
     libpry.raises("line 3", unicode, cubictemp.Template(s))
예제 #19
0
 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)
예제 #20
0
 def test_format_execution(self):
     s = """
         <!--(block foo)-->
             @!bar!@
         <!--(end)-->
         @!foo!@
     """
     libpry.raises("line 3", unicode, cubictemp.Template(s))
예제 #21
0
 def test_compile(self):
     packet.pcap.BPFProgram(self.l, "icmp")
     libpry.raises(
         packet.pcap.PcapError,
         packet.pcap.BPFProgram,
         self.l,
         "asdf"
     )
예제 #22
0
 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")
예제 #23
0
 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)
예제 #24
0
 def test_unbalanced(self):
     s = """
         <!--(end)-->
         @!foo!@
         <!--(end)-->
         @!foo!@
         one
     """
     libpry.raises("unbalanced block", cubictemp.Template, s)
예제 #25
0
 def test_addChildrenFromList_err(self):
     nodes = [
         Node("one"), [
             Node("two"),
         ], [
             Node("six"),
         ]
     ]
     libpry.raises("not a tree object", Node, "root", nodes)
예제 #26
0
파일: test_bar.py 프로젝트: bavardage/qtile
 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)
예제 #27
0
 def test_addChildrenFromList_err(self):
     nodes = [
         Node("one"), [
             Node("two"),
         ], [
             Node("six"),
         ]
     ]
     libpry.raises("not a tree object", Node, "root", nodes)
예제 #28
0
파일: test_flow.py 프로젝트: 0m15/mitmproxy
    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"
예제 #29
0
 def test_nonexistent(self):
     s = tools.Splitter()
     libpry.raises(
         "no such file",
         s,
         ["nonexistent"],
         4,
         self.tmpdir(),
     )
예제 #30
0
    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"
예제 #31
0
 def test_unbalanced(self):
     s = """
         <!--(end)-->
         @!foo!@
         <!--(end)-->
         @!foo!@
         one
     """
     libpry.raises("unbalanced block", cubictemp.Template, s)
예제 #32
0
 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"
     )
예제 #33
0
 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)
예제 #34
0
파일: test_dump.py 프로젝트: npk/mitmproxy
    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"))
예제 #35
0
파일: test_dump.py 프로젝트: 0m15/mitmproxy
    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"
        )
예제 #36
0
 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")
예제 #37
0
    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())
예제 #38
0
 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)
예제 #39
0
 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")
     )
예제 #40
0
 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")
예제 #41
0
 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")
예제 #42
0
    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)
예제 #43
0
 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"
     )
예제 #44
0
 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"
예제 #45
0
    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
예제 #46
0
 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"
예제 #47
0
 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])
예제 #48
0
    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)
예제 #49
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")
예제 #50
0
 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])
예제 #51
0
    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)
예제 #52
0
    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
예제 #53
0
    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
예제 #54
0
 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
예제 #55
0
 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")
예제 #56
0
 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"))