aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-07-14 11:11:41 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-07-14 11:11:41 +1200
commit97b2e6d958a691060746b530219bf15a0bede1ae (patch)
tree6287a9c3b1994c64213dfbee7e62dd36d8492fec /test
parentc52d567b4360ebbaa63918beb16a5f78649309a5 (diff)
downloadmitmproxy-97b2e6d958a691060746b530219bf15a0bede1ae.tar.gz
mitmproxy-97b2e6d958a691060746b530219bf15a0bede1ae.tar.bz2
mitmproxy-97b2e6d958a691060746b530219bf15a0bede1ae.zip
Add a .setter helper to Options
This returns a function that sets a named attribute, and is handy for event-driven code like mitmproxy console.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_options.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/test/mitmproxy/test_options.py b/test/mitmproxy/test_options.py
index 5fdb7abe..97db9430 100644
--- a/test/mitmproxy/test_options.py
+++ b/test/mitmproxy/test_options.py
@@ -3,7 +3,7 @@ import copy
from mitmproxy import options
from mitmproxy import exceptions
-from netlib.tutils import raises
+from netlib import tutils
class TO(options.Options):
@@ -19,8 +19,8 @@ def test_options():
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")
+ tutils.raises("no such option", setattr, o, "nonexistent", "value")
+ tutils.raises("no such option", o.update, nonexistent = "value")
rec = []
@@ -38,6 +38,14 @@ def test_options():
assert rec[-1].one == "oink"
+def test_setter():
+ o = TO(two="three")
+ f = o.setter("two")
+ f("xxx")
+ assert o.two == "xxx"
+ tutils.raises("no such option", o.setter, "nonexistent")
+
+
def test_rollback():
o = TO(one="two")