How to use test_config method in autotest

Best Python code snippet using autotest_python

test_config.py

Source:test_config.py Github

copy

Full Screen

1from __future__ import absolute_import2import copy3import os4from unittest import mock5import mozunit6import pytest7import conftest8from talos.config import (9 get_active_tests,10 get_test,11 get_config,12 get_browser_config,13 get_configs,14 ConfigurationError,15 DEFAULTS,16)17from talos.test import PageloaderTest18import six19ORIGINAL_DEFAULTS = copy.deepcopy(DEFAULTS)20class mock_test(PageloaderTest):21 keys = [22 "tpmanifest",23 "tpcycles",24 "tppagecycles",25 "tprender",26 "tpchrome",27 "tpmozafterpaint",28 "fnbpaint",29 "tploadnocache",30 "firstpaint",31 "userready",32 "testeventmap",33 "base_vs_ref",34 "mainthread",35 "resolution",36 "cycles",37 "gecko_profile",38 "gecko_profile_interval",39 "gecko_profile_entries",40 "tptimeout",41 "win_counters",42 "w7_counters",43 "linux_counters",44 "mac_counters",45 "tpscrolltest",46 "xperf_counters",47 "timeout",48 "shutdown",49 "responsiveness",50 "profile_path",51 "xperf_providers",52 "xperf_user_providers",53 "xperf_stackwalk",54 "format_pagename",55 "filters",56 "preferences",57 "extensions",58 "setup",59 "cleanup",60 "lower_is_better",61 "alert_threshold",62 "unit",63 "webextensions",64 "profile",65 "tpmozafterpaint",66 "url",67 ]68 tpmozafterpaint = "value"69 firstpaint = "value"70 userready = "value"71 fnbpaint = "value"72class Test_get_active_tests(object):73 def test_raises_exception_for_undefined_test(self):74 with pytest.raises(ConfigurationError):75 get_active_tests({"activeTests": "undefined_test"})76 with pytest.raises(ConfigurationError):77 get_active_tests({"activeTests": " undefined_test "})78 with pytest.raises(ConfigurationError):79 get_active_tests({"activeTests": "undef_test:undef_test2:undef_test3"})80class Test_get_test(object):81 global_overrides = {82 "tpmozafterpaint": "overriden",83 "firstpaint": "overriden",84 "userready": "overriden",85 "fnbpaint": "overriden",86 }87 config = {"webserver": "test_webserver"}88 def test_doesnt_override_specific_keys_unless_they_are_null(self):89 test_instance = mock_test()90 test_dict = get_test({}, self.global_overrides, [], test_instance)91 assert test_dict["tpmozafterpaint"] == "value"92 assert test_dict["firstpaint"] == "value"93 assert test_dict["userready"] == "value"94 assert test_dict["fnbpaint"] == "value"95 # nulls still get overriden96 test_instance = mock_test(97 tpmozafterpaint=None, firstpaint=None, userready=None, fnbpaint=None98 )99 test_dict = get_test({}, self.global_overrides, [], test_instance)100 assert test_dict["tpmozafterpaint"] == "overriden"101 assert test_dict["firstpaint"] == "overriden"102 assert test_dict["userready"] == "overriden"103 assert test_dict["fnbpaint"] == "overriden"104 @mock.patch("talos.config.open", create=True)105 def test_interpolate_keys(self, mock_open):106 mock_open.return_value = mock.MagicMock(readlines=lambda: [])107 test_instance = mock_test(108 url="${talos}/test_page.html", tpmanifest="${talos}/file.manifest"109 )110 test_dict = get_test(self.config, self.global_overrides, [], test_instance)111 assert test_dict["url"].startswith("http://test_webserver/")112 assert "${talos}" not in test_dict["url"]113 assert "${talos}" not in test_dict["tpmanifest"]114 def test_build_tpmanifest(self, tmpdir):115 manifest_file = tmpdir.join("file.manifest").ensure(file=True)116 test_instance = mock_test(url="test_page.html", tpmanifest=str(manifest_file))117 test_dict = get_test(self.config, self.global_overrides, [], test_instance)118 assert test_dict["tpmanifest"].endswith(".develop")119 def test_add_counters(self):120 test_instance = mock_test(121 linux_counters=None,122 mac_counters=[],123 win_counters=["counter_a"],124 w7_counters=["counter_a", "counter_b"],125 xperf_counters=["counter_a", "counter_extra"],126 )127 counters = ["counter_a", "counter_b", "counter_c"]128 test_dict = get_test(129 self.config, self.global_overrides, counters, test_instance130 )131 assert test_dict["linux_counters"] == counters132 assert test_dict["mac_counters"] == counters133 assert test_dict["win_counters"] == counters134 assert test_dict["w7_counters"] == counters135 assert set(test_dict["xperf_counters"]) == set(counters + ["counter_extra"])136class Test_get_browser_config(object):137 required = (138 "extensions",139 "browser_path",140 "browser_wait",141 "extra_args",142 "buildid",143 "env",144 "init_url",145 "webserver",146 )147 optional = [148 "bcontroller_config",149 "child_process",150 "debug",151 "debugger",152 "debugger_args",153 "develop",154 "e10s",155 "process",156 "framework",157 "repository",158 "sourcestamp",159 "symbols_path",160 "test_timeout",161 "xperf_path",162 "error_filename",163 "no_upload_results",164 "stylothreads",165 "subtests",166 "preferences",167 ]168 def test_that_contains_title(self):169 config_no_optionals = dict.fromkeys(self.required, "")170 config_no_optionals.update(title="is_mandatory")171 browser_config = get_browser_config(config_no_optionals)172 assert browser_config["title"] == "is_mandatory"173 def test_raises_keyerror_for_missing_title(self):174 config_missing_title = dict.fromkeys(self.required, "")175 with pytest.raises(KeyError):176 get_browser_config(config_missing_title)177 def test_raises_keyerror_for_required_keys(self):178 config_missing_required = dict.fromkeys(self.required, "")179 config_missing_required.update(title="is_mandatory")180 del config_missing_required["extensions"]181 with pytest.raises(KeyError):182 get_browser_config(config_missing_required)183 def test_doesnt_raise_on_missing_optionals(self):184 config_missing_optionals = dict.fromkeys(self.required, "")185 config_missing_optionals["title"] = "is_mandatory"186 try:187 get_browser_config(config_missing_optionals)188 except KeyError:189 pytest.fail("Must not raise exception on missing optional")190class Test_get_config(object):191 @classmethod192 def setup_class(cls):193 cls.argv = "--suite other-e10s --mainthread -e /some/random/path".split()194 cls.argv_unprovided_tests = "-e /some/random/path".split()195 cls.argv_unknown_suite = (196 "--suite random-unknown-suite -e /some/random/path".split()197 )198 cls.argv_overrides_defaults = """199 --suite other-e10s200 --executablePath /some/random/path201 --cycles 20202 --gecko-profile203 --gecko-profile-interval 1000204 --gecko-profile-entries 1000205 --mainthread206 --tpcycles 20207 --mozAfterPaint208 --firstPaint209 --firstNonBlankPaint210 --userReady211 --tppagecycles 20212 """.split()213 cls.argv_ts_paint = "--activeTests ts_paint -e /some/random/path".split()214 cls.argv_ts_paint_webext = (215 "--activeTests ts_paint_webext -e /some/random/path".split()216 )217 cls.argv_ts_paint_heavy = (218 "--activeTests ts_paint_heavy -e /some/random/path".split()219 )220 cls.argv_sessionrestore = (221 "--activeTests sessionrestore -e /some/random/path".split()222 )223 cls.argv_sessionrestore_no_auto_restore = (224 "--activeTests sessionrestore_no_auto_restore -e /some/random/path".split()225 )226 cls.argv_sessionrestore_many_windows = (227 "--activeTests sessionrestore_many_windows -e /some/random/path".split()228 )229 cls.argv_tresize = "--activeTests tresize -e /some/random/path".split()230 cls.argv_cpstartup = "--activeTests cpstartup -e /some/random/path".split()231 cls.argv_tabpaint = "--activeTests tabpaint -e /some/random/path".split()232 cls.argv_tabswitch = "--activeTests tabswitch -e /some/random/path".split()233 cls.argv_tart = "--activeTests tart -e /some/random/path".split()234 cls.argv_damp = "--activeTests damp -e /some/random/path".split()235 cls.argv_glterrain = "--activeTests glterrain -e /some/random/path".split()236 cls.argv_glvideo = "--activeTests glvideo -e /some/random/path".split()237 cls.argv_tp5n = "--activeTests tp5n -e /some/random/path".split()238 cls.argv_tp5o = "--activeTests tp5o -e /some/random/path".split()239 cls.argv_tp5o_webext = "--activeTests tp5o_webext -e /some/random/path".split()240 cls.argv_tp5o_scroll = "--activeTests tp5o_scroll -e /some/random/path".split()241 cls.argv_v8_7 = "--activeTests v8_7 -e /some/random/path".split()242 cls.argv_kraken = "--activeTests kraken -e /some/random/path".split()243 cls.argv_basic_compositor_video = (244 "--activeTests basic_compositor_video -e /some/random/path".split()245 )246 cls.argv_dromaeo_css = "--activeTests dromaeo_css -e /some/random/path".split()247 cls.argv_dromaeo_dom = "--activeTests dromaeo_dom -e /some/random/path".split()248 cls.argv_tsvgm = "--activeTests tsvgm -e /some/random/path".split()249 cls.argv_tsvgx = "--activeTests tsvgx -e /some/random/path".split()250 cls.argv_tsvg_static = "--activeTests tsvg_static -e /some/random/path".split()251 cls.argv_tsvgr_opacity = (252 "--activeTests tsvgr_opacity -e /some/random/path".split()253 )254 cls.argv_tscrollx = "--activeTests tscrollx -e /some/random/path".split()255 cls.argv_a11yr = "--activeTests a11yr -e /some/random/path".split()256 cls.argv_perf_reftest = (257 "--activeTests perf_reftest -e /some/random/path".split()258 )259 cls.argv_perf_reftest_singletons = (260 "--activeTests perf_reftest_singletons -e /some/random/path".split()261 )262 @classmethod263 def teardown_class(cls):264 conftest.remove_develop_files()265 def test_correctly_overrides_test_valus(self):266 config = get_config(self.argv)267 assert bool(config) is True268 # no null values269 null_keys = [key for key, val in six.iteritems(config) if val is None]270 assert len(null_keys) == 0271 # expected keys are there272 assert config["browser_path"] == "/some/random/path"273 assert config["suite"] == "other-e10s"274 assert config["mainthread"] is True275 # default values overriden276 config = get_config(self.argv_overrides_defaults)277 assert config["basetest"] == ORIGINAL_DEFAULTS["basetest"]278 def test_config_has_tests(self):279 config = get_config(self.argv)280 assert len(config["tests"]) > 0281 def test_global_variable_isnt_modified(self):282 get_config(self.argv)283 assert ORIGINAL_DEFAULTS == DEFAULTS284 def test_raises_except_if_unprovided_tests_on_cli(self):285 with pytest.raises(ConfigurationError):286 get_config(self.argv_unprovided_tests)287 with pytest.raises(ConfigurationError):288 get_config(self.argv_unknown_suite)289 def test_ts_paint_has_expected_attributes(self):290 config = get_config(self.argv_ts_paint)291 test_config = config["tests"][0]292 assert test_config["name"] == "ts_paint"293 assert test_config["cycles"] == 20294 assert test_config["timeout"] == 150295 assert test_config["gecko_profile_startup"] is True296 assert test_config["gecko_profile_entries"] == 10000000297 assert (298 test_config["url"] != "startup_test/tspaint_test.html"299 ) # interpolation was done300 assert test_config["xperf_counters"] == []301 # TODO: these don't work; is this a bug?302 # assert test_config['win7_counters'] == []303 assert test_config["filters"] is not None304 assert test_config["tpmozafterpaint"] is True305 # assert test_config['mainthread'] is False306 # assert test_config['responsiveness'] is False307 # assert test_config['unit'] == 'ms'308 def test_ts_paint_webext_has_expected_attributes(self):309 config = get_config(self.argv_ts_paint_webext)310 test_config = config["tests"][0]311 assert test_config["name"] == "ts_paint_webext"312 assert test_config["cycles"] == 20313 assert test_config["timeout"] == 150314 assert test_config["gecko_profile_startup"] is True315 assert test_config["gecko_profile_entries"] == 10000000316 assert (317 test_config["url"] != "startup_test/tspaint_test.html"318 ) # interpolation was done319 assert test_config["xperf_counters"] == []320 # TODO: these don't work; is this a bug?321 # assert test_config['win7_counters'] == []322 assert test_config["filters"] is not None323 assert test_config["tpmozafterpaint"] is True324 # assert test_config['mainthread'] is False325 # assert test_config['responsiveness'] is False326 # assert test_config['unit'] == 'ms'327 # TODO: this isn't overriden328 # assert test_config['webextensions'] != '${talos}/webextensions/dummy/dummy-signed.xpi'329 assert test_config["preferences"] == {"xpinstall.signatures.required": False}330 def test_ts_paint_heavy_has_expected_attributes(self):331 config = get_config(self.argv_ts_paint_heavy)332 test_config = config["tests"][0]333 assert test_config["name"] == "ts_paint_heavy"334 assert test_config["cycles"] == 20335 assert test_config["timeout"] == 150336 assert test_config["gecko_profile_startup"] is True337 assert test_config["gecko_profile_entries"] == 10000000338 assert (339 test_config["url"] != "startup_test/tspaint_test.html"340 ) # interpolation was done341 assert test_config["xperf_counters"] == []342 # TODO: this doesn't work; is this a bug?343 # assert test_config['win7_counters'] == []344 assert test_config["filters"] is not None345 assert test_config["tpmozafterpaint"] is True346 # assert test_config['mainthread'] is False347 # assert test_config['responsiveness'] is False348 # assert test_config['unit'] == 'ms'349 assert test_config["profile"] == "simple"350 def test_sessionrestore_has_expected_attributes(self):351 config = get_config(self.argv_sessionrestore)352 test_config = config["tests"][0]353 assert test_config["name"] == "sessionrestore"354 assert test_config["cycles"] == 10355 assert test_config["timeout"] == 900356 assert test_config["gecko_profile_startup"] is True357 assert test_config["gecko_profile_entries"] == 10000000358 assert test_config["reinstall"] == [359 "sessionstore.jsonlz4",360 "sessionstore.js",361 "sessionCheckpoints.json",362 ]363 assert test_config["url"] == "about:home"364 assert test_config["preferences"] == {"browser.startup.page": 3}365 # assert test_config['unit'] == 'ms'366 def test_sesssionrestore_no_auto_restore_has_expected_attributes(self):367 config = get_config(self.argv_sessionrestore_no_auto_restore)368 test_config = config["tests"][0]369 assert test_config["name"] == "sessionrestore_no_auto_restore"370 assert test_config["cycles"] == 10371 assert test_config["timeout"] == 900372 assert test_config["gecko_profile_startup"] is True373 assert test_config["gecko_profile_entries"] == 10000000374 assert test_config["reinstall"] == [375 "sessionstore.jsonlz4",376 "sessionstore.js",377 "sessionCheckpoints.json",378 ]379 assert test_config["url"] == "about:home"380 assert test_config["preferences"] == {"browser.startup.page": 1}381 # assert test_config['unit'] == 'ms'382 def test_sessionrestore_many_windows_has_expected_attributes(self):383 config = get_config(self.argv_sessionrestore_many_windows)384 test_config = config["tests"][0]385 assert test_config["name"] == "sessionrestore_many_windows"386 assert test_config["cycles"] == 10387 assert test_config["timeout"] == 900388 assert test_config["gecko_profile_startup"] is True389 assert test_config["gecko_profile_entries"] == 10000000390 assert test_config["reinstall"] == [391 "sessionstore.jsonlz4",392 "sessionstore.js",393 "sessionCheckpoints.json",394 ]395 assert test_config["url"] == "about:home"396 assert test_config["preferences"] == {"browser.startup.page": 3}397 # assert test_config['unit'] == 'ms'398 def test_tresize_has_expected_attributes(self):399 config = get_config(self.argv_tresize)400 test_config = config["tests"][0]401 assert test_config["name"] == "tresize"402 assert test_config["cycles"] == 20403 assert (404 test_config["url"] != "startup_test/tresize/addon/content/tresize-test.html"405 )406 assert test_config["timeout"] == 150407 assert test_config["gecko_profile_interval"] == 2408 assert test_config["gecko_profile_entries"] == 1000000409 assert test_config["tpmozafterpaint"] is True410 assert test_config["filters"] is not None411 # assert test_config['unit'] == 'ms'412 def test_cpstartup_has_expected_attributes(self):413 config = get_config(self.argv_cpstartup)414 test_config = config["tests"][0]415 assert test_config["name"] == "cpstartup"416 assert test_config["tpcycles"] == 1417 assert (418 test_config["tpmanifest"] != "${talos}/tests/cpstartup/cpstartup.manifest"419 )420 assert test_config["tppagecycles"] == 20421 assert test_config["gecko_profile_entries"] == 1000000422 assert test_config["tploadnocache"] is True423 assert test_config["unit"] == "ms"424 assert test_config["preferences"] == {425 "addon.test.cpstartup.webserver": "${webserver}",426 "browser.link.open_newwindow": 3,427 "browser.link.open_newwindow.restriction": 2,428 }429 def test_tabpaint_has_expected_attributes(self):430 config = get_config(self.argv_tabpaint)431 test_config = config["tests"][0]432 assert test_config["name"] == "tabpaint"433 assert test_config["tpcycles"] == 1434 assert test_config["tpmanifest"] != "${talos}/tests/tabpaint/tabpaint.manifest"435 assert test_config["tppagecycles"] == 20436 assert test_config["gecko_profile_entries"] == 1000000437 assert test_config["tploadnocache"] is True438 assert test_config["unit"] == "ms"439 assert test_config["preferences"] == {440 "browser.link.open_newwindow": 3,441 "browser.link.open_newwindow.restriction": 2,442 }443 def test_tabswitch_has_expected_attributes(self):444 config = get_config(self.argv_tabswitch)445 test_config = config["tests"][0]446 assert test_config["name"] == "tabswitch"447 assert test_config["tpcycles"] == 1448 assert (449 test_config["tpmanifest"] != "${talos}/tests/tabswitch/tabswitch.manifest"450 )451 assert test_config["tppagecycles"] == 5452 assert test_config["gecko_profile_entries"] == 5000000453 assert test_config["tploadnocache"] is True454 assert test_config["preferences"] == {455 "addon.test.tabswitch.urlfile": os.path.join(456 "${talos}", "tests", "tp5o.html"457 ),458 "addon.test.tabswitch.webserver": "${webserver}",459 "addon.test.tabswitch.maxurls": -1,460 }461 assert test_config["unit"] == "ms"462 def test_tart_has_expected_attributes(self):463 config = get_config(self.argv_tart)464 test_config = config["tests"][0]465 assert test_config["name"] == "tart"466 assert test_config["tpmanifest"] != "${talos}/tests/tart/tart.manifest"467 assert test_config["tpcycles"] == 1468 assert test_config["tppagecycles"] == 25469 assert test_config["tploadnocache"] is True470 assert test_config["tpmozafterpaint"] is False471 assert test_config["gecko_profile_interval"] == 10472 assert test_config["gecko_profile_entries"] == 1000000473 assert "win_counters" not in test_config474 assert "w7_counters" not in test_config475 assert "linux_counters" not in test_config476 assert "mac_counters" not in test_config477 assert test_config["preferences"] == {478 "layout.frame_rate": 0,479 "docshell.event_starvation_delay_hint": 1,480 "dom.send_after_paint_to_content": False,481 }482 assert test_config["filters"] is not None483 assert test_config["unit"] == "ms"484 def test_damp_has_expected_attributes(self):485 config = get_config(self.argv_damp)486 test_config = config["tests"][0]487 assert test_config["name"] == "damp"488 assert test_config["tpmanifest"] != "${talos}/tests/devtools/damp.manifest"489 assert test_config["cycles"] == 5490 assert test_config["tpcycles"] == 1491 assert test_config["tppagecycles"] == 5492 assert test_config["tploadnocache"] is True493 assert test_config["tpmozafterpaint"] is False494 assert test_config["gecko_profile_interval"] == 10495 assert test_config["gecko_profile_entries"] == 1000000496 assert "win_counters" not in test_config497 assert "w7_counters" not in test_config498 assert "linux_counters" not in test_config499 assert "mac_counters" not in test_config500 assert test_config["filters"] is not None501 assert test_config["preferences"] == {"devtools.memory.enabled": True}502 assert test_config["unit"] == "ms"503 def test_glterrain_has_expected_attributes(self):504 config = get_config(self.argv_glterrain)505 test_config = config["tests"][0]506 assert test_config["name"] == "glterrain"507 assert test_config["tpmanifest"] != "${talos}/tests/webgl/glterrain.manifest"508 assert test_config["tpcycles"] == 1509 assert test_config["tppagecycles"] == 25510 assert test_config["tploadnocache"] is True511 assert test_config["tpmozafterpaint"] is False512 assert test_config["tpchrome"] is False513 assert test_config["gecko_profile_interval"] == 10514 assert test_config["gecko_profile_entries"] == 2000000515 assert "win_counters" not in test_config516 assert "w7_counters" not in test_config517 assert "linux_counters" not in test_config518 assert "mac_counters" not in test_config519 assert test_config["preferences"] == {520 "layout.frame_rate": 0,521 "docshell.event_starvation_delay_hint": 1,522 "dom.send_after_paint_to_content": False,523 }524 assert test_config["filters"] is not None525 assert test_config["unit"] == "frame interval"526 def test_glvideo_has_expected_attributes(self):527 config = get_config(self.argv_glvideo)528 test_config = config["tests"][0]529 assert test_config["name"] == "glvideo"530 assert test_config["tpmanifest"] != "${talos}/tests/webgl/glvideo.manifest"531 assert test_config["tpcycles"] == 1532 assert test_config["tppagecycles"] == 5533 assert test_config["tploadnocache"] is True534 assert test_config["tpmozafterpaint"] is False535 assert test_config["tpchrome"] is False536 assert test_config["gecko_profile_interval"] == 2537 assert test_config["gecko_profile_entries"] == 2000000538 assert "win_counters" not in test_config539 assert "w7_counters" not in test_config540 assert "linux_counters" not in test_config541 assert "mac_counters" not in test_config542 assert test_config["filters"] is not None543 assert test_config["unit"] == "ms"544 @mock.patch("talos.config.build_manifest", conftest.patched_build_manifest)545 def test_tp5n_has_expected_attributes(self):546 config = get_config(self.argv_tp5n)547 test_config = config["tests"][0]548 assert test_config["name"] == "tp5n"549 assert test_config["resolution"] == 20550 assert test_config["tpmanifest"] != "${talos}/tests/tp5n/tp5n.manifest"551 assert test_config["tpcycles"] == 1552 assert test_config["tppagecycles"] == 1553 assert test_config["cycles"] == 1554 assert test_config["tpmozafterpaint"] is True555 assert test_config["tptimeout"] == 5000556 assert test_config["mainthread"] is True557 assert test_config["w7_counters"] == []558 assert test_config["win_counters"] == []559 assert test_config["linux_counters"] == []560 assert test_config["mac_counters"] == []561 assert test_config["xperf_counters"] == [562 "main_startup_fileio",563 "main_startup_netio",564 "main_normal_fileio",565 "main_normal_netio",566 "nonmain_startup_fileio",567 "nonmain_normal_fileio",568 "nonmain_normal_netio",569 "mainthread_readcount",570 "mainthread_readbytes",571 "mainthread_writecount",572 "mainthread_writebytes",573 ]574 assert test_config["xperf_providers"] == [575 "PROC_THREAD",576 "LOADER",577 "HARD_FAULTS",578 "FILENAME",579 "FILE_IO",580 "FILE_IO_INIT",581 ]582 assert test_config["xperf_user_providers"] == [583 "Mozilla Generic Provider",584 "Microsoft-Windows-TCPIP",585 ]586 assert test_config["xperf_stackwalk"] == [587 "FileCreate",588 "FileRead",589 "FileWrite",590 "FileFlush",591 "FileClose",592 ]593 assert test_config["filters"] is not None594 assert test_config["timeout"] == 1800595 assert test_config["preferences"] == {596 "extensions.enabledScopes": "",597 "talos.logfile": "browser_output.txt",598 }599 assert test_config["unit"] == "ms"600 @mock.patch("talos.config.build_manifest", conftest.patched_build_manifest)601 def test_tp5o_has_expected_attributes(self):602 config = get_config(self.argv_tp5o)603 test_config = config["tests"][0]604 assert test_config["name"] == "tp5o"605 assert test_config["tpcycles"] == 1606 assert test_config["tppagecycles"] == 25607 assert test_config["cycles"] == 1608 assert test_config["tpmozafterpaint"] is True609 assert test_config["tptimeout"] == 5000610 assert test_config["mainthread"] is False611 assert test_config["tpmanifest"] != "${talos}/tests/tp5n/tp5o.manifest"612 assert test_config["win_counters"] == ["% Processor Time"]613 assert test_config["w7_counters"] == ["% Processor Time"]614 assert test_config["linux_counters"] == ["XRes"]615 assert test_config["mac_counters"] == []616 assert test_config["responsiveness"] is True617 assert test_config["gecko_profile_interval"] == 2618 assert test_config["gecko_profile_entries"] == 4000000619 assert test_config["filters"] is not None620 assert test_config["timeout"] == 1800621 assert test_config["unit"] == "ms"622 @mock.patch("talos.config.build_manifest", conftest.patched_build_manifest)623 def test_tp5o_webext_has_expected_attributes(self):624 config = get_config(self.argv_tp5o_webext)625 test_config = config["tests"][0]626 assert test_config["name"] == "tp5o_webext"627 assert test_config["tpcycles"] == 1628 assert test_config["tppagecycles"] == 25629 assert test_config["cycles"] == 1630 assert test_config["tpmozafterpaint"] is True631 assert test_config["tptimeout"] == 5000632 assert test_config["mainthread"] is False633 assert test_config["tpmanifest"] != "${talos}/tests/tp5n/tp5o.manifest"634 assert test_config["win_counters"] == ["% Processor Time"]635 assert test_config["w7_counters"] == ["% Processor Time"]636 assert test_config["linux_counters"] == ["XRes"]637 assert test_config["mac_counters"] == []638 assert test_config["responsiveness"] is True639 assert test_config["gecko_profile_interval"] == 2640 assert test_config["gecko_profile_entries"] == 4000000641 assert test_config["filters"] is not None642 assert test_config["timeout"] == 1800643 assert test_config["unit"] == "ms"644 assert test_config["webextensions"] == "${talos}/webextensions/dummy/dummy.xpi"645 assert test_config["preferences"] == {"xpinstall.signatures.required": False}646 @mock.patch("talos.config.build_manifest", conftest.patched_build_manifest)647 def test_tp5o_scroll_has_expected_attributes(self):648 config = get_config(self.argv_tp5o_scroll)649 test_config = config["tests"][0]650 assert test_config["name"] == "tp5o_scroll"651 assert test_config["tpmanifest"] != "${talos}/tests/tp5n/tp5o.manifest"652 assert test_config["tpcycles"] == 1653 assert test_config["tppagecycles"] == 12654 assert test_config["gecko_profile_interval"] == 2655 assert test_config["gecko_profile_entries"] == 2000000656 assert test_config["tpscrolltest"] is True657 assert test_config["tpmozafterpaint"] is False658 assert test_config["preferences"] == {659 "layout.frame_rate": 0,660 "docshell.event_starvation_delay_hint": 1,661 "dom.send_after_paint_to_content": False,662 "layout.css.scroll-behavior.spring-constant": "'10'",663 "toolkit.framesRecording.bufferSize": 10000,664 }665 assert test_config["filters"] is not None666 assert test_config["unit"] == "1/FPS"667 def test_v8_7_has_expected_attributes(self):668 config = get_config(self.argv_v8_7)669 test_config = config["tests"][0]670 assert test_config["name"] == "v8_7"671 assert test_config["tpmanifest"] != "${talos}/tests/v8_7/v8.manifest"672 assert test_config["gecko_profile_interval"] == 1673 assert test_config["gecko_profile_entries"] == 1000000674 assert test_config["tpcycles"] == 1675 assert test_config["resolution"] == 20676 assert test_config["tpmozafterpaint"] is False677 assert test_config["preferences"] == {"dom.send_after_paint_to_content": False}678 assert test_config["filters"] is not None679 assert test_config["unit"] == "score"680 assert test_config["lower_is_better"] is False681 def test_kraken_has_expected_attributes(self):682 config = get_config(self.argv_kraken)683 test_config = config["tests"][0]684 assert test_config["name"] == "kraken"685 assert test_config["tpmanifest"] != "${talos}/tests/kraken/kraken.manifest"686 assert test_config["tpcycles"] == 1687 assert test_config["tppagecycles"] == 1688 assert test_config["gecko_profile_interval"] == 1689 assert test_config["gecko_profile_entries"] == 5000000690 assert test_config["tpmozafterpaint"] is False691 assert test_config["tpchrome"] is False692 assert test_config["preferences"] == {"dom.send_after_paint_to_content": False}693 assert test_config["filters"] is not None694 assert test_config["unit"] == "score"695 def test_basic_compositor_video_has_expected_attributes(self):696 config = get_config(self.argv_basic_compositor_video)697 test_config = config["tests"][0]698 assert test_config["name"] == "basic_compositor_video"699 assert test_config["tpmanifest"] != "${talos}/tests/video/video.manifest"700 assert test_config["tpcycles"] == 1701 assert test_config["tppagecycles"] == 12702 assert test_config["tpchrome"] is False703 assert test_config["timeout"] == 10000704 assert test_config["gecko_profile_interval"] == 1705 assert test_config["gecko_profile_entries"] == 2000000706 assert test_config["preferences"] == {707 "full-screen-api.allow-trusted-requests-only": False,708 "layers.acceleration.force-enabled": False,709 "layers.acceleration.disabled": True,710 "layout.frame_rate": 0,711 "docshell.event_starvation_delay_hint": 1,712 "full-screen-api.warning.timeout": 500,713 "media.ruin-av-sync.enabled": True,714 }715 assert test_config["filters"] is not None716 assert test_config["unit"] == "ms/frame"717 assert test_config["lower_is_better"] is True718 def test_dromaeo_css_has_expected_attributes(self):719 config = get_config(self.argv_dromaeo_css)720 test_config = config["tests"][0]721 assert test_config["name"] == "dromaeo_css"722 assert test_config["tpcycles"] == 1723 assert test_config["filters"] is not None724 assert test_config["lower_is_better"] is False725 assert test_config["alert_threshold"] == 5.0726 assert test_config["tpchrome"] is False727 assert test_config["gecko_profile_interval"] == 2728 assert test_config["gecko_profile_entries"] == 10000000729 assert test_config["tpmanifest"] != "${talos}/tests/dromaeo/css.manifest"730 assert test_config["unit"] == "score"731 def test_dromaeo_dom_has_expected_attributes(self):732 config = get_config(self.argv_dromaeo_dom)733 test_config = config["tests"][0]734 assert test_config["name"] == "dromaeo_dom"735 assert test_config["tpcycles"] == 1736 assert test_config["filters"] is not None737 assert test_config["lower_is_better"] is False738 assert test_config["alert_threshold"] == 5.0739 assert test_config["tpchrome"] is False740 assert test_config["gecko_profile_interval"] == 2741 assert test_config["gecko_profile_entries"] == 10000000742 assert test_config["tpmanifest"] != "${talos}/tests/dromaeo/dom.manifest"743 assert test_config["unit"] == "score"744 def test_tsvgm_has_expected_attributes(self):745 config = get_config(self.argv_tsvgm)746 test_config = config["tests"][0]747 assert test_config["name"] == "tsvgm"748 assert test_config["tpmanifest"] != "${talos}/tests/svgx/svgm.manifest"749 assert test_config["tpcycles"] == 1750 assert test_config["tppagecycles"] == 7751 assert test_config["tpmozafterpaint"] is False752 assert test_config["tpchrome"] is False753 assert test_config["gecko_profile_interval"] == 10754 assert test_config["gecko_profile_entries"] == 1000000755 assert test_config["preferences"] == {756 "layout.frame_rate": 0,757 "docshell.event_starvation_delay_hint": 1,758 "dom.send_after_paint_to_content": False,759 }760 assert test_config["filters"] is not None761 assert test_config["unit"] == "ms"762 def test_tsvgx_has_expected_attributes(self):763 config = get_config(self.argv_tsvgx)764 test_config = config["tests"][0]765 assert test_config["name"] == "tsvgx"766 assert test_config["tpmanifest"] != "${talos}/tests/svgx/svgx.manifest"767 assert test_config["tpcycles"] == 1768 assert test_config["tppagecycles"] == 25769 assert test_config["tpmozafterpaint"] is False770 assert test_config["tpchrome"] is False771 assert test_config["gecko_profile_interval"] == 10772 assert test_config["gecko_profile_entries"] == 1000000773 assert test_config["preferences"] == {774 "layout.frame_rate": 0,775 "docshell.event_starvation_delay_hint": 1,776 "dom.send_after_paint_to_content": False,777 }778 assert test_config["filters"] is not None779 assert test_config["unit"] == "ms"780 def test_tsvg_static_has_expected_attributes(self):781 config = get_config(self.argv_tsvg_static)782 test_config = config["tests"][0]783 assert test_config["name"] == "tsvg_static"784 assert (785 test_config["tpmanifest"] != "${talos}/tests/svg_static/svg_static.manifest"786 )787 assert test_config["tpcycles"] == 1788 assert test_config["tppagecycles"] == 25789 assert test_config["tpmozafterpaint"] is True790 assert test_config["tpchrome"] is False791 assert test_config["gecko_profile_interval"] == 1792 assert test_config["gecko_profile_entries"] == 10000000793 assert test_config["filters"] is not None794 assert test_config["unit"] == "ms"795 def test_tsvgr_opacity_has_expected_attributes(self):796 config = get_config(self.argv_tsvgr_opacity)797 test_config = config["tests"][0]798 assert test_config["name"] == "tsvgr_opacity"799 assert (800 test_config["tpmanifest"]801 != "${talos}/tests/svg_opacity/svg_opacity.manifest"802 )803 assert test_config["tpcycles"] == 1804 assert test_config["tppagecycles"] == 25805 assert test_config["tpmozafterpaint"] is True806 assert test_config["tpchrome"] is False807 assert test_config["gecko_profile_interval"] == 1808 assert test_config["gecko_profile_entries"] == 10000000809 assert test_config["filters"] is not None810 assert test_config["unit"] == "ms"811 def test_tscrollx_has_expected_attributes(self):812 config = get_config(self.argv_tscrollx)813 test_config = config["tests"][0]814 assert test_config["name"] == "tscrollx"815 assert test_config["tpmanifest"] != "${talos}/tests/scroll/scroll.manifest"816 assert test_config["tpcycles"] == 1817 assert test_config["tppagecycles"] == 25818 assert test_config["tpmozafterpaint"] is False819 assert test_config["tpchrome"] is False820 assert test_config["gecko_profile_interval"] == 1821 assert test_config["gecko_profile_entries"] == 1000000822 assert test_config["preferences"] == {823 "layout.frame_rate": 0,824 "docshell.event_starvation_delay_hint": 1,825 "dom.send_after_paint_to_content": False,826 "layout.css.scroll-behavior.spring-constant": "'10'",827 "toolkit.framesRecording.bufferSize": 10000,828 }829 assert test_config["filters"] is not None830 assert test_config["unit"] == "ms"831 def test_a11yr_has_expect_attributes(self):832 config = get_config(self.argv_a11yr)833 test_config = config["tests"][0]834 assert test_config["name"] == "a11yr"835 assert test_config["tpmanifest"] != "${talos}/tests/a11y/a11y.manifest"836 assert test_config["tpcycles"] == 1837 assert test_config["tppagecycles"] == 25838 assert test_config["tpmozafterpaint"] is True839 assert test_config["tpchrome"] is False840 assert test_config["preferences"] == {"dom.send_after_paint_to_content": False}841 assert test_config["unit"] == "ms"842 assert test_config["alert_threshold"] == 5.0843 def test_perf_reftest_has_expected_attributes(self):844 config = get_config(self.argv_perf_reftest)845 test_config = config["tests"][0]846 assert test_config["name"] == "perf_reftest"847 assert test_config["base_vs_ref"] is True848 assert (849 test_config["tpmanifest"]850 != "${talos}/tests/perf-reftest/perf_reftest.manifest"851 )852 assert test_config["tpcycles"] == 1853 assert test_config["tppagecycles"] == 10854 assert test_config["tptimeout"] == 30000855 assert test_config["gecko_profile_interval"] == 1856 assert test_config["gecko_profile_entries"] == 2000000857 assert test_config["filters"] is not None858 assert test_config["unit"] == "ms"859 assert test_config["lower_is_better"] is True860 assert test_config["alert_threshold"] == 5.0861 def test_perf_reftest_singletons_has_expected_attributes(self):862 config = get_config(self.argv_perf_reftest_singletons)863 test_config = config["tests"][0]864 assert test_config["name"] == "perf_reftest_singletons"865 assert (866 test_config["tpmanifest"]867 != "${talos}/tests/perf-reftest-singletons/perf_reftest_singletons.manifest"868 )869 assert test_config["tpcycles"] == 1870 assert test_config["tppagecycles"] == 15871 assert test_config["tptimeout"] == 30000872 assert test_config["gecko_profile_interval"] == 1873 assert test_config["gecko_profile_entries"] == 2000000874 assert test_config["filters"] is not None875 assert test_config["unit"] == "ms"876 assert test_config["lower_is_better"] is True877 assert test_config["alert_threshold"] == 5.0878@mock.patch("talos.config.get_browser_config")879@mock.patch("talos.config.get_config")880def test_get_configs(get_config_mock, get_browser_config_mock):881 # unpacks in right order882 get_config_mock.return_value = "first"883 get_browser_config_mock.return_value = "second"884 first, second = get_configs()885 assert (first, second) == ("first", "second")886if __name__ == "__main__":...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

