How to use reload method in Playwright Internal

Best JavaScript code snippet using playwright-internal

test_settings.py

Source:test_settings.py Github

copy

Full Screen

1import unittest2class TestSettingsConfiguratorMixin(unittest.TestCase):3 def _makeOne(self, *arg, **kw):4 from pyramid.config import Configurator5 config = Configurator(*arg, **kw)6 return config7 def test__set_settings_as_None(self):8 config = self._makeOne()9 settings = config._set_settings(None)10 self.assertTrue(settings)11 def test__set_settings_as_dictwithvalues(self):12 config = self._makeOne()13 settings = config._set_settings({'a':'1'})14 self.assertEqual(settings['a'], '1')15 def test_get_settings_nosettings(self):16 from pyramid.registry import Registry17 reg = Registry()18 config = self._makeOne(reg)19 self.assertEqual(config.get_settings(), None)20 def test_get_settings_withsettings(self):21 settings = {'a':1}22 config = self._makeOne()23 config.registry.settings = settings24 self.assertEqual(config.get_settings(), settings)25 def test_add_settings_settings_already_registered(self):26 from pyramid.registry import Registry27 reg = Registry()28 config = self._makeOne(reg)29 config._set_settings({'a':1})30 config.add_settings({'b':2})31 settings = reg.settings32 self.assertEqual(settings['a'], 1)33 self.assertEqual(settings['b'], 2)34 def test_add_settings_settings_not_yet_registered(self):35 from pyramid.registry import Registry36 from pyramid.interfaces import ISettings37 reg = Registry()38 config = self._makeOne(reg)39 config.add_settings({'a':1})40 settings = reg.getUtility(ISettings)41 self.assertEqual(settings['a'], 1)42 def test_add_settings_settings_None(self):43 from pyramid.registry import Registry44 from pyramid.interfaces import ISettings45 reg = Registry()46 config = self._makeOne(reg)47 config.add_settings(None, a=1)48 settings = reg.getUtility(ISettings)49 self.assertEqual(settings['a'], 1)50class TestSettings(unittest.TestCase):51 52 def _getTargetClass(self):53 from pyramid.config.settings import Settings54 return Settings55 def _makeOne(self, d=None, environ=None):56 if environ is None:57 environ = {}58 klass = self._getTargetClass()59 return klass(d, _environ_=environ)60 def test_getattr_success(self):61 import warnings62 with warnings.catch_warnings(record=True) as w:63 warnings.filterwarnings('always')64 settings = self._makeOne({'reload_templates':False})65 self.assertEqual(settings.reload_templates, False)66 self.assertEqual(len(w), 1)67 def test_getattr_fail(self):68 import warnings69 with warnings.catch_warnings(record=True) as w:70 warnings.filterwarnings('always')71 settings = self._makeOne({})72 self.assertRaises(AttributeError, settings.__getattr__, 'wontexist')73 self.assertEqual(len(w), 0)74 def test_getattr_raises_attribute_error(self):75 settings = self._makeOne()76 self.assertRaises(AttributeError, settings.__getattr__, 'mykey')77 def test_noargs(self):78 settings = self._makeOne()79 self.assertEqual(settings['debug_authorization'], False)80 self.assertEqual(settings['debug_notfound'], False)81 self.assertEqual(settings['debug_routematch'], False)82 self.assertEqual(settings['reload_templates'], False)83 self.assertEqual(settings['reload_resources'], False)84 self.assertEqual(settings['pyramid.debug_authorization'], False)85 self.assertEqual(settings['pyramid.debug_notfound'], False)86 self.assertEqual(settings['pyramid.debug_routematch'], False)87 self.assertEqual(settings['pyramid.reload_templates'], False)88 self.assertEqual(settings['pyramid.reload_resources'], False)89 def test_prevent_http_cache(self):90 settings = self._makeOne({})91 self.assertEqual(settings['prevent_http_cache'], False)92 self.assertEqual(settings['pyramid.prevent_http_cache'], False)93 result = self._makeOne({'prevent_http_cache':'false'})94 self.assertEqual(result['prevent_http_cache'], False)95 self.assertEqual(result['pyramid.prevent_http_cache'], False)96 result = self._makeOne({'prevent_http_cache':'t'})97 self.assertEqual(result['prevent_http_cache'], True)98 self.assertEqual(result['pyramid.prevent_http_cache'], True)99 result = self._makeOne({'prevent_http_cache':'1'})100 self.assertEqual(result['prevent_http_cache'], True)101 self.assertEqual(result['pyramid.prevent_http_cache'], True)102 result = self._makeOne({'pyramid.prevent_http_cache':'t'})103 self.assertEqual(result['prevent_http_cache'], True)104 self.assertEqual(result['pyramid.prevent_http_cache'], True)105 result = self._makeOne({}, {'PYRAMID_PREVENT_HTTP_CACHE':'1'})106 self.assertEqual(result['prevent_http_cache'], True)107 self.assertEqual(result['pyramid.prevent_http_cache'], True)108 result = self._makeOne({'prevent_http_cache':'false',109 'pyramid.prevent_http_cache':'1'})110 self.assertEqual(result['prevent_http_cache'], True)111 self.assertEqual(result['pyramid.prevent_http_cache'], True)112 result = self._makeOne({'prevent_http_cache':'false',113 'pyramid.prevent_http_cache':'f'},114 {'PYRAMID_PREVENT_HTTP_CACHE':'1'})115 self.assertEqual(result['prevent_http_cache'], True)116 self.assertEqual(result['pyramid.prevent_http_cache'], True)117 def test_reload_templates(self):118 settings = self._makeOne({})119 self.assertEqual(settings['reload_templates'], False)120 self.assertEqual(settings['pyramid.reload_templates'], False)121 result = self._makeOne({'reload_templates':'false'})122 self.assertEqual(result['reload_templates'], False)123 self.assertEqual(result['pyramid.reload_templates'], False)124 result = self._makeOne({'reload_templates':'t'})125 self.assertEqual(result['reload_templates'], True)126 self.assertEqual(result['pyramid.reload_templates'], True)127 result = self._makeOne({'reload_templates':'1'})128 self.assertEqual(result['reload_templates'], True)129 self.assertEqual(result['pyramid.reload_templates'], True)130 result = self._makeOne({'pyramid.reload_templates':'1'})131 self.assertEqual(result['reload_templates'], True)132 self.assertEqual(result['pyramid.reload_templates'], True)133 result = self._makeOne({}, {'PYRAMID_RELOAD_TEMPLATES':'1'})134 self.assertEqual(result['reload_templates'], True)135 self.assertEqual(result['pyramid.reload_templates'], True)136 result = self._makeOne({'reload_templates':'false',137 'pyramid.reload_templates':'1'})138 self.assertEqual(result['reload_templates'], True)139 self.assertEqual(result['pyramid.reload_templates'], True)140 result = self._makeOne({'reload_templates':'false'},141 {'PYRAMID_RELOAD_TEMPLATES':'1'})142 self.assertEqual(result['reload_templates'], True)143 self.assertEqual(result['pyramid.reload_templates'], True)144 def test_reload_resources(self):145 # alias for reload_assets146 result = self._makeOne({})147 self.assertEqual(result['reload_resources'], False)148 self.assertEqual(result['reload_assets'], False)149 self.assertEqual(result['pyramid.reload_resources'], False)150 self.assertEqual(result['pyramid.reload_assets'], False)151 result = self._makeOne({'reload_resources':'false'})152 self.assertEqual(result['reload_resources'], False)153 self.assertEqual(result['reload_assets'], False)154 self.assertEqual(result['pyramid.reload_resources'], False)155 self.assertEqual(result['pyramid.reload_assets'], False)156 result = self._makeOne({'reload_resources':'t'})157 self.assertEqual(result['reload_resources'], True)158 self.assertEqual(result['reload_assets'], True)159 self.assertEqual(result['pyramid.reload_resources'], True)160 self.assertEqual(result['pyramid.reload_assets'], True)161 result = self._makeOne({'reload_resources':'1'})162 self.assertEqual(result['reload_resources'], True)163 self.assertEqual(result['reload_assets'], True)164 self.assertEqual(result['pyramid.reload_resources'], True)165 self.assertEqual(result['pyramid.reload_assets'], True)166 result = self._makeOne({'pyramid.reload_resources':'1'})167 self.assertEqual(result['reload_resources'], True)168 self.assertEqual(result['reload_assets'], True)169 self.assertEqual(result['pyramid.reload_resources'], True)170 self.assertEqual(result['pyramid.reload_assets'], True)171 result = self._makeOne({}, {'PYRAMID_RELOAD_RESOURCES':'1'})172 self.assertEqual(result['reload_resources'], True)173 self.assertEqual(result['reload_assets'], True)174 self.assertEqual(result['pyramid.reload_resources'], True)175 self.assertEqual(result['pyramid.reload_assets'], True)176 result = self._makeOne({'reload_resources':'false',177 'pyramid.reload_resources':'1'})178 self.assertEqual(result['reload_resources'], True)179 self.assertEqual(result['reload_assets'], True)180 self.assertEqual(result['pyramid.reload_resources'], True)181 self.assertEqual(result['pyramid.reload_assets'], True)182 result = self._makeOne({'reload_resources':'false',183 'pyramid.reload_resources':'false'},184 {'PYRAMID_RELOAD_RESOURCES':'1'})185 self.assertEqual(result['reload_resources'], True)186 self.assertEqual(result['reload_assets'], True)187 self.assertEqual(result['pyramid.reload_resources'], True)188 self.assertEqual(result['pyramid.reload_assets'], True)189 def test_reload_assets(self):190 # alias for reload_resources191 result = self._makeOne({})192 self.assertEqual(result['reload_assets'], False)193 self.assertEqual(result['reload_resources'], False)194 self.assertEqual(result['pyramid.reload_assets'], False)195 self.assertEqual(result['pyramid.reload_resources'], False)196 result = self._makeOne({'reload_assets':'false'})197 self.assertEqual(result['reload_resources'], False)198 self.assertEqual(result['reload_assets'], False)199 self.assertEqual(result['pyramid.reload_assets'], False)200 self.assertEqual(result['pyramid.reload_resources'], False)201 result = self._makeOne({'reload_assets':'t'})202 self.assertEqual(result['reload_assets'], True)203 self.assertEqual(result['reload_resources'], True)204 self.assertEqual(result['pyramid.reload_assets'], True)205 self.assertEqual(result['pyramid.reload_resources'], True)206 result = self._makeOne({'reload_assets':'1'})207 self.assertEqual(result['reload_assets'], True)208 self.assertEqual(result['reload_resources'], True)209 self.assertEqual(result['pyramid.reload_assets'], True)210 self.assertEqual(result['pyramid.reload_resources'], True)211 result = self._makeOne({'pyramid.reload_assets':'1'})212 self.assertEqual(result['reload_assets'], True)213 self.assertEqual(result['reload_resources'], True)214 self.assertEqual(result['pyramid.reload_assets'], True)215 self.assertEqual(result['pyramid.reload_resources'], True)216 result = self._makeOne({}, {'PYRAMID_RELOAD_ASSETS':'1'})217 self.assertEqual(result['reload_assets'], True)218 self.assertEqual(result['reload_resources'], True)219 self.assertEqual(result['pyramid.reload_assets'], True)220 self.assertEqual(result['pyramid.reload_resources'], True)221 result = self._makeOne({'reload_assets':'false',222 'pyramid.reload_assets':'1'})223 self.assertEqual(result['reload_assets'], True)224 self.assertEqual(result['reload_resources'], True)225 self.assertEqual(result['pyramid.reload_assets'], True)226 self.assertEqual(result['pyramid.reload_resources'], True)227 result = self._makeOne({'reload_assets':'false',228 'pyramid.reload_assets':'false'},229 {'PYRAMID_RELOAD_ASSETS':'1'})230 self.assertEqual(result['reload_assets'], True)231 self.assertEqual(result['reload_resources'], True)232 self.assertEqual(result['pyramid.reload_assets'], True)233 self.assertEqual(result['pyramid.reload_resources'], True)234 def test_reload_all(self):235 result = self._makeOne({})236 self.assertEqual(result['reload_templates'], False)237 self.assertEqual(result['reload_resources'], False)238 self.assertEqual(result['reload_assets'], False)239 self.assertEqual(result['pyramid.reload_templates'], False)240 self.assertEqual(result['pyramid.reload_resources'], False)241 self.assertEqual(result['pyramid.reload_assets'], False)242 result = self._makeOne({'reload_all':'false'})243 self.assertEqual(result['reload_templates'], False)244 self.assertEqual(result['reload_resources'], False)245 self.assertEqual(result['reload_assets'], False)246 self.assertEqual(result['pyramid.reload_templates'], False)247 self.assertEqual(result['pyramid.reload_resources'], False)248 self.assertEqual(result['pyramid.reload_assets'], False)249 result = self._makeOne({'reload_all':'t'})250 self.assertEqual(result['reload_templates'], True)251 self.assertEqual(result['reload_resources'], True)252 self.assertEqual(result['reload_assets'], True)253 self.assertEqual(result['pyramid.reload_templates'], True)254 self.assertEqual(result['pyramid.reload_resources'], True)255 self.assertEqual(result['pyramid.reload_assets'], True)256 result = self._makeOne({'reload_all':'1'})257 self.assertEqual(result['reload_templates'], True)258 self.assertEqual(result['reload_resources'], True)259 self.assertEqual(result['reload_assets'], True)260 self.assertEqual(result['pyramid.reload_templates'], True)261 self.assertEqual(result['pyramid.reload_resources'], True)262 self.assertEqual(result['pyramid.reload_assets'], True)263 result = self._makeOne({'pyramid.reload_all':'1'})264 self.assertEqual(result['reload_templates'], True)265 self.assertEqual(result['reload_resources'], True)266 self.assertEqual(result['reload_assets'], True)267 self.assertEqual(result['pyramid.reload_templates'], True)268 self.assertEqual(result['pyramid.reload_resources'], True)269 self.assertEqual(result['pyramid.reload_assets'], True)270 result = self._makeOne({}, {'PYRAMID_RELOAD_ALL':'1'})271 self.assertEqual(result['reload_templates'], True)272 self.assertEqual(result['reload_resources'], True)273 self.assertEqual(result['reload_assets'], True)274 self.assertEqual(result['pyramid.reload_templates'], True)275 self.assertEqual(result['pyramid.reload_resources'], True)276 self.assertEqual(result['pyramid.reload_assets'], True)277 result = self._makeOne({'reload_all':'false',278 'pyramid.reload_all':'1'})279 self.assertEqual(result['reload_templates'], True)280 self.assertEqual(result['reload_resources'], True)281 self.assertEqual(result['reload_assets'], True)282 self.assertEqual(result['pyramid.reload_templates'], True)283 self.assertEqual(result['pyramid.reload_resources'], True)284 self.assertEqual(result['pyramid.reload_assets'], True)285 result = self._makeOne({'reload_all':'false',286 'pyramid.reload_all':'false'},287 {'PYRAMID_RELOAD_ALL':'1'})288 self.assertEqual(result['reload_templates'], True)289 self.assertEqual(result['reload_resources'], True)290 self.assertEqual(result['reload_assets'], True)291 self.assertEqual(result['pyramid.reload_templates'], True)292 self.assertEqual(result['pyramid.reload_resources'], True)293 self.assertEqual(result['pyramid.reload_assets'], True)294 def test_debug_authorization(self):295 result = self._makeOne({})296 self.assertEqual(result['debug_authorization'], False)297 self.assertEqual(result['pyramid.debug_authorization'], False)298 result = self._makeOne({'debug_authorization':'false'})299 self.assertEqual(result['debug_authorization'], False)300 self.assertEqual(result['pyramid.debug_authorization'], False)301 result = self._makeOne({'debug_authorization':'t'})302 self.assertEqual(result['debug_authorization'], True)303 self.assertEqual(result['pyramid.debug_authorization'], True)304 result = self._makeOne({'debug_authorization':'1'})305 self.assertEqual(result['debug_authorization'], True)306 self.assertEqual(result['pyramid.debug_authorization'], True)307 result = self._makeOne({'pyramid.debug_authorization':'1'})308 self.assertEqual(result['debug_authorization'], True)309 self.assertEqual(result['pyramid.debug_authorization'], True)310 result = self._makeOne({}, {'PYRAMID_DEBUG_AUTHORIZATION':'1'})311 self.assertEqual(result['debug_authorization'], True)312 self.assertEqual(result['pyramid.debug_authorization'], True)313 result = self._makeOne({'debug_authorization':'false',314 'pyramid.debug_authorization':'1'})315 self.assertEqual(result['debug_authorization'], True)316 self.assertEqual(result['pyramid.debug_authorization'], True)317 result = self._makeOne({'debug_authorization':'false',318 'pyramid.debug_authorization':'false'},319 {'PYRAMID_DEBUG_AUTHORIZATION':'1'})320 self.assertEqual(result['debug_authorization'], True)321 self.assertEqual(result['pyramid.debug_authorization'], True)322 def test_debug_notfound(self):323 result = self._makeOne({})324 self.assertEqual(result['debug_notfound'], False)325 self.assertEqual(result['pyramid.debug_notfound'], False)326 result = self._makeOne({'debug_notfound':'false'})327 self.assertEqual(result['debug_notfound'], False)328 self.assertEqual(result['pyramid.debug_notfound'], False)329 result = self._makeOne({'debug_notfound':'t'})330 self.assertEqual(result['debug_notfound'], True)331 self.assertEqual(result['pyramid.debug_notfound'], True)332 result = self._makeOne({'debug_notfound':'1'})333 self.assertEqual(result['debug_notfound'], True)334 self.assertEqual(result['pyramid.debug_notfound'], True)335 result = self._makeOne({'pyramid.debug_notfound':'1'})336 self.assertEqual(result['debug_notfound'], True)337 self.assertEqual(result['pyramid.debug_notfound'], True)338 result = self._makeOne({}, {'PYRAMID_DEBUG_NOTFOUND':'1'})339 self.assertEqual(result['debug_notfound'], True)340 self.assertEqual(result['pyramid.debug_notfound'], True)341 result = self._makeOne({'debug_notfound':'false',342 'pyramid.debug_notfound':'1'})343 self.assertEqual(result['debug_notfound'], True)344 self.assertEqual(result['pyramid.debug_notfound'], True)345 result = self._makeOne({'debug_notfound':'false',346 'pyramid.debug_notfound':'false'},347 {'PYRAMID_DEBUG_NOTFOUND':'1'})348 self.assertEqual(result['debug_notfound'], True)349 self.assertEqual(result['pyramid.debug_notfound'], True)350 def test_debug_routematch(self):351 result = self._makeOne({})352 self.assertEqual(result['debug_routematch'], False)353 self.assertEqual(result['pyramid.debug_routematch'], False)354 result = self._makeOne({'debug_routematch':'false'})355 self.assertEqual(result['debug_routematch'], False)356 self.assertEqual(result['pyramid.debug_routematch'], False)357 result = self._makeOne({'debug_routematch':'t'})358 self.assertEqual(result['debug_routematch'], True)359 self.assertEqual(result['pyramid.debug_routematch'], True)360 result = self._makeOne({'debug_routematch':'1'})361 self.assertEqual(result['debug_routematch'], True)362 self.assertEqual(result['pyramid.debug_routematch'], True)363 result = self._makeOne({'pyramid.debug_routematch':'1'})364 self.assertEqual(result['debug_routematch'], True)365 self.assertEqual(result['pyramid.debug_routematch'], True)366 result = self._makeOne({}, {'PYRAMID_DEBUG_ROUTEMATCH':'1'})367 self.assertEqual(result['debug_routematch'], True)368 self.assertEqual(result['pyramid.debug_routematch'], True)369 result = self._makeOne({'debug_routematch':'false',370 'pyramid.debug_routematch':'1'})371 self.assertEqual(result['debug_routematch'], True)372 self.assertEqual(result['pyramid.debug_routematch'], True)373 result = self._makeOne({'debug_routematch':'false',374 'pyramid.debug_routematch':'false'},375 {'PYRAMID_DEBUG_ROUTEMATCH':'1'})376 self.assertEqual(result['debug_routematch'], True)377 self.assertEqual(result['pyramid.debug_routematch'], True)378 def test_debug_templates(self):379 result = self._makeOne({})380 self.assertEqual(result['debug_templates'], False)381 self.assertEqual(result['pyramid.debug_templates'], False)382 result = self._makeOne({'debug_templates':'false'})383 self.assertEqual(result['debug_templates'], False)384 self.assertEqual(result['pyramid.debug_templates'], False)385 result = self._makeOne({'debug_templates':'t'})386 self.assertEqual(result['debug_templates'], True)387 self.assertEqual(result['pyramid.debug_templates'], True)388 result = self._makeOne({'debug_templates':'1'})389 self.assertEqual(result['debug_templates'], True)390 self.assertEqual(result['pyramid.debug_templates'], True)391 result = self._makeOne({'pyramid.debug_templates':'1'})392 self.assertEqual(result['debug_templates'], True)393 self.assertEqual(result['pyramid.debug_templates'], True)394 result = self._makeOne({}, {'PYRAMID_DEBUG_TEMPLATES':'1'})395 self.assertEqual(result['debug_templates'], True)396 self.assertEqual(result['pyramid.debug_templates'], True)397 result = self._makeOne({'debug_templates':'false',398 'pyramid.debug_templates':'1'})399 self.assertEqual(result['debug_templates'], True)400 self.assertEqual(result['pyramid.debug_templates'], True)401 result = self._makeOne({'debug_templates':'false',402 'pyramid.debug_templates':'false'},403 {'PYRAMID_DEBUG_TEMPLATES':'1'})404 self.assertEqual(result['debug_templates'], True)405 self.assertEqual(result['pyramid.debug_templates'], True)406 def test_debug_all(self):407 result = self._makeOne({})408 self.assertEqual(result['debug_notfound'], False)409 self.assertEqual(result['debug_routematch'], False)410 self.assertEqual(result['debug_authorization'], False)411 self.assertEqual(result['debug_templates'], False)412 self.assertEqual(result['pyramid.debug_notfound'], False)413 self.assertEqual(result['pyramid.debug_routematch'], False)414 self.assertEqual(result['pyramid.debug_authorization'], False)415 self.assertEqual(result['pyramid.debug_templates'], False)416 result = self._makeOne({'debug_all':'false'})417 self.assertEqual(result['debug_notfound'], False)418 self.assertEqual(result['debug_routematch'], False)419 self.assertEqual(result['debug_authorization'], False)420 self.assertEqual(result['debug_templates'], False)421 self.assertEqual(result['pyramid.debug_notfound'], False)422 self.assertEqual(result['pyramid.debug_routematch'], False)423 self.assertEqual(result['pyramid.debug_authorization'], False)424 self.assertEqual(result['pyramid.debug_templates'], False)425 result = self._makeOne({'debug_all':'t'})426 self.assertEqual(result['debug_notfound'], True)427 self.assertEqual(result['debug_routematch'], True)428 self.assertEqual(result['debug_authorization'], True)429 self.assertEqual(result['debug_templates'], True)430 self.assertEqual(result['pyramid.debug_notfound'], True)431 self.assertEqual(result['pyramid.debug_routematch'], True)432 self.assertEqual(result['pyramid.debug_authorization'], True)433 self.assertEqual(result['pyramid.debug_templates'], True)434 result = self._makeOne({'debug_all':'1'})435 self.assertEqual(result['debug_notfound'], True)436 self.assertEqual(result['debug_routematch'], True)437 self.assertEqual(result['debug_authorization'], True)438 self.assertEqual(result['debug_templates'], True)439 self.assertEqual(result['pyramid.debug_notfound'], True)440 self.assertEqual(result['pyramid.debug_routematch'], True)441 self.assertEqual(result['pyramid.debug_authorization'], True)442 self.assertEqual(result['pyramid.debug_templates'], True)443 result = self._makeOne({'pyramid.debug_all':'1'})444 self.assertEqual(result['debug_notfound'], True)445 self.assertEqual(result['debug_routematch'], True)446 self.assertEqual(result['debug_authorization'], True)447 self.assertEqual(result['debug_templates'], True)448 self.assertEqual(result['pyramid.debug_notfound'], True)449 self.assertEqual(result['pyramid.debug_routematch'], True)450 self.assertEqual(result['pyramid.debug_authorization'], True)451 self.assertEqual(result['pyramid.debug_templates'], True)452 result = self._makeOne({}, {'PYRAMID_DEBUG_ALL':'1'})453 self.assertEqual(result['debug_notfound'], True)454 self.assertEqual(result['debug_routematch'], True)455 self.assertEqual(result['debug_authorization'], True)456 self.assertEqual(result['debug_templates'], True)457 self.assertEqual(result['pyramid.debug_notfound'], True)458 self.assertEqual(result['pyramid.debug_routematch'], True)459 self.assertEqual(result['pyramid.debug_authorization'], True)460 self.assertEqual(result['pyramid.debug_templates'], True)461 result = self._makeOne({'debug_all':'false',462 'pyramid.debug_all':'1'})463 self.assertEqual(result['debug_notfound'], True)464 self.assertEqual(result['debug_routematch'], True)465 self.assertEqual(result['debug_authorization'], True)466 self.assertEqual(result['debug_templates'], True)467 self.assertEqual(result['pyramid.debug_notfound'], True)468 self.assertEqual(result['pyramid.debug_routematch'], True)469 self.assertEqual(result['pyramid.debug_authorization'], True)470 self.assertEqual(result['pyramid.debug_templates'], True)471 result = self._makeOne({'debug_all':'false',472 'pyramid.debug_all':'false'},473 {'PYRAMID_DEBUG_ALL':'1'})474 self.assertEqual(result['debug_notfound'], True)475 self.assertEqual(result['debug_routematch'], True)476 self.assertEqual(result['debug_authorization'], True)477 self.assertEqual(result['debug_templates'], True)478 self.assertEqual(result['pyramid.debug_notfound'], True)479 self.assertEqual(result['pyramid.debug_routematch'], True)480 self.assertEqual(result['pyramid.debug_authorization'], True)481 self.assertEqual(result['pyramid.debug_templates'], True)482 def test_default_locale_name(self):483 result = self._makeOne({})484 self.assertEqual(result['default_locale_name'], 'en')485 self.assertEqual(result['pyramid.default_locale_name'], 'en')486 result = self._makeOne({'default_locale_name':'abc'})487 self.assertEqual(result['default_locale_name'], 'abc')488 self.assertEqual(result['pyramid.default_locale_name'], 'abc')489 result = self._makeOne({'pyramid.default_locale_name':'abc'})490 self.assertEqual(result['default_locale_name'], 'abc')491 self.assertEqual(result['pyramid.default_locale_name'], 'abc')492 result = self._makeOne({}, {'PYRAMID_DEFAULT_LOCALE_NAME':'abc'})493 self.assertEqual(result['default_locale_name'], 'abc')494 self.assertEqual(result['pyramid.default_locale_name'], 'abc')495 result = self._makeOne({'default_locale_name':'def',496 'pyramid.default_locale_name':'abc'})497 self.assertEqual(result['default_locale_name'], 'abc')498 self.assertEqual(result['pyramid.default_locale_name'], 'abc')499 result = self._makeOne({'default_locale_name':'def',500 'pyramid.default_locale_name':'ghi'},501 {'PYRAMID_DEFAULT_LOCALE_NAME':'abc'})502 self.assertEqual(result['default_locale_name'], 'abc')503 self.assertEqual(result['pyramid.default_locale_name'], 'abc')504 def test_originals_kept(self):505 result = self._makeOne({'a':'i am so a'})...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1# Copyright (c) 2019-present, Facebook, Inc.2# All rights reserved.3#4# This source code is licensed under the license found in the5# LICENSE file in the root directory of this source tree.6#7from logging import getLogger8import os9import torch10from .pretrain import load_embeddings11# , TRANSFORMER_LAYER_PARAMS12from .transformer import DECODER_ONLY_PARAMS, TransformerModel13logger = getLogger()14def check_model_params(params):15 """16 Check models parameters.17 """18 # masked language modeling task parameters19 assert params.bptt >= 120 assert 0 <= params.word_pred < 121 assert 0 <= params.sample_alpha < 122 s = params.word_mask_keep_rand.split(',')23 assert len(s) == 324 s = [float(x) for x in s]25 assert all([0 <= x <= 1 for x in s]) and sum(s) == 126 params.word_mask = s[0]27 params.word_keep = s[1]28 params.word_rand = s[2]29 # input sentence noise for DAE30 if len(params.ae_steps) == 0:31 assert params.word_shuffle == 032 assert params.word_dropout == 033 assert params.word_blank == 034 else:35 assert params.word_shuffle == 0 or params.word_shuffle > 136 assert 0 <= params.word_dropout < 137 assert 0 <= params.word_blank < 138 # model dimensions39 if params.emb_dim_encoder == 0 and params.emb_dim_decoder == 0:40 assert params.emb_dim > 041 params.emb_dim_encoder = params.emb_dim42 params.emb_dim_decoder = params.emb_dim43 else:44 assert params.emb_dim == 045 assert params.emb_dim_encoder > 0 and params.emb_dim_decoder > 046 if params.emb_dim_encoder == params.emb_dim_decoder:47 params.emb_dim = params.emb_dim_decoder48 else:49 assert params.reload_emb == "", 'Pre-trained embeddings are not supported when the embedding size of the ' \50 'encoder and the decoder do not match '51 assert params.emb_dim_encoder % params.n_heads == 052 assert params.emb_dim_decoder % params.n_heads == 053 if params.n_layers_encoder == 0 and params.n_layers_decoder == 0:54 assert params.n_layers > 055 params.n_layers_encoder = params.n_layers56 params.n_layers_decoder = params.n_layers57 else:58 assert params.n_layers == 059 assert params.n_layers_encoder > 0 and params.n_layers_decoder > 060 # reload pretrained word embeddings61 if params.reload_emb != '':62 assert os.path.isfile(params.reload_emb)63 # reload a pretrained model64 if params.reload_model != '':65 if params.encoder_only:66 assert os.path.isfile(params.reload_model)67 else:68 s = params.reload_model.split(',')69 assert len(s) == 270 assert all([x == '' or os.path.isfile(x) for x in s])71 assert not (params.beam_size > 1 and params.number_samples >72 1), 'Cannot sample when already doing beam search'73 assert (params.eval_temperature is None) == (params.number_samples <=74 1), 'Eval temperature should be set if and only if taking several samples at eval time'75def set_pretrain_emb(model, dico, word2id, embeddings):76 """77 Pretrain word embeddings.78 """79 n_found = 080 with torch.no_grad():81 for i in range(len(dico)):82 idx = word2id.get(dico[i], None)83 if idx is None:84 continue85 n_found += 186 model.embeddings.weight[i] = embeddings[idx].cuda()87 model.pred_layer.proj.weight[i] = embeddings[idx].cuda()88 logger.info("Pretrained %i/%i words (%.3f%%)."89 % (n_found, len(dico), 100. * n_found / len(dico)))90def build_model(params, dico):91 """92 Build model.93 """94 if params.encoder_only:95 # build96 model = TransformerModel(97 params, dico, is_encoder=True, with_output=True)98 # reload pretrained word embeddings99 if params.reload_emb != '':100 word2id, embeddings = load_embeddings(params.reload_emb, params)101 set_pretrain_emb(model, dico, word2id, embeddings)102 # reload a pretrained model103 if params.reload_model != '':104 logger.info("Reloading model from %s ..." % params.reload_model)105 reloaded = torch.load(params.reload_model, map_location=lambda storage, loc: storage.cuda(106 params.local_rank))['model']107 if all([k.startswith('module.') for k in reloaded.keys()]):108 reloaded = {k[len('module.'):]: v for k, v in reloaded.items()}109 # # HACK to reload models with less layers110 # for i in range(12, 24):111 # for k in TRANSFORMER_LAYER_PARAMS:112 # k = k % i113 # if k in model.state_dict() and k not in reloaded:114 # logger.warning("Parameter %s not found. Ignoring ..." % k)115 # reloaded[k] = model.state_dict()[k]116 model.load_state_dict(reloaded)117 logger.info("Model: {}".format(model))118 logger.info("Number of parameters (model): %i" % sum(119 [p.numel() for p in model.parameters() if p.requires_grad]))120 return [model.cuda()]121 else:122 # build123 # TODO: only output when necessary - len(params.clm_steps + params.mlm_steps) > 0124 encoder = TransformerModel(125 params, dico, is_encoder=True, with_output=True)126 if params.separate_decoders:127 decoders = [TransformerModel(128 params, dico, is_encoder=False, with_output=True) for _ in params.lang2id.values()]129 else:130 decoders = [TransformerModel(131 params, dico, is_encoder=False, with_output=True)]132 for layer in range(params.n_layers_decoder):133 if layer <= params.n_share_dec - 1:134 assert params.amp == -1, "sharing layers is not supported with AMP"135 logger.info(136 "Sharing decoder attention parameters for layer %i" % layer)137 for i in range(1, len(decoders)):138 decoders[i].attentions[layer] = decoders[0].attentions[layer]139 # reload pretrained word embeddings140 if params.reload_emb != '':141 word2id, embeddings = load_embeddings(params.reload_emb, params)142 set_pretrain_emb(encoder, dico, word2id, embeddings)143 set_pretrain_emb(decoders, dico, word2id, embeddings)144 # reload a pretrained model145 if params.reload_model != '':146 enc_path, dec_path = params.reload_model.split(',')147 assert not (enc_path == '' and dec_path == '')148 # reload encoder149 if enc_path != '':150 logger.info("Reloading encoder from %s ..." % enc_path)151 enc_reload = torch.load(152 enc_path, map_location=lambda storage, loc: storage.cuda(params.local_rank))153 enc_reload = enc_reload['model' if 'model' in enc_reload else 'encoder']154 if all([k.startswith('module.') for k in enc_reload.keys()]):155 enc_reload = {k[len('module.'):]: v for k,156 v in enc_reload.items()}157 # # HACK to reload models trained with less languages158 n_langs = len(params.langs)159 n_langs_reload = enc_reload['lang_embeddings.weight'].size()[0]160 assert n_langs == n_langs_reload or n_langs == 2 * \161 n_langs_reload or n_langs == 2 * n_langs_reload + 1162 if n_langs == 2 * n_langs_reload:163 enc_reload['lang_embeddings.weight'] = enc_reload['lang_embeddings.weight'].transpose(164 0, 1).repeat_interleave(2, 1).transpose(0, 1)165 elif n_langs == 2 * n_langs_reload + 1:166 enc_reload['lang_embeddings.weight'] = enc_reload['lang_embeddings.weight'].transpose(167 0, 1).repeat_interleave(2, 1).transpose(0, 1)168 enc_reload['lang_embeddings.weight'] = torch.cat(169 [enc_reload['lang_embeddings.weight'][0, :].unsqueeze(dim=0), enc_reload['lang_embeddings.weight']])170 if encoder.position_embeddings.weight.size()[0] == 2 * enc_reload['position_embeddings.weight'].size()[0]:171 enc_reload['position_embeddings.weight'] = enc_reload['position_embeddings.weight'].repeat(172 2, 1)173 encoder.load_state_dict(enc_reload)174 # reload decoders175 if dec_path != '':176 for dec in decoders:177 logger.info("Reloading decoders from %s ..." % dec_path)178 dec_reload = torch.load(179 dec_path, map_location=lambda storage, loc: storage.cuda(params.local_rank))180 dec_reload = dec_reload['model' if 'model' in dec_reload else 'decoder']181 if all([k.startswith('module.') for k in dec_reload.keys()]):182 dec_reload = {183 k[len('module.'):]: v for k, v in dec_reload.items()}184 # # HACK to reload models trained with less languages185 n_langs = len(params.langs)186 n_langs_reload = dec_reload['lang_embeddings.weight'].size()[187 0]188 assert n_langs == n_langs_reload or n_langs == 2 * \189 n_langs_reload or n_langs == 2 * n_langs_reload + 1190 if n_langs == 2 * n_langs_reload:191 dec_reload['lang_embeddings.weight'] = dec_reload['lang_embeddings.weight'].transpose(192 0, 1).repeat_interleave(2, 1).transpose(0, 1)193 elif n_langs == 2 * n_langs_reload + 1:194 dec_reload['lang_embeddings.weight'] = dec_reload['lang_embeddings.weight'].transpose(195 0, 1).repeat_interleave(2, 1).transpose(0, 1)196 dec_reload['lang_embeddings.weight'] = torch.cat(197 [dec_reload['lang_embeddings.weight'][0, :].unsqueeze(dim=0), dec_reload['lang_embeddings.weight']])198 if dec.position_embeddings.weight.size()[0] == 2 * dec_reload['position_embeddings.weight'].size()[0]:199 dec_reload['position_embeddings.weight'] = dec_reload['position_embeddings.weight'].repeat(200 2, 1)201 for i in range(params.n_layers_decoder):202 for name in DECODER_ONLY_PARAMS:203 if name % i not in dec_reload:204 logger.warning(205 "Parameter %s not found." % (name % i))206 dec_reload[name % i] = dec.state_dict()[207 name % i]208 dec.load_state_dict(dec_reload)209 logger.debug("Encoder: {}".format(encoder))210 logger.debug("Decoder: {}".format(decoders))211 logger.info("Number of parameters (encoder): %i" % sum(212 [p.numel() for p in encoder.parameters() if p.requires_grad]))213 logger.info("Number of parameters (decoders): %i" % sum(214 [p.numel() for p in decoders[0].parameters() if p.requires_grad]))215 logger.info(f"Number of decoders: {len(decoders)}")...

