How to use register_option method in avocado

Best Python code snippet using avocado_python Github


Full Screen

...19 # Our test fixture in sets "chained_assignment"20 # to "raise" only after all test methods have been setup.21 # However, after this setup, there is no longer any22 # "chained_assignment" option, so re-register it.23"chained_assignment", "raise")24 def teardown_method(self, method):25 setattr(, "_global_config", self.gc)26 setattr(, "_deprecated_options", setattr(, "_registered_options", def test_api(self):29 # the pandas object exposes the user API30 assert hasattr(pd, "get_option")31 assert hasattr(pd, "set_option")32 assert hasattr(pd, "reset_option")33 assert hasattr(pd, "describe_option")34 def test_is_one_of_factory(self):35 v =[None, 12])36 v(12)37 v(None)38 msg = r"Value must be one of None\|12"39 with pytest.raises(ValueError, match=msg):40 v(1.1)41 def test_register_option(self):42"a", 1, "doc")43 # can't register an already registered option44 msg = "Option 'a' has already been registered"45 with pytest.raises(OptionError, match=msg):46"a", 1, "doc")47 # can't register an already registered option48 msg = "Path prefix to option 'a' is already an option"49 with pytest.raises(OptionError, match=msg):50"a.b.c.d1", 1, "doc")51 with pytest.raises(OptionError, match=msg):52"a.b.c.d2", 1, "doc")53 # no python keywords54 msg = "for is a python keyword"55 with pytest.raises(ValueError, match=msg):56"for", 0)57 with pytest.raises(ValueError, match=msg):58"a.for.b", 0)59 # must be valid identifier (ensure attribute access works)60 msg = "oh my goddess! is not a valid identifier"61 with pytest.raises(ValueError, match=msg):62"Oh my Goddess!", 0)63 # we can register options several levels deep64 # without predefining the intermediate steps65 # and we can define differently named options66 # in the same namespace67"k.b.c.d1", 1, "doc")68"k.b.c.d2", 1, "doc")69 def test_describe_option(self):70"a", 1, "doc")71"b", 1, "doc2")72"b")73"c.d.e1", 1, "doc3")74"c.d.e2", 1, "doc4")75"f", 1)76"g.h", 1)77"k", 2)78"g.h", rkey="k")79"l", "foo")80 # non-existent keys raise KeyError81 msg = r"No such keys\(s\)"82 with pytest.raises(OptionError, match=msg):83"no.such.key")84 # we can get the description for any key we registered85 assert "doc" in"a", _print_desc=False)86 assert "doc2" in"b", _print_desc=False)87 assert "precated" in"b", _print_desc=False)88 assert "doc3" in"c.d.e1", _print_desc=False)89 assert "doc4" in"c.d.e2", _print_desc=False)90 # if no doc is specified we get a default message91 # saying "description not available"92 assert "vailable" in"f", _print_desc=False)93 assert "vailable" in"g.h", _print_desc=False)94 assert "precated" in"g.h", _print_desc=False)95 assert "k" in"g.h", _print_desc=False)96 # default is reported97 assert "foo" in"l", _print_desc=False)98 # current value is reported99 assert "bar" not in"l", _print_desc=False)100"l", "bar")101 assert "bar" in"l", _print_desc=False)102 def test_case_insensitive(self):103"KanBAN", 1, "doc")104 assert "doc" in"kanbaN", _print_desc=False)105 assert"kanBaN") == 1106"KanBan", 2)107 assert"kAnBaN") == 2108 # gets of non-existent keys fail109 msg = r"No such keys\(s\): 'no_such_option'"110 with pytest.raises(OptionError, match=msg):111"no_such_option")112"KanBan")113 assert"kAnBaN")114 def test_get_option(self):115"a", 1, "doc")116"b.c", "hullo", "doc2")117"b.b", None, "doc2")118 # gets of existing keys succeed119 assert"a") == 1120 assert"b.c") == "hullo"121 assert"b.b") is None122 # gets of non-existent keys fail123 msg = r"No such keys\(s\): 'no_such_option'"124 with pytest.raises(OptionError, match=msg):125"no_such_option")126 def test_set_option(self):127"a", 1, "doc")128"b.c", "hullo", "doc2")129"b.b", None, "doc2")130 assert"a") == 1131 assert"b.c") == "hullo"132 assert"b.b") is None133"a", 2)134"b.c", "wurld")135"b.b", 1.1)136 assert"a") == 2137 assert"b.c") == "wurld"138 assert"b.b") == 1.1139 msg = r"No such keys\(s\): 'no.such.key'"140 with pytest.raises(OptionError, match=msg):141"no.such.key", None)142 def test_set_option_empty_args(self):143 msg = "Must provide an even number of non-keyword arguments"144 with pytest.raises(ValueError, match=msg):145 def test_set_option_uneven_args(self):147 msg = "Must provide an even number of non-keyword arguments"148 with pytest.raises(ValueError, match=msg):149"a.b", 2, "b.c")150 def test_set_option_invalid_single_argument_type(self):151 msg = "Must provide an even number of non-keyword arguments"152 with pytest.raises(ValueError, match=msg):153 def test_set_option_multiple(self):155"a", 1, "doc")156"b.c", "hullo", "doc2")157"b.b", None, "doc2")158 assert"a") == 1159 assert"b.c") == "hullo"160 assert"b.b") is None161"a", "2", "b.c", None, "b.b", 10.0)162 assert"a") == "2"163 assert"b.c") is None164 assert"b.b") == 10.0165 def test_validation(self):166"a", 1, "doc","d", 1, "doc","b.c", "hullo", "doc2", msg = "Value must have type '<class 'int'>'"170 with pytest.raises(ValueError, match=msg):171"a.b.c.d2", "NO", "doc","a", 2) # int is_int173"b.c", "wurld") # str is_str174"d", 2)175"d", None) # non-negative int can be None176 # None not is_int177 with pytest.raises(ValueError, match=msg):178"a", None)179 with pytest.raises(ValueError, match=msg):180"a", "ab")181 msg = "Value must be a nonnegative integer or None"182 with pytest.raises(ValueError, match=msg):183 "a.b.c.d3", "NO", "doc", )186 with pytest.raises(ValueError, match=msg):187 "a.b.c.d3", -2, "doc", )190 msg = r"Value must be an instance of <class 'str'>\|<class 'bytes'>"191 with pytest.raises(ValueError, match=msg):192"b.c", 1)193 validator =[None,])194"b", lambda: None, "doc", validator=validator)195"b", "%.1f".format) # Formatter is callable196"b", None) # Formatter is none (default)197 with pytest.raises(ValueError, match="Value must be a callable"):198"b", "%.1f")199 def test_reset_option(self):200"a", 1, "doc","b.c", "hullo", "doc2", assert"a") == 1203 assert"b.c") == "hullo"204"a", 2)205"b.c", "wurld")206 assert"a") == 2207 assert"b.c") == "wurld"208"a")209 assert"a") == 1210 assert"b.c") == "wurld"211"b.c")212 assert"a") == 1213 assert"b.c") == "hullo"214 def test_reset_option_all(self):215"a", 1, "doc","b.c", "hullo", "doc2", assert"a") == 1218 assert"b.c") == "hullo"219"a", 2)220"b.c", "wurld")221 assert"a") == 2222 assert"b.c") == "wurld"223"all")224 assert"a") == 1225 assert"b.c") == "hullo"226 def test_deprecate_option(self):227 # we can deprecate non-existent options228"foo")229 assert"foo")230 with warnings.catch_warnings(record=True) as w:231 warnings.simplefilter("always")232 with pytest.raises(KeyError, match="No such keys.s.: 'foo'"):233"foo")234 assert len(w) == 1 # should have raised one warning235 assert "deprecated" in str(w[-1]) # we get the default message236"a", 1, "doc","b.c", "hullo", "doc2")238"foo", "hullo", "doc2")239"a", removal_ver="nifty_ver")240 with warnings.catch_warnings(record=True) as w:241 warnings.simplefilter("always")242"a")243 assert len(w) == 1 # should have raised one warning244 assert "eprecated" in str(w[-1]) # we get the default message245 assert "nifty_ver" in str(w[-1]) # with the removal_ver quoted246 msg = "Option 'a' has already been defined as deprecated"247 with pytest.raises(OptionError, match=msg):248"a")249"b.c", "zounds!")250 with warnings.catch_warnings(record=True) as w:251 warnings.simplefilter("always")252"b.c")253 assert len(w) == 1 # should have raised one warning254 assert "zounds!" in str(w[-1]) # we get the custom message255 # test rerouting keys256"d.a", "foo", "doc2")257"d.dep", "bar", "doc2")258 assert"d.a") == "foo"259 assert"d.dep") == "bar"260"d.dep", rkey="d.a") # reroute d.dep to d.a261 with warnings.catch_warnings(record=True) as w:262 warnings.simplefilter("always")263 assert"d.dep") == "foo"264 assert len(w) == 1 # should have raised one warning265 assert "eprecated" in str(w[-1]) # we get the custom message266 with warnings.catch_warnings(record=True) as w:267 warnings.simplefilter("always")268"d.dep", "baz") # should overwrite "d.a"269 assert len(w) == 1 # should have raised one warning270 assert "eprecated" in str(w[-1]) # we get the custom message271 with warnings.catch_warnings(record=True) as w:272 warnings.simplefilter("always")273 assert"d.dep") == "baz"274 assert len(w) == 1 # should have raised one warning275 assert "eprecated" in str(w[-1]) # we get the custom message276 def test_config_prefix(self):277 with"base"):278"a", 1, "doc1")279"b", 2, "doc2")280 assert"a") == 1281 assert"b") == 2282"a", 3)283"b", 4)284 assert"a") == 3285 assert"b") == 4286 assert"base.a") == 3287 assert"base.b") == 4288 assert "doc1" in"base.a", _print_desc=False)289 assert "doc2" in"base.b", _print_desc=False)290"base.a")291"base.b")292 with"base"):293 assert"a") == 1294 assert"b") == 2295 def test_callback(self):296 k = [None]297 v = [None]298 def callback(key):299 k.append(key)300 v.append("d.a", "foo", cb=callback)302"d.b", "foo", cb=callback)303 del k[-1], v[-1]304"d.a", "fooz")305 assert k[-1] == "d.a"306 assert v[-1] == "fooz"307 del k[-1], v[-1]308"d.b", "boo")309 assert k[-1] == "d.b"310 assert v[-1] == "boo"311 del k[-1], v[-1]312"d.b")313 assert k[-1] == "d.b"314 def test_set_ContextManager(self):315 def eq(val):316 assert"a") == val317"a", 0)318 eq(0)319 with"a", 15):320 eq(15)321 with"a", 25):322 eq(25)323 eq(15)324 eq(0)325"a", 17)326 eq(17)327 def test_attribute_access(self):328 holder = []329 def f3(key):330 holder.append(True)331"a", 0)332"c", 0, cb=f3)333 options = assert options.a == 0335 with"a", 15):336 assert options.a == 15337 options.a = 500338 assert"a") == 500339"a")340 assert options.a =="a", 0)341 msg = "You can only set the value of existing options"342 with pytest.raises(OptionError, match=msg):343 options.b = 1344 with pytest.raises(OptionError, match=msg):345 options.display = 1346 # make sure callback kicks when using this form of setting347 options.c = 1348 assert len(holder) == 1349 def test_option_context_scope(self):350 # Ensure that creating a context does not affect the existing351 # environment as it is supposed to be used with the `with` statement.352 # See original_value = 60354 context_value = 10355 option_name = "a"356, original_value)357 # Ensure creating contexts didn't affect the current context.358 ctx =, context_value)359 assert == original_value360 # Ensure the correct value is available inside the context.361 with ctx:362 assert == context_value363 # Ensure the current context is reset364 assert == original_value365 def test_dictwrapper_getattr(self):366 options = # GH 19789368 with pytest.raises(OptionError, match="No such option"):369 options.bananas370 assert not hasattr(options, "bananas")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?