1import os2import unittest3import yaml4from builder import Builder5from config import Config6import input_validator as iv7from testdata.data import aws_namespaces as ns_list8class TestBuilder(unittest.TestCase):9 def test_getRegionCode(self):10 test_config = Config('./testdata/test-config.yml')11 valid_ns = ["au", "ca", "eu", "nl", "uk", "wa"]12 for ns in valid_ns:13 self.assertEqual(test_config.getRegionCode(ns), f"-{ns}")14 def test_get_listener_url(self):15 test_config = Config('./testdata/test-config.yml')16 self.assertEqual(test_config.getListenerUrl(), 'https://listener.logz.io:8053')17 valid_ns = ["au", "ca", "eu", "nl", "uk", "wa"]18 for ns in valid_ns:19 test_config.otel['logzio_region'] = ns20 self.assertEqual(test_config.getListenerUrl(), f'https://listener-{ns}.logz.io:8053')21 test_config.otel['custom_listener'] = 'test'22 self.assertEqual(test_config.getListenerUrl(), test_config.otel['custom_listener'])23 def test_load_config(self):24 # otel25 test_config = Config('./testdata/test-config.yml')26 self.assertEqual(test_config.otel['logzio_region'], 'us')27 self.assertEqual(test_config.otel['custom_listener'], '')28 self.assertEqual(test_config.otel['p8s_logzio_name'], 'cloudwatch-metrics')29 self.assertEqual(test_config.otel['token'], 'fakeXamgZErKKkMhmzdVZDhuZcpGKXeo')30 self.assertEqual(test_config.otel['scrape_interval'], 300)31 self.assertEqual(test_config.otel['remote_timeout'], 120)32 self.assertEqual(test_config.otel['log_level'], 'debug')33 self.assertEqual(test_config.otel['logzio_log_level'], 'info')34 self.assertEqual(test_config.otel['AWS_ACCESS_KEY_ID'], 'fakeXamgZErKKkMhmzdVZDhuZcpGKXeo')35 self.assertEqual(test_config.otel['AWS_SECRET_ACCESS_KEY'], 'fakeXamgZErKKkMhmzdVZDhuZcpGKXeo')36 # cloudwatch37 self.assertEqual(test_config.cloudwatch['custom_config'], 'false')38 self.assertEqual(test_config.cloudwatch['region'], 'us-east-1')39 self.assertEqual(test_config.cloudwatch['role_arn'], '')40 self.assertEqual(test_config.cloudwatch['aws_namespaces'], ["AWS/Lambda", "AWS/EC2"])41 self.assertEqual(test_config.cloudwatch['set_timestamp'], 'false')42 self.assertEqual(test_config.cloudwatch['delay_seconds'], 600)43 self.assertEqual(test_config.cloudwatch['range_seconds'], 600)44 self.assertEqual(test_config.cloudwatch['period_seconds'], 300)45 # Success46 try:47 Config('./testdata/test-config.yml')48 except Exception as e:49 self.fail(f'Unexpected error {e}')50 def test_load_config_env_overwrite(self):51 # otel52 os.environ['LOGZIO_REGION'] = 'eu'53 os.environ['SCRAPE_INTERVAL'] = '600'54 os.environ['P8S_LOGZIO_NAME'] = 'test'55 os.environ['TOKEN'] = 'test'56 os.environ['CUSTOM_LISTENER'] = 'test'57 os.environ['REMOTE_TIMEOUT'] = '600'58 os.environ['LOG_LEVEL'] = 'info'59 os.environ['LOGZIO_LOG_LEVEL'] = 'debug'60 os.environ['AWS_ACCESS_KEY_ID'] = 'test'61 os.environ['AWS_SECRET_ACCESS_KEY'] = 'test'62 # cloudwatch63 os.environ['DELAY_SECONDS'] = '60'64 os.environ['RANGE_SECONDS'] = '60'65 os.environ['PERIOD_SECONDS'] = '60'66 os.environ['SET_TIMESTAMP'] = 'true'67 os.environ['AWS_REGION'] = 'us-east-2'68 os.environ['AWS_NAMESPACES'] = 'AWS/RDS,AWS/ELB'69 os.environ['CUSTOM_CONFIG'] = 'true'70 os.environ['AWS_ROLE_ARN'] = 'test'71 test_config = Config('./testdata/test-config.yml')72 os.environ.clear()73 # otel74 self.assertEqual(test_config.otel['logzio_region'], 'eu')75 self.assertEqual(test_config.otel['scrape_interval'], 600)76 self.assertEqual(test_config.otel['token'], 'test')77 self.assertEqual(test_config.otel['custom_listener'], 'test')78 self.assertEqual(test_config.otel['remote_timeout'], 600)79 self.assertEqual(test_config.otel['log_level'], 'info')80 self.assertEqual(test_config.otel['logzio_log_level'], 'debug')81 self.assertEqual(test_config.otel['AWS_ACCESS_KEY_ID'], 'test')82 self.assertEqual(test_config.otel['AWS_SECRET_ACCESS_KEY'], 'test')83 # cloudwatch84 self.assertEqual(test_config.cloudwatch['custom_config'], 'true')85 self.assertEqual(test_config.cloudwatch['region'], 'us-east-2')86 self.assertEqual(test_config.cloudwatch['role_arn'], 'test')87 self.assertEqual(test_config.cloudwatch['aws_namespaces'], 'AWS/RDS,AWS/ELB')88 self.assertEqual(test_config.cloudwatch['delay_seconds'], 60)89 self.assertEqual(test_config.cloudwatch['range_seconds'], 60)90 self.assertEqual(test_config.cloudwatch['period_seconds'], 60)91 self.assertEqual(test_config.cloudwatch['set_timestamp'], 'true')92 def test_add_all_cloudwatch_namespaces(self):93 try:94 builder = Builder('./testdata/test-config.yml', cloudwatchConfigPath='./testdata/cloudwatch-test.yml')95 builder.config.cloudwatch['aws_namespaces'] = ns_list96 builder.updateCloudwatchConfiguration('./cw_namespaces/')97 with open(builder.cloudwatchConfigPath, 'r+') as cw:98 builder.dumpAndCloseFile({'metrics': []}, cw)99 except Exception as e:100 self.fail(f'Unexpected error {e}')101 def test_cloudwatch_config(self):102 try:103 builder = Builder('./testdata/test-config.yml', cloudwatchConfigPath='./testdata/cloudwatch-test.yml')104 builder.config.cloudwatch['aws_namespaces'], remove = iv.is_valid_aws_namespaces('AWS/EC2,AWS/RDS')105 builder.updateCloudwatchConfiguration('./cw_namespaces/')106 with open(builder.cloudwatchConfigPath, 'r+') as cw:107 builder.dumpAndCloseFile({'metrics': []}, cw)108 except Exception as e:109 self.fail(f'Unexpected error {e}')110 def test_update_otel_collector(self):111 try:112 builder = Builder('./testdata/test-config.yml', otelConfigPath='./testdata/otel-test.yml')113 with open(builder.otelConfigPath, 'r+') as otel:114 builder.updateOtelConfiguration()115 values = yaml.safe_load(otel)116 self.assertEqual(values['receivers']['prometheus_exec']['scrape_interval'], '300s')117 self.assertEqual(values['receivers']['prometheus_exec']['scrape_timeout'], '300s')118 self.assertEqual(values['exporters']['prometheusremotewrite']['endpoint'],119 'https://listener.logz.io:8053')120 self.assertEqual(values['exporters']['prometheusremotewrite']['timeout'], '120s')121 self.assertEqual(values['exporters']['prometheusremotewrite']['external_labels']['p8s_logzio_name'],122 'cloudwatch-metrics')123 self.assertEqual(values['exporters']['prometheusremotewrite']['headers']['Authorization'],124 'Bearer fakeXamgZErKKkMhmzdVZDhuZcpGKXeo')125 self.assertEqual(values['service']['telemetry']['logs']['level'], 'debug')126 # reset config127 with open('./testdata/default-otel.yml', 'r+') as otel_def:128 testing_otel_yaml = yaml.safe_load(otel_def)129 builder.dumpAndCloseFile(testing_otel_yaml, otel)130 except Exception as e:131 self.fail(f'Unexpected error {e}')132class TestInput(unittest.TestCase):133 def test_is_valid_logzio_token(self):134 # Fail Type135 non_valid_types = [-2, None, 4j, ['string', 'string']]136 for t in non_valid_types:137 self.assertRaises(TypeError, iv.is_valid_logzio_token, t)138 # Fail Value139 non_valid_vals = ['12', 'quwyekclshyrflclhf', 'rDRJEidvpIbecUwshyCn4kuUjbymiHev']140 for v in non_valid_vals:141 self.assertRaises(ValueError, iv.is_valid_logzio_token, v)142 # Success143 try:144 iv.is_valid_logzio_token('rDRJEidvpIbecUwshyCnGkuUjbymiHev')145 except (TypeError, ValueError) as e:146 self.fail(f'Unexpected error {e}')147 def test_is_valid_logzio_region_code(self):148 # Fail Type149 non_valid_types = [-2, None, 4j, ['string', 'string']]150 for t in non_valid_types:151 self.assertRaises(TypeError, iv.is_valid_logzio_region_code, t)152 # Fail Value153 non_valid_vals = ['12', 'usa', 'au,ca']154 for v in non_valid_vals:155 self.assertRaises(ValueError, iv.is_valid_logzio_region_code, v)156 # Success157 try:158 iv.is_valid_logzio_region_code('ca')159 except (TypeError, ValueError) as e:160 self.fail(f'Unexpected error {e}')161 try:162 iv.is_valid_logzio_region_code('us')163 except (TypeError, ValueError) as e:164 self.fail(f'Unexpected error {e}')165 def test_is_valid_scrape_interval(self):166 # Fail type167 non_valid_types = ['12', None, False, ['string', 'string'], 4j]168 for t in non_valid_types:169 self.assertRaises(TypeError, iv.is_valid_interval, t)170 # Fail Value171 non_valid_vals = [-60, 55, 10, 306]172 for v in non_valid_vals:173 self.assertRaises(ValueError, iv.is_valid_interval, v)174 # Success175 try:176 iv.is_valid_interval(360000)177 except (TypeError, ValueError) as e:178 self.fail(f'Unexpected error {e}')179 try:180 iv.is_valid_interval(60)181 except (TypeError, ValueError) as e:182 self.fail(f'Unexpected error {e}')183 def test_is_valid_aws_namespaces(self):184 # Fail Value185 self.assertRaises(ValueError, iv.is_valid_aws_namespaces, '')186 self.assertRaises(ValueError, iv.is_valid_aws_namespaces, 'AWS/ec2, aws/RDS, AWS/lambda, AWS/fdfdf')187 # Success188 self.assertTupleEqual(iv.is_valid_aws_namespaces('AWS/RDS,AWS/Lambda,AWS/CloudFront'),189 (['AWS/CloudFront', 'AWS/Lambda', 'AWS/RDS'], []))190 self.assertTupleEqual(iv.is_valid_aws_namespaces('AWS/RDS,AWS/nosuch,AWS/Lambda,AWS/CloudFront'),191 (['AWS/CloudFront', 'AWS/Lambda', 'AWS/RDS'], ['AWS/nosuch']))192 self.assertTupleEqual(iv.is_valid_aws_namespaces('AWS/RDS,AWS/Lambda,AWS/Cloudfront'),193 (['AWS/Lambda', 'AWS/RDS'], ['AWS/Cloudfront']))194 self.assertTupleEqual(iv.is_valid_aws_namespaces('AWS/RDS, AWS/RDS, AWS/Lambda,AWS/Lambda,AWS/Cloudfront'),195 (['AWS/Lambda', 'AWS/RDS'], ['AWS/Cloudfront']))196 def test_is_valid_p8s_logzio_name(self):197 # Fail Type198 non_valid_types = [-2, None, 4j, ['string', 'string']]199 for t in non_valid_types:200 self.assertRaises(TypeError, iv.is_valid_p8s_logzio_name, t)201 # Success202 try:203 iv.is_valid_p8s_logzio_name('dev5')204 except (TypeError, ValueError) as e:205 self.fail(f'Unexpected error {e}')206 def test_is_valid_custom_listener(self):207 # Fail Type208 non_valid_types = [-2, None, 4j, ['string', 'string']]209 for t in non_valid_types:210 self.assertRaises(TypeError, iv.is_valid_custom_listener, t)211 # Fail Value212 non_valid_vals = ['12', 'www.custom.listener:3000', 'custom.listener:3000', 'htt://custom.listener:3000',213 'https://custom.listener:', 'https://custom.']214 for v in non_valid_vals:215 self.assertRaises(ValueError, iv.is_valid_custom_listener, v)216 # Success217 try:218 iv.is_valid_custom_listener('http://custom.listener:3000')219 except (TypeError, ValueError) as e:220 self.fail(f'Unexpected error {e}')221 try:222 iv.is_valid_custom_listener('https://localhost:9200')223 except (TypeError, ValueError) as e:224 self.fail(f'Unexpected error {e}')225if __name__ == '__main__':...