Full Screen

Full Screen

test_unit_reload.py

Source:test_unit_reload.py Github

copy

Full Screen

1#!/usr/bin/env python2import os3import unittest2 as unittest4from gppylib.mainUtils import ExceptionNoStackTraceNeeded5from gppylib.operations.reload import GpReload6from mock import MagicMock, Mock, mock_open, patch7class GpReloadTestCase(unittest.TestCase):8 def setUp(self):9 class Options:10 def __init__(self):11 if 'PGPORT' not in os.environ:12 self.port = None13 else:14 self.port = os.environ['PGPORT']15 self.table_file = '/tmp/table_file'16 self.database = 'testdb'17 self.interactive = False18 args = None19 self.reload = GpReload(Options(), args)20 def tearDown(self):21 if self.reload.table_file and os.path.exists(self.reload.table_file):22 os.remove(self.reload.table_file)23 def test_validate_options_table_file_not_specified(self):24 self.reload.table_file = None25 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, 'Please specify table file'):26 self.reload.validate_options()27 @patch('os.path.exists', return_value=False)28 def test_validate_options_table_file_does_not_exist(self, mock1):29 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, 'Unable to find table file "/tmp/table_file"'):30 self.reload.validate_options()31 @patch('os.path.exists', return_value=True)32 def test_validate_options_database_not_specified(self, mock1):33 self.reload.database = None34 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, 'Please specify the correct database'):35 self.reload.validate_options()36 @patch('os.path.exists', return_value=True)37 @patch('os.environ')38 def test_validate_options_no_port(self, mock1, mock2):39 self.reload.port = None40 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, 'Please specify PGPORT using -p option or set PGPORT in the environment'):41 self.reload.validate_options()42 @patch('os.path.exists', return_value=True)43 def test_validate_options_valid(self, mock1):44 self.reload.validate_options()45 def test_parse_line_empty_table(self):46 line = 'public.:sort_column'47 with self.assertRaises(Exception):48 self.reload.parse_line(line)49 def test_parse_line_empty_schema(self):50 line = '.t1:sort_column'51 with self.assertRaises(Exception):52 self.reload.parse_line(line)53 def test_parse_line_empty_columns(self):54 line = 'public.t1:'55 with self.assertRaises(Exception):56 self.reload.parse_line(line)57 def test_parse_columns_empty_line(self):58 columns = ''59 with self.assertRaisesRegexp(Exception, 'Empty column'):60 self.reload.parse_columns(columns)61 def test_parse_columns_single_column(self):62 columns = 'single_col'63 self.assertEqual([('single_col', 'asc')], self.reload.parse_columns(columns))64 def test_parse_columns_empty_columns(self):65 columns = ' , c2 foo'66 with self.assertRaisesRegexp(Exception, 'Empty column'):67 self.reload.parse_columns(columns)68 def test_parse_column_single_sort_order(self):69 columns = 'single_col asc'70 self.assertEqual([('single_col', 'asc')], self.reload.parse_columns(columns))71 def test_parse_column_invalid_sort_order1(self):72 columns = 'c1, c2 foo'73 with self.assertRaisesRegexp(Exception, 'Invalid sort order foo'):74 self.reload.parse_columns(columns)75 def test_parse_column_invalid_sort_order2(self):76 columns = 'c1, c2 foo bar'77 with self.assertRaisesRegexp(Exception, 'Invalid sort order specified'):78 self.reload.parse_columns(columns)79 def test_validate_table_file_empty_table_name(self):80 self.reload.table_file = '/tmp/table_file'81 with open(self.reload.table_file, 'w') as fp:82 fp.write('public.t1: a, b\n')83 fp.write('public.: a, b\n')84 try:85 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, "Line 'public.: a, b' is not formatted correctly"):86 self.reload.validate_table_file()87 finally:88 if os.path.exists(self.reload.table_file):89 os.remove(self.reload.table_file)90 def test_validate_table_file_empty_schema_name(self):91 self.reload.table_file = '/tmp/table_file'92 with open(self.reload.table_file, 'w') as fp:93 fp.write('public.t1: a, b\n')94 fp.write('.t1: a, b\n')95 try:96 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, "Line '.t1: a, b' is not formatted correctly"):97 self.reload.validate_table_file()98 finally:99 if os.path.exists(self.reload.table_file):100 os.remove(self.reload.table_file)101 def test_validate_table_file_empty_column_list(self):102 self.reload.table_file = '/tmp/table_file'103 with open(self.reload.table_file, 'w') as fp:104 fp.write('public.t1:\n')105 try:106 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, "Line 'public.t1:' is not formatted correctly"):107 self.reload.validate_table_file()108 finally:109 if os.path.exists(self.reload.table_file):110 os.remove(self.reload.table_file)111 def test_validate_table_file_invalid_sort_order(self):112 self.reload.table_file = '/tmp/table_file'113 with open(self.reload.table_file, 'w') as fp:114 fp.write('public.t1: a, b\n')115 fp.write('public.t2: a, b foo\n')116 try:117 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, "Line 'public.t2: a, b foo' is not formatted correctly"):118 self.reload.validate_table_file()119 finally:120 if os.path.exists(self.reload.table_file):121 os.remove(self.reload.table_file)122 def test_validate_table_file_valid_data1(self):123 self.reload.table_file = '/tmp/table_file'124 with open(self.reload.table_file, 'w') as fp:125 fp.write('public.t1: a, b\n')126 fp.write('public.t2: a, b\n')127 try:128 expected_output = [('public', 't1', [('a', 'asc'), ('b', 'asc')]), ('public', 't2', [('a', 'asc'), ('b', 'asc')])]129 self.assertEqual(expected_output, self.reload.validate_table_file())130 finally:131 if os.path.exists(self.reload.table_file):132 os.remove(self.reload.table_file)133 def test_validate_table_file_valid_data2(self):134 self.reload.table_file = '/tmp/table_file'135 with open(self.reload.table_file, 'w') as fp:136 fp.write('public.t1: a, b desc\n')137 fp.write('public.t2: a desc, b\n')138 try:139 expected_output = [('public', 't1', [('a', 'asc'), ('b', 'desc')]), ('public', 't2', [('a', 'desc'), ('b', 'asc')])]140 self.assertEqual(expected_output, self.reload.validate_table_file())141 finally:142 if os.path.exists(self.reload.table_file):143 os.remove(self.reload.table_file)144 @patch('gppylib.operations.reload.dbconn.connect')145 @patch('gppylib.operations.reload.execSQLForSingleton', return_value=0)146 def test_validate_table_invalid_table(self, mock1, mock2):147 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, "Table public.t1 does not exist"):148 self.reload.validate_table('public', 't1')149 @patch('gppylib.operations.reload.dbconn.connect')150 @patch('gppylib.operations.reload.execSQLForSingleton', return_value=1)151 def test_validate_table_valid_table(self, mock1, mock2):152 self.reload.validate_table('public', 't1')153 @patch('gppylib.operations.reload.dbconn.connect')154 def test_validate_columns_invalid_column(self, mock1):155 m = Mock()156 m.fetchall.return_value=[['a', 'x'], ['b', 'y']]157 with patch('gppylib.operations.reload.execSQL', return_value=m) as p:158 with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, 'Table public.t1 does not have column c'):159 self.reload.validate_columns('public', 't1', [('a', 'x'), ('b', 'y'), ('c', 'z')])160 @patch('gppylib.operations.reload.dbconn.connect')161 def test_validate_columns_valid_column1(self, mock1):162 m = Mock()163 m.fetchall.return_value=[['a', 'x'], ['b', 'y'], ['c', 'z']]164 with patch('gppylib.operations.reload.execSQL', return_value=m) as p:165 self.reload.validate_columns('public', 't1', [('a', 'x'), ('b', 'y'), ('c', 'z')])166 @patch('gppylib.operations.reload.dbconn.connect')167 def test_validate_columns_valid_column2(self, mock1):168 m = Mock()169 m.fetchall.return_value=[['a', 'w'], ['b', 'x'], ['c', 'y'], ['d', 'z']]170 with patch('gppylib.operations.reload.execSQL', return_value=m) as p:171 self.reload.validate_columns('public', 't1', [('a', 'w'), ('b', 'x'), ('c', 'y'), ('d', 'z')])172 @patch('gppylib.operations.reload.execSQLForSingleton', return_value=0)173 @patch('gppylib.operations.reload.dbconn.connect')174 def test_check_indexes_no_indexes(self, mock1, mock2):175 self.assertTrue(self.reload.check_indexes('public', 't1'))176 @patch('gppylib.operations.reload.ask_yesno', return_value=True)177 @patch('gppylib.operations.reload.dbconn.connect')178 @patch('gppylib.operations.reload.execSQLForSingleton', return_value=1)179 def test_check_indexes_with_indexes_with_continue(self, mock1, mock2, mock3):180 self.reload.interactive=True181 self.assertTrue(self.reload.check_indexes('public', 't1'))182 @patch('gppylib.operations.reload.ask_yesno', return_value=False)183 @patch('gppylib.operations.reload.dbconn.connect')184 @patch('gppylib.operations.reload.execSQLForSingleton', return_value=1)185 def test_check_indexes_with_indexes_without_continue(self, mock1, mock2, mock3):186 self.reload.interactive=True187 self.assertFalse(self.reload.check_indexes('public', 't1'))188 @patch('gppylib.operations.reload.dbconn.connect')189 @patch('gppylib.operations.reload.execSQL', side_effect=[[('public', 'x1')], [('public', 'x2')]])190 def test_get_parent_partition_map(self, mock1, mock2):191 expected = {('public', 't1'): ('public', 'x1'), ('public', 't2'): ('public', 'x2')}192 self.reload.table_list = [('public', 't1', 'a b c d'), ('public', 't2', 'd e f g')]193 self.assertEqual(expected, self.reload.get_parent_partitions())194 @patch('gppylib.operations.reload.dbconn.connect') 195 @patch('gppylib.operations.reload.execSQL', side_effect=[[('public', 'x1')], []])196 def test_get_parent_partition_map_non_partition(self, mock1, mock2):197 expected = {('public', 't1'): ('public', 'x1'), ('public', 't2'): ('public', 't2')}198 self.reload.table_list = [('public', 't1', 'a b c d'), ('public', 't2', 'd e f g')]...

