diff options
| author | Aldo Cortesi <aldo@corte.si> | 2016-07-13 22:57:31 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-13 22:57:31 +1200 |
| commit | efc0b9fe7f8420abb03bbfce9316afee9cfa4c5c (patch) | |
| tree | 59e17892e13a20c051512dfd2bd6a5af5d30ca03 /test | |
| parent | 2624911d75670afaff8631943d567bfa2b42d7b8 (diff) | |
| parent | 077850bd107d7ffe1cf3d4a8667bb04ea47beb96 (diff) | |
| download | mitmproxy-efc0b9fe7f8420abb03bbfce9316afee9cfa4c5c.tar.gz mitmproxy-efc0b9fe7f8420abb03bbfce9316afee9cfa4c5c.tar.bz2 mitmproxy-efc0b9fe7f8420abb03bbfce9316afee9cfa4c5c.zip | |
Merge pull request #1347 from cortesi/options
Options
Diffstat (limited to 'test')
| -rw-r--r-- | test/mitmproxy/test_options.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/mitmproxy/test_options.py b/test/mitmproxy/test_options.py new file mode 100644 index 00000000..5fdb7abe --- /dev/null +++ b/test/mitmproxy/test_options.py @@ -0,0 +1,67 @@ +from __future__ import absolute_import, print_function, division +import copy + +from mitmproxy import options +from mitmproxy import exceptions +from netlib.tutils import raises + + +class TO(options.Options): + attributes = [ + "one", + "two" + ] + + +def test_options(): + o = TO(two="three") + assert o.one is None + assert o.two == "three" + o.one = "one" + assert o.one == "one" + raises("no such option", setattr, o, "nonexistent", "value") + raises("no such option", o.update, nonexistent = "value") + + rec = [] + + def sub(opts): + rec.append(copy.copy(opts)) + + o.changed.connect(sub) + + o.one = "ninety" + assert len(rec) == 1 + assert rec[-1].one == "ninety" + + o.update(one="oink") + assert len(rec) == 2 + assert rec[-1].one == "oink" + + +def test_rollback(): + o = TO(one="two") + + rec = [] + + def sub(opts): + rec.append(copy.copy(opts)) + + recerr = [] + + def errsub(opts, **kwargs): + recerr.append(kwargs) + + def err(opts): + if opts.one == "ten": + raise exceptions.OptionsError + + o.changed.connect(sub) + o.changed.connect(err) + o.errored.connect(errsub) + + o.one = "ten" + assert isinstance(recerr[0]["exc"], exceptions.OptionsError) + assert o.one == "two" + assert len(rec) == 2 + assert rec[0].one == "ten" + assert rec[1].one == "two" |