Full Screen

Full Screen

conf.py

Source:conf.py Github

copy

Full Screen

1"""2Unit tests for the stem.util.conf class and functions.3"""4import unittest5import stem.util.conf6import stem.util.enum7from stem.util.conf import parse_enum, parse_enum_csv8class TestConf(unittest.TestCase):9 def tearDown(self):10 # clears the config contents11 test_config = stem.util.conf.get_config('unit_testing')12 test_config.clear()13 test_config.clear_listeners()14 def test_config_dict(self):15 """16 Tests the config_dict function.17 """18 my_config = {19 'bool_value': False,20 'int_value': 5,21 'str_value': 'hello',22 'list_value': [],23 }24 test_config = stem.util.conf.get_config('unit_testing')25 # checks that sync causes existing contents to be applied26 test_config.set('bool_value', 'true')27 my_config = stem.util.conf.config_dict('unit_testing', my_config)28 self.assertEqual(True, my_config['bool_value'])29 # check a basic synchronize30 test_config.set('str_value', 'me')31 self.assertEqual('me', my_config['str_value'])32 # synchronize with a type mismatch, should keep the old value33 test_config.set('int_value', '7a')34 self.assertEqual(5, my_config['int_value'])35 # changes for a collection36 test_config.set('list_value', 'a', False)37 self.assertEqual(['a'], my_config['list_value'])38 test_config.set('list_value', 'b', False)39 self.assertEqual(['a', 'b'], my_config['list_value'])40 test_config.set('list_value', 'c', False)41 self.assertEqual(['a', 'b', 'c'], my_config['list_value'])42 def test_parse_enum(self):43 """44 Tests the parse_enum function.45 """46 Insects = stem.util.enum.Enum('BUTTERFLY', 'LADYBUG', 'CRICKET')47 self.assertEqual(Insects.LADYBUG, parse_enum('my_option', 'ladybug', Insects))48 self.assertRaises(ValueError, parse_enum, 'my_option', 'ugabuga', Insects)49 self.assertRaises(ValueError, parse_enum, 'my_option', 'ladybug, cricket', Insects)50 def test_parse_enum_csv(self):51 """52 Tests the parse_enum_csv function.53 """54 Insects = stem.util.enum.Enum('BUTTERFLY', 'LADYBUG', 'CRICKET')55 # check the case insensitivity56 self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'ladybug', Insects))57 self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'Ladybug', Insects))58 self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'LaDyBuG', Insects))59 self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'LADYBUG', Insects))60 # various number of values61 self.assertEqual([], parse_enum_csv('my_option', '', Insects))62 self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'ladybug', Insects))63 self.assertEqual(64 [Insects.LADYBUG, Insects.BUTTERFLY],65 parse_enum_csv('my_option', 'ladybug, butterfly', Insects)66 )67 self.assertEqual(68 [Insects.LADYBUG, Insects.BUTTERFLY, Insects.CRICKET],69 parse_enum_csv('my_option', 'ladybug, butterfly, cricket', Insects)70 )71 # edge cases for count argument where things are ok72 self.assertEqual(73 [Insects.LADYBUG, Insects.BUTTERFLY],74 parse_enum_csv('my_option', 'ladybug, butterfly', Insects, 2)75 )76 self.assertEqual(77 [Insects.LADYBUG, Insects.BUTTERFLY],78 parse_enum_csv('my_option', 'ladybug, butterfly', Insects, (1, 2))79 )80 self.assertEqual(81 [Insects.LADYBUG, Insects.BUTTERFLY],82 parse_enum_csv('my_option', 'ladybug, butterfly', Insects, (2, 3))83 )84 self.assertEqual(85 [Insects.LADYBUG, Insects.BUTTERFLY],86 parse_enum_csv('my_option', 'ladybug, butterfly', Insects, (2, 2))87 )88 # failure cases89 self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ugabuga', Insects)90 self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug, ugabuga', Insects)91 self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug butterfly', Insects) # no comma92 self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug', Insects, 2)93 self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug', Insects, (2, 3))94 def test_clear(self):95 """96 Tests the clear method.97 """98 test_config = stem.util.conf.get_config('unit_testing')99 self.assertEqual([], list(test_config.keys()))100 # tests clearing when we're already empty101 test_config.clear()102 self.assertEqual([], list(test_config.keys()))103 # tests clearing when we have contents104 test_config.set('hello', 'world')105 self.assertEqual(['hello'], list(test_config.keys()))106 test_config.clear()107 self.assertEqual([], list(test_config.keys()))108 def test_listeners(self):109 """110 Tests the add_listener and clear_listeners methods.111 """112 listener_received_keys = []113 def test_listener(config, key):114 self.assertEqual(config, stem.util.conf.get_config('unit_testing'))115 listener_received_keys.append(key)116 test_config = stem.util.conf.get_config('unit_testing')117 test_config.add_listener(test_listener)118 self.assertEqual([], listener_received_keys)119 test_config.set('hello', 'world')120 self.assertEqual(['hello'], listener_received_keys)121 test_config.clear_listeners()122 test_config.set('foo', 'bar')123 self.assertEqual(['hello'], listener_received_keys)124 def test_unused_keys(self):125 """126 Tests the unused_keys method.127 """128 test_config = stem.util.conf.get_config('unit_testing')129 test_config.set('hello', 'world')130 test_config.set('foo', 'bar')131 test_config.set('pw', '12345')132 test_config.get('hello')133 test_config.get_value('foo')134 self.assertEqual(set(['pw']), test_config.unused_keys())135 test_config.get('pw')136 self.assertEqual(set(), test_config.unused_keys())137 def test_get(self):138 """139 Tests the get and get_value methods.140 """141 test_config = stem.util.conf.get_config('unit_testing')142 test_config.set('bool_value', 'true')143 test_config.set('int_value', '11')144 test_config.set('float_value', '11.1')145 test_config.set('str_value', 'world')146 test_config.set('list_value', 'a', False)147 test_config.set('list_value', 'b', False)148 test_config.set('list_value', 'c', False)149 test_config.set('map_value', 'foo => bar')150 # check that we get the default for type mismatch or missing values151 self.assertEqual(5, test_config.get('foo', 5))152 self.assertEqual(5, test_config.get('bool_value', 5))153 # checks that we get a string when no default is supplied154 self.assertEqual('11', test_config.get('int_value'))155 # exercise type casting for each of the supported types156 self.assertEqual(True, test_config.get('bool_value', False))157 self.assertEqual(11, test_config.get('int_value', 0))158 self.assertEqual(11.1, test_config.get('float_value', 0.0))159 self.assertEqual('world', test_config.get('str_value', ''))160 self.assertEqual(['a', 'b', 'c'], test_config.get('list_value', []))161 self.assertEqual(('a', 'b', 'c'), test_config.get('list_value', ()))162 self.assertEqual({'foo': 'bar'}, test_config.get('map_value', {}))163 # the get_value is similar, though only provides back a string or list164 self.assertEqual('c', test_config.get_value('list_value'))165 self.assertEqual(['a', 'b', 'c'], test_config.get_value('list_value', multiple = True))166 self.assertEqual(None, test_config.get_value('foo'))...

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:

YouTube

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

Run autotest 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?

Helpful

NotHelpful