Full Screen

Full Screen

migrate.py

Source:migrate.py Github

copy

Full Screen

...128 log.debug('def_ms=%s' % unicode(def_ms))129 html += "</body></html>"130 return HttpResponse(html)131@csrf_exempt132def gitreload(request, reload_dir=None):133 '''134 This can be used as a github WebHook Service Hook, for reloading of the content repo used by the LMS.135 If reload_dir is not None, then instruct the xml loader to reload that course directory.136 '''137 html = "<html><body>"138 ip = getip(request)139 html += '<h3>IP address: %s ' % ip140 html += '<h3>User: %s ' % request.user141 ALLOWED_IPS = [] # allow none by default142 if hasattr(settings, 'ALLOWED_GITRELOAD_IPS'): # allow override in settings143 ALLOWED_IPS = settings.ALLOWED_GITRELOAD_IPS144 if not (ip in ALLOWED_IPS or 'any' in ALLOWED_IPS):145 if request.user and request.user.is_staff:146 log.debug(u'request allowed because user=%s is staff', request.user)...

Full Screen

Full Screen

settings.py

Source:settings.py Github

copy

Full Screen

1import os2import warnings3from zope.interface import implementer4from pyramid.interfaces import ISettings5from pyramid.settings import asbool6class SettingsConfiguratorMixin(object):7 def _set_settings(self, mapping):8 if not mapping:9 mapping = {}10 settings = Settings(mapping)11 self.registry.settings = settings12 return settings13 def add_settings(self, settings=None, **kw):14 """Augment the :term:`deployment settings` with one or more15 key/value pairs. 16 You may pass a dictionary::17 config.add_settings({'external_uri':'http://example.com'})18 Or a set of key/value pairs::19 config.add_settings(external_uri='http://example.com')20 This function is useful when you need to test code that accesses the21 :attr:`pyramid.registry.Registry.settings` API (or the22 :meth:`pyramid.config.Configurator.get_settings` API) and23 which uses values from that API.24 """25 if settings is None:26 settings = {}27 utility = self.registry.settings28 if utility is None:29 utility = self._set_settings(settings)30 utility.update(settings)31 utility.update(kw)32 def get_settings(self):33 """34 Return a :term:`deployment settings` object for the current35 application. A deployment settings object is a dictionary-like36 object that contains key/value pairs based on the dictionary passed37 as the ``settings`` argument to the38 :class:`pyramid.config.Configurator` constructor.39 .. note:: the :attr:`pyramid.registry.Registry.settings` API40 performs the same duty.41 """42 return self.registry.settings43@implementer(ISettings)44class Settings(dict):45 """ Deployment settings. Update application settings (usually46 from PasteDeploy keywords) with framework-specific key/value pairs47 (e.g. find ``PYRAMID_DEBUG_AUTHORIZATION`` in os.environ and jam into48 keyword args)."""49 # _environ_ is dep inj for testing50 def __init__(self, d=None, _environ_=os.environ, **kw):51 if d is None:52 d = {}53 dict.__init__(self, d, **kw)54 eget = _environ_.get55 config_debug_all = self.get('debug_all', '')56 config_debug_all = self.get('pyramid.debug_all', config_debug_all)57 eff_debug_all = asbool(eget('PYRAMID_DEBUG_ALL', config_debug_all))58 config_reload_all = self.get('reload_all', '')59 config_reload_all = self.get('pyramid.reload_all', config_reload_all)60 eff_reload_all = asbool(eget('PYRAMID_RELOAD_ALL', config_reload_all))61 config_debug_auth = self.get('debug_authorization', '')62 config_debug_auth = self.get('pyramid.debug_authorization',63 config_debug_auth)64 eff_debug_auth = asbool(eget('PYRAMID_DEBUG_AUTHORIZATION',65 config_debug_auth))66 config_debug_notfound = self.get('debug_notfound', '')67 config_debug_notfound = self.get('pyramid.debug_notfound',68 config_debug_notfound)69 eff_debug_notfound = asbool(eget('PYRAMID_DEBUG_NOTFOUND',70 config_debug_notfound))71 config_debug_routematch = self.get('debug_routematch', '')72 config_debug_routematch = self.get('pyramid.debug_routematch',73 config_debug_routematch)74 eff_debug_routematch = asbool(eget('PYRAMID_DEBUG_ROUTEMATCH',75 config_debug_routematch))76 config_debug_templates = self.get('debug_templates', '')77 config_debug_templates = self.get('pyramid.debug_templates',78 config_debug_templates)79 eff_debug_templates = asbool(eget('PYRAMID_DEBUG_TEMPLATES',80 config_debug_templates))81 config_reload_templates = self.get('reload_templates', '')82 config_reload_templates = self.get('pyramid.reload_templates',83 config_reload_templates)84 eff_reload_templates = asbool(eget('PYRAMID_RELOAD_TEMPLATES',85 config_reload_templates))86 config_reload_assets = self.get('reload_assets', '')87 config_reload_assets = self.get('pyramid.reload_assets',88 config_reload_assets)89 reload_assets = asbool(eget('PYRAMID_RELOAD_ASSETS',90 config_reload_assets))91 config_reload_resources = self.get('reload_resources', '')92 config_reload_resources = self.get('pyramid.reload_resources',93 config_reload_resources)94 reload_resources = asbool(eget('PYRAMID_RELOAD_RESOURCES',95 config_reload_resources))96 # reload_resources is an older alias for reload_assets97 eff_reload_assets = reload_assets or reload_resources98 locale_name = self.get('default_locale_name', 'en')99 locale_name = self.get('pyramid.default_locale_name', locale_name)100 eff_locale_name = eget('PYRAMID_DEFAULT_LOCALE_NAME', locale_name)101 config_prevent_http_cache = self.get('prevent_http_cache', '')102 config_prevent_http_cache = self.get('pyramid.prevent_http_cache',103 config_prevent_http_cache)104 eff_prevent_http_cache = asbool(eget('PYRAMID_PREVENT_HTTP_CACHE',105 config_prevent_http_cache))106 update = {107 'debug_authorization': eff_debug_all or eff_debug_auth,108 'debug_notfound': eff_debug_all or eff_debug_notfound,109 'debug_routematch': eff_debug_all or eff_debug_routematch,110 'debug_templates': eff_debug_all or eff_debug_templates,111 'reload_templates': eff_reload_all or eff_reload_templates,112 'reload_resources':eff_reload_all or eff_reload_assets,113 'reload_assets':eff_reload_all or eff_reload_assets,114 'default_locale_name':eff_locale_name,115 'prevent_http_cache':eff_prevent_http_cache,116 'pyramid.debug_authorization': eff_debug_all or eff_debug_auth,117 'pyramid.debug_notfound': eff_debug_all or eff_debug_notfound,118 'pyramid.debug_routematch': eff_debug_all or eff_debug_routematch,119 'pyramid.debug_templates': eff_debug_all or eff_debug_templates,120 'pyramid.reload_templates': eff_reload_all or eff_reload_templates,121 'pyramid.reload_resources':eff_reload_all or eff_reload_assets,122 'pyramid.reload_assets':eff_reload_all or eff_reload_assets,123 'pyramid.default_locale_name':eff_locale_name,124 'pyramid.prevent_http_cache':eff_prevent_http_cache,125 }126 self.update(update)127 def __getattr__(self, name):128 try:129 val = self[name]130 # only deprecate on success; a probing getattr/hasattr should not131 # print this warning132 warnings.warn(133 'Obtaining settings via attributes of the settings dictionary '134 'is deprecated as of Pyramid 1.2; use settings["foo"] instead '135 'of settings.foo',136 DeprecationWarning,137 2138 )139 return val140 except KeyError:...

