aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_plugins.py
blob: 135d93ceb519b5a6bbd8331bd71ab98e9e86c9db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from libmproxy import plugins, flow
import libpry

class uPlugin(libpry.AutoTree):
    def test_simple(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)

        p = plugins.Plugin(os.path.join("plugins", "a.py"), fm)
        assert "here" in p.ns
        assert p.run("here") == (True, 1)
        assert p.run("here") == (True, 2)
        
        ret = p.run("errargs")
        assert not ret[0] 
        assert len(ret[1]) == 2

        # Check reload
        p.load()
        assert p.run("here") == (True, 1)

    def test_err(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)

        libpry.raises(IOError, plugins.Plugin, "nonexistent", fm)
        libpry.raises(SyntaxError, plugins.Plugin, os.path.join("plugins", "syntaxerr.py"), fm)



tests = [
    uPlugin(),
]