From 97b2e6d958a691060746b530219bf15a0bede1ae Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 14 Jul 2016 11:11:41 +1200 Subject: 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. --- test/mitmproxy/test_options.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'test') 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") -- cgit v1.2.3