Full Screen

Full Screen

all.py

Source:all.py Github

copy

Full Screen

1# vim: syn=python2import angarock3reload(angarock)4import azynya5reload(azynya)6import bard_guild7reload(bard_guild)8import brownie_fields9reload(brownie_fields)10import cantador11reload(cantador)12import castle_greenlight13reload(castle_greenlight)14import circus15reload(circus)16import cleric_guild17reload(cleric_guild)18import concordia19reload(concordia)20import damorra_swamps21reload(damorra_swamps)22import darkwater23reload(darkwater)24import deep_forest_ranger_outpost25reload(deep_forest_ranger_outpost)26import dragons27reload(dragons)28import dryads29reload(dryads)30import dusk31reload(dusk)32import harbour33reload(harbour)34import hemlock35reload(hemlock)36import hillside37reload(hillside)38import keep39reload(keep)40import maester41reload(maester)42import mage_guild43reload(mage_guild)44import malbeth45reload(malbeth)46import manor47reload(manor)48import medo49reload(medo)50import mellarnia51reload(mellarnia)52import minas_tirith53reload(minas_tirith)54import neckbreaker_desert55reload(neckbreaker_desert)56import newbie_fields57reload(newbie_fields)58import obizuth59reload(obizuth)60import ranger_forest61reload(ranger_forest)62import ravenloft63reload(ravenloft)64import revelstone65reload(revelstone)66import saurus67reload(saurus)68import temple_of_burning_night69reload(temple_of_burning_night)70import terray71reload(terray)72import towanda73reload(towanda)74import turre75reload(turre)76import tyrir77reload(tyrir)78import uhruul79reload(uhruul)80import valley_of_mystery81reload(valley_of_mystery)82import varalors83reload(varalors)84import yellow_tower85reload(yellow_tower)86import zombie_city87reload(zombie_city)88CITY_SKIPS = (89 zombie_city.FILE[0]['skip'] +90 cleric_guild.FILE[1]['skip'] +91 bard_guild.FILE[1]['skip'] +92 mage_guild.FILE[1]['skip'] + 1)93FILE = (94 [95 {96 'announce': '9w',97 },98 {99 'path': '9 e',100 'name': '__announce__',101 #'announce': 'ZombieCity',...

