How to use load_environment method in lisa

Best Python code snippet using lisa_python

test_loaders.py

Source:test_loaders.py Github

copy

Full Screen

...80 def test_empty_files(self):81 """YAML loader can deal with empty files.82 """83 self.loader("""""").load_bundles()84 self.loader("""""").load_environment()85 def test_load_environment(self):86 environment = self.loader("""87 url: /foo88 directory: something89 versions: 'timestamp'90 auto_build: true91 url_expire: true92 config:93 compass_bin: /opt/compass94 bundles:95 test:96 output: foo97 """).load_environment()98 assert environment.url == '/foo'99 assert environment.url_expire == True100 assert environment.auto_build == True101 assert environment.config['versions'] == 'timestamp'102 assert environment.config['COMPASS_BIN'] == '/opt/compass'103 # Because the loader isn't aware of the file location, the104 # directory is read as-is, relative to cwd rather than the105 # file location.106 assert environment.config['directory'] == 'something'107 # [bug] Make sure the bundles are loaded as well.108 assert len(environment) == 1109 def test_load_environment_no_url_or_directory(self):110 """Check that "url" and "directory" are not required.111 """112 self.loader("""foo: bar""").load_environment()113 def test_load_environment_directory_base(self):114 environment = self.loader("""115 url: /foo116 directory: ../something117 """, filename='/var/www/project/config/yaml').load_environment()118 # The directory is considered relative to the YAML file location.119 assert environment.directory == '/var/www/project/something'120 def test_load_extra_default(self):121 """[Regression] If no extra= is given, the value defaults to {}"""122 bundles = self.loader("""123 foo:124 output: foo125 """).load_bundles()126 assert bundles['foo'].extra == {}127class TestPython(object):128 """Test the PythonLoader.129 """130 def test_path(self):131 """[bug] Regression test: Python loader does not leave132 sys.path messed up.133 """134 old_path = sys.path[:]135 loader = PythonLoader('sys')136 assert sys.path == old_path137 def test_load_bundles(self):138 import types139 module = types.ModuleType('test')140 module.foo = Bundle('bar')141 loader = PythonLoader(module)142 bundles = loader.load_bundles()143 assert len(bundles) == 1144 assert list(bundles.values())[0].contents[0] == 'bar'145 def test_load_environment_with_prefix(self):146 import types147 module = types.ModuleType("testing")148 module2 = types.ModuleType("testing2")149 module.environment = Environment() # default name150 module2.assets = Environment()151 sys.modules["testing"] = module152 sys.modules["testing2"] = module2153 loader = PythonLoader("testing")154 env = loader.load_environment()155 assert env == module.environment156 loader2 = PythonLoader("testing:environment")157 assert loader2.environment == "environment"158 env2 = loader2.load_environment()159 assert env2 == module.environment160 loader3 = PythonLoader("testing2:assets")161 assert loader3.environment == "assets"162 env3 = loader3.load_environment()163 assert env3 == module2.assets164class TestYAMLCustomFilters(TestYAML):165 def setup(self):166 super(TestYAMLCustomFilters, self).setup()167 # If zope.dottedname is not installed, that's OK168 pytest.importorskip("zope.dottedname.resolve")169 # Save off the original get_import_resolver170 self.original_resolver = YAMLLoader._get_import_resolver171 # Make a mock172 def mock(cls):173 raise ImportError174 self.mock_resolver = mock175 def mock_importer(self):176 """ Mock the import resolver to a fake one that raises import error.177 Be sure to call reset_importer if you use this at the beginning of178 any test."""179 YAMLLoader._get_import_resolver = self.mock_resolver180 def reset_importer(self):181 """ Reset the import resolver to the default one """182 YAMLLoader._get_import_resolver = self.original_resolver183 def test_cant_import_zope_is_fine(self):184 """ Check that a YAML file without filters is fine if the import of185 zope.dottedname fails """186 self.mock_importer()187 self.loader("""foo: bar""").load_environment()188 self.reset_importer()189 def test_need_zope_to_have_filter(self):190 """ Check that we get an error if the zope.dottedname module is not191 installed and they try to use custom filters """192 self.mock_importer()193 loader = self.loader("""194 filters:195 - webassets.filter.less.Less196 """)197 pytest.raises(EnvironmentError, loader.load_environment)198 self.reset_importer()199 def test_load_filter_module_throws_exc(self):200 """ Check that passing dotted module path throws an exception """201 # Try to load based on module name, instead of the class202 loader = self.loader("""203 filters:204 - webassets.filter.less205 """)206 pytest.raises(LoaderError, loader.load_environment)207 def test_bad_filter_throws_exc(self):208 """ Test that importing filters that don't exist throws an exception """209 loader = self.loader("""210 filters:211 - webassets.fake.filter212 """)213 pytest.raises(LoaderError, loader.load_environment)214 def test_load_filters(self):215 """Check that filters can be loaded from YAML """216 # Delete the less filter217 import webassets.filter218 del webassets.filter._FILTERS['less']219 # Verify that it was deleted220 pytest.raises(ValueError, get_filter, 'less')221 # Load it again from YAML222 self.loader("""223 filters:224 - webassets.filter.less.Less225 """).load_environment()226 # Check that it's back...

Full Screen

Full Screen

config.py

Source:config.py Github

copy

Full Screen

...4"""5Loads the environment secrets into memory and manages database connections6"""7SENTINEL = object()8def load_environment(key, default=SENTINEL):9 """10 Loads an environment variable, and if not found, then defaults to the specified11 value (or raises an error if none was specified.)12 """13 value = os.getenv(key)14 if value is None:15 if default is not SENTINEL:16 print(f"{key} is not configured. Falling back to default value.")17 value = default18 else:19 raise EnvironmentError(20 f"A value for {key} cannot be found. See environemt configuration")21 return value22def initialize_engine():23 """24 Initializes the Postgres database engine to spawn sessions off of25 as needed later.26 """27 print("Initializing engine...")28 return create_engine(29 f"postgresql://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/Team20")30def get_session():31 """32 Creates and returns a new database session33 """34 print("Creating a new db session")35 Session = sessionmaker(bind=engine)36 return Session()37JWT_SECRET = load_environment('JWT_SECRET', default='secret')38DB_USER = load_environment('DB_USER')39DB_PASS = load_environment('DB_PASSWORD')40DB_HOST = load_environment('DB_HOST')41DB_PORT = load_environment('DB_PORT')42LOGIN_URL = load_environment('LOGIN_URL', default='/login')43SALT_FORMAT = load_environment('SALT_FORMAT', default='#~{}')44engine = initialize_engine()45states = ["AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI",46 "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO",47 "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA",...

Full Screen

Full Screen

environment.py

Source:environment.py Github

copy

Full Screen

2"""WSGI environment setup for budget."""3from budget.config.app_cfg import base_config4__all__ = ['load_environment']5#Use base_config to setup the environment loader function6load_environment = base_config.make_load_environment()7from tg import response8_load_environment = load_environment9def load_environment(*args):10 _load_environment(*args)11 _render_genshi = base_config.render_functions.genshi12 def render_genshi(*args, **kwargs):13 if response.content_type == 'text/xml':14 kwargs['method'] = 'xml'15 return _render_genshi(*args, **kwargs)...

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 lisa 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