Full Screen

Full Screen

mReloadMixins.py

Source:mReloadMixins.py Github

copy

Full Screen

...42Mixin.setPlugin('mainframe', 'on_update_ui', on_mainframe_updateui)434445def OnToolReloadName(win, event):46 reload(ReloadMixins)47 from ReloadMixins import MixinDialog4849 dlg = MixinDialog(win)50 answer = dlg.ShowModal()51 dlg.Destroy()525354Mixin.setMixin('mainframe', 'OnToolReloadName', OnToolReloadName)555657def OnToolreload_mixins(win, event):58 if win.pref.mixin_reload_mixins_mode:59 mode = "normal mode"60 else:61 mode = "auto reload Mixin plugins mode"62 dlg = wx.MessageDialog(win, 'Are you want to switch to %s?\n this operation will'63 ' take effect after restarting this program!\n'64 'so doing this will close this program!\n'65 'the patch was made by ygao,you can contact me at ygao2004@gmail.com' % mode,66 "reload Mixins", wx.OK | wx.CANCEL | wx.ICON_QUESTION)67 try: res = dlg.ShowModal()68 finally: dlg.Destroy()69 if res == wx.ID_YES:70 pass71 elif res == wx.ID_CANCEL:72 return73 win.pref.mixin_reload_mixins_mode = not win.pref.mixin_reload_mixins_mode74 win.pref.save()75 reload(ReloadMixins)76 if win.pref.mixin_reload_mixins_mode:77 from ReloadMixins import MixinDialog78 dlg = MixinDialog(win)79 answer = dlg.ShowModal()80 dlg.Destroy()81 #ReloadMixins.create_import_py(win,flag=True)82 else:83 ReloadMixins.create_import_py(win)84# Globals.mainframe.Close()85Mixin.setMixin('mainframe', 'OnToolreload_mixins', OnToolreload_mixins)868788def pref_init(pref):89 pref.mixin_reload_mixins_mode = False ...

Full Screen

Full Screen

_pydev_sys_patch.py

Source:_pydev_sys_patch.py Github

copy

Full Screen

...12 system_exc_info = sys.exc_info13 sys.exc_info = patched_exc_info(system_exc_info)14 if not hasattr(sys, "system_exc_info"):15 sys.system_exc_info = system_exc_info16def patched_reload(orig_reload):17 def pydev_debugger_reload(module):18 orig_reload(module)19 if module.__name__ == "sys":20 # if sys module was reloaded we should patch it again21 patch_sys_module()22 return pydev_debugger_reload23def patch_reload():24 if sys.version_info[0] >= 3:25 import builtins # Py326 else:27 import __builtin__ as builtins28 if hasattr(builtins, "reload"):29 sys.builtin_orig_reload = builtins.reload30 builtins.reload = patched_reload(sys.builtin_orig_reload) # @UndefinedVariable31 try:32 import imp33 sys.imp_orig_reload = imp.reload34 imp.reload = patched_reload(sys.imp_orig_reload) # @UndefinedVariable35 except:36 pass37 else:38 try:39 import importlib40 sys.importlib_orig_reload = importlib.reload # @UndefinedVariable41 importlib.reload = patched_reload(sys.importlib_orig_reload) # @UndefinedVariable42 except:43 pass44 del builtins45def cancel_patches_in_sys_module():46 sys.exc_info = sys.system_exc_info # @UndefinedVariable47 if sys.version_info[0] >= 3:48 import builtins # Py349 else:50 import __builtin__ as builtins51 if hasattr(sys, "builtin_orig_reload"):52 builtins.reload = sys.builtin_orig_reload53 if hasattr(sys, "imp_orig_reload"):54 import imp55 imp.reload = sys.imp_orig_reload...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.reload();7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.reload();15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.reload();23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.reload();31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.reload();39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();46 await page.reload();47 await browser.close();48})();49const { chromium } = require('playwright');50(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.reload();7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.reload();7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.reload({ waitUntil: 'networkidle' });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.reload({ timeout: 5000 });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.reload({ timeout: 5000, waitUntil: 'networkidle' });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.reload({ timeout: 5000, waitUntil: 'domcontentloaded' });39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.reload();7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.reload();7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch({ headless: false });12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.reload({ waitUntil: 'networkidle' });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch({ headless: false });20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.reload({ timeout: 1000 });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch({ headless: false });28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.reload({ waitUntil: 'networkidle', timeout: 1000 });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch({ headless: false });36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.reload({ timeout: 1000, waitUntil: 'networkidle' });39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch({ headless: false });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright-internal');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.reload();7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {webkit, devices} = require('playwright');2(async () => {3 const browser = await webkit.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.reload();7 await browser.close();8})();9const { chromium, devices } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.reload();15 await browser.close();16})();17const { firefox, devices } = require('playwright');18(async () => {19 const browser = await firefox.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.reload();23 await browser.close();24})();25const { webkit, devices } = require('playwright');26(async () => {27 const browser = await webkit.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.reload();31 await browser.close();32})();33const { chromium, devices } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.reload();39 await browser.close();40})();41const { firefox, devices } = require('playwright');42(async () => {43 const browser = await firefox.launch();44 const context = await browser.newContext();45 const page = await context.newPage();46 await page.reload();47 await browser.close();48})();49const {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { expect } = require('chai');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.reload();8 await page.screenshot({ path: `screenshot.png` });9 await browser.close();10})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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