Best Python code snippet using localstack_python
_fillers.py
Source:_fillers.py
2from DnD_battler.creature._load_beastiary import CreatureLoader3from ._initialise import CreatureInitialise4class CreatureFill(CreatureLoader, CreatureInitialise):5 def _fill_from_dict(self, dictionary: dict):6 return self._initialise(**dictionary)7 def _fill_from_beastiary(self, name: str):8 if name in self.beastiary:9 return self._initialise(**self.beastiary[name])10 else:11 # For now fallback to preset. In future preset will be removed?12 return self._fill_from_preset(name)13 def _fill_from_preset(self, name:str):14 """15 Legacy... It might stop working due to code changes.16 :param name: the name of creature.17 :return: the stored creature.18 """19 if name == "netsharpshooter":20 self._initialise(name="netsharpshooter",21 alignment="good",22 hp=18, ac=18, hd=8,23 initiative_bonus=2,24 healing_spells=6, healing_bonus=3, healing_dice=4, sc_ability="cha",25 attack_parameters=[['rapier', 4, 2, 8]], alt_attack=['net', 4, 0, 0], level=3)26 elif name == "bard":27 self._initialise(name="Bard", alignment="good",28 hp=18, ac=18,29 healing_spells=6, healing_bonus=3, healing_dice=4,30 initiative_bonus=2,31 attack_parameters=[['rapier', 4, 2, 8]], level=3)32 elif name == "generic_tank":33 self._initialise(name="generic tank", alignment="good",34 hp=20, ac=17,35 initiative_bonus=2,36 attack_parameters=[['great sword', 5, 3, 6, 6]], level=3)37 elif name == "mega_tank":38 self._initialise(name="mega tank", alignment="good",39 hp=24, ac=17,40 initiative_bonus=2,41 attack_parameters=[['great sword', 5, 3, 10]], level=3)42 elif name == "a_b_dragon":43 self._initialise(name="Adult black dragon (minus frightful)", alignment="evil",44 ac=19, hp=195, initiative_bonus=2,45 attack_parameters=[['1', 11, 6, 10, 10], ['2', 11, 6, 6, 6], ['2', 11, 4, 6, 6]])46 elif name == "y_b_dragon":47 self._initialise(name="Young black dragon", alignment="evil",48 ac=18, hp=127,49 initiative_bonus=2,50 attack_parameters=[['1', 7, 4, 10, 10, 8], ['2', 7, 4, 6, 6], ['2', 7, 4, 6, 6]])51 elif name == "frost_giant":52 self._initialise(name="Frost Giant", alignment="evil",53 ac=15, hp=138,54 attack_parameters=[['club', 9, 6, 12, 12, 12], ['club', 9, 6, 12, 12, 12]])55 elif name == "hill_giant":56 self._initialise(name="Hill Giant", alignment="evil",57 ac=13, hp=105,58 attack_parameters=[['club', 8, 5, 8, 8, 8], ['club', 8, 5, 8, 8, 8]])59 elif name == "goblin":60 self._initialise(name="Goblin", alignment="evil",61 ac=15, hp=7,62 initiative_bonus=2,63 attack_parameters=[['sword', 4, 2, 6]])64 elif name == "hero":65 self._initialise(name="hero", alignment="good",66 ac=16, hp=18, # bog standard shielded leather-clad level 3.67 attack_parameters=[['longsword', 4, 2, 8]])68 elif name == "antijoe":69 self._initialise(name="antiJoe", alignment="evil",70 ac=17, hp=103, # bog standard leather-clad level 3.71 attack_parameters=[['shortsword', 2, 2, 6]])72 elif name == "joe":73 self._initialise(name="Joe", alignment="good",74 ac=17, hp=103, # bog standard leather-clad level 3.75 attack_parameters=[['shortsword', 2, 2, 6]])76 elif name == "bob":77 self._initialise(name="Bob", alignment="mad",78 ac=10, hp=8,79 attack_parameters=[['club', 2, 0, 4], ['club', 2, 0, 4]])80 elif name == "allo":81 self._initialise(name="Allosaurus", alignment="evil",82 ac=13, hp=51,83 attack_parameters=[['claw', 6, 4, 8], ['bite', 6, 4, 10, 10]])84 elif name == "anky":85 self._initialise("Ankylosaurus",86 ac=15, hp=68, alignment='evil',87 attack_parameters=[['tail', 7, 4, 6, 6, 6, 6]],88 log="CR 3 700 XP")89 elif name == "my barbarian":90 self._initialise(name="Barbarian",91 ac=18, hp=66, alignment="good",92 attack_parameters=[['greatsword', 4, 1, 6, 6], ['frenzy greatsword', 4, 1, 6, 6]],93 log="hp is doubled due to resistance", level=3)94 elif name == "my druid":95 self._initialise(name="Twice Brown Bear Druid",96 hp=86, ac=11, alignment="good",97 attack_parameters=[['claw', 5, 4, 8], ['bite', 5, 4, 6, 6]],98 ability_bonuses=[0, 0, 0, 0, 3, 0],99 sc_ability='wis', buff='cast_barkskin', buff_spells=4,100 log='The hp is bear x 2 + druid', level=3)101 elif name == "inert":102 self._initialise(name="inert", alignment="bad",103 ac=10, hp=20,104 attack_parameters=[['toothpick', 0, 0, 2]])105 elif name == "test":106 self._initialise(name="Test", alignment="good",107 ac=10, hp=100,108 attack_parameters=[['club', 2, 0, 4]])109 elif name == "polar":110 self._initialise(name="polar bear", alignment='evil',111 ac=12, hp=42,112 attack_parameters=[['bite', 7, 5, 8], ['claw', 7, 5, 6, 6]])113 elif name == "paradox":114 self._initialise(name="Paradox", alignment="evil",115 ac=10, hp=200,116 attack_parameters=[['A', 2, 0, 1]])117 elif name == "commoner":118 self._initialise(name="Commoner", alignment="good",119 ac=10, hp=4,120 attack_parameters=[['club', 2, 0, 4]])121 elif name == "giant_rat":122 self._initialise(name="Giant Rat", alignment="evil",123 hp=7, ac=12,124 initiative_bonus=2,125 attack_parameters=[['bite', 4, 2, 4]])126 elif name == "twibear":127 self._initialise(name="Twice Brown Bear Druid",128 hp=86, ac=11, alignment="good",129 attack_parameters=[['claw', 5, 4, 8], ['bite', 5, 4, 6]], level=3)130 elif name == "barkskin_twibear":131 self._initialise(name="Druid twice as Barkskinned Brown Bear",132 hp=86, ac=16, alignment="good",133 attack_parameters=[['claw', 5, 4, 8], ['bite', 5, 4, 6]], level=3)134 elif name == "barkskin_bear":135 self._initialise(name="Barkskinned Brown Bear", alignment="good",136 hp=34, ac=16,137 attack_parameters=[['claw', 5, 4, 8], ['bite', 5, 4, 6]], level=4, hd=10)138 elif name == "giant_toad":139 self._initialise(name="Giant Toad", alignment="evil",140 hp=39, ac=11,141 attack_parameters=[['lick', 4, 2, 10, 10]])142 elif name == "cthulhu": # PF stats. who cares. you'll die.143 self._initialise(name="Cthulhu", alignment="beyond",144 ac=49, hp=774, xp=9830400,145 initiative_bonus=15,146 attack_parameters=[['2 claws', 42, 23, 6, 6, 6, 6], ['4 tentacles', 42, 34, 10, 10]],147 alt_attack=['none', 0],148 healing_spells=99999, healing_dice=1, healing_bonus=30,149 ability_bonuses=[56, 21, 45, 31, 36, 34], sc_ability='wis',150 buff='cast_nothing', buff_spells=0, log=None, hd=8, level=36, proficiency=27)151 else:152 self._initialise(name="Commoner", alignment="evil",153 ac=10, hp=4,...
test_startup.py
Source:test_startup.py
1# This file is part of datacube-ows, part of the Open Data Cube project.2# See https://opendatacube.org for more information.3#4# Copyright (c) 2017-2021 OWS Contributors5# SPDX-License-Identifier: Apache-2.06import os7from unittest.mock import MagicMock, patch8import flask9import pytest10def test_fake_creds(monkeypatch):11 from datacube_ows.startup_utils import (CredentialManager,12 initialise_aws_credentials)13 CredentialManager._instance = None14 log = MagicMock()15 monkeypatch.setenv("AWS_DEFAULT_REGION", "")16 initialise_aws_credentials(log=log)17 CredentialManager._instance = None18 monkeypatch.setenv("AWS_DEFAULT_REGION", "us-west-1")19 monkeypatch.setenv("AWS_NO_SIGN_REQUEST", "false")20 monkeypatch.setenv("AWS_REQUEST_PAYER", "requester")21 with patch("datacube_ows.startup_utils.configure_s3_access") as s3a:22 s3a.return_value = None23 initialise_aws_credentials(log=log)24 assert os.getenv("AWS_NO_SIGN_REQUEST") is None25 CredentialManager._instance = None26 monkeypatch.setenv("AWS_NO_SIGN_REQUEST", "yes")27 initialise_aws_credentials()28 assert os.getenv("AWS_ACCESS_KEY_ID") == "fake"29def test_renewable_creds(monkeypatch):30 from datacube_ows.startup_utils import (CredentialManager,31 RefreshableCredentials,32 initialise_aws_credentials)33 CredentialManager._instance = None34 log = MagicMock()35 monkeypatch.setenv("AWS_DEFAULT_REGION", "")36 initialise_aws_credentials(log=log)37 CredentialManager._instance = None38 monkeypatch.setenv("AWS_DEFAULT_REGION", "us-west-1")39 monkeypatch.setenv("AWS_NO_SIGN_REQUEST", "false")40 monkeypatch.setenv("AWS_REQUEST_PAYER", "requester")41 with patch("datacube_ows.startup_utils.configure_s3_access") as s3a:42 mock_creds = MagicMock(spec=RefreshableCredentials)43 s3a.return_value = mock_creds44 initialise_aws_credentials(log=log)45 CredentialManager.check_cred()46 mock_creds.refresh_needed.return_value = True47 CredentialManager.check_cred()48def test_s3_endpoint_default(monkeypatch):49 from datacube_ows.startup_utils import (CredentialManager,50 initialise_aws_credentials)51 CredentialManager._instance = None52 log = MagicMock()53 monkeypatch.setenv("AWS_DEFAULT_REGION", "us-west-1")54 monkeypatch.setenv("AWS_S3_ENDPOINT", "")55 initialise_aws_credentials(log=log)56 assert "AWS_S3_ENDPOINT" not in os.environ57def test_initialise_logger():58 from datacube_ows.startup_utils import initialise_logger59 log = initialise_logger("tim.the.testlogger")60 assert log is not None61 log.info("Test")62def test_initialise_ign_warn():63 from datacube_ows.startup_utils import initialise_ignorable_warnings64 initialise_ignorable_warnings()65def test_initialise_nodebugging(monkeypatch):66 monkeypatch.setenv("PYDEV_DEBUG", "")67 from datacube_ows.startup_utils import initialise_debugging68 initialise_debugging()69def test_initialise_debugging(monkeypatch):70 monkeypatch.setenv("PYDEV_DEBUG", "YES")71 from datacube_ows.startup_utils import initialise_debugging72 fake_mod = MagicMock()73 with patch.dict("sys.modules", pydevd_pycharm=fake_mod) as set_trc:74 initialise_debugging()75 fake_mod.settrace.assert_called()76def test_initialise_sentry(monkeypatch):77 monkeypatch.setenv("SENTRY_KEY", "")78 monkeypatch.setenv("SENTRY_PROJECT", "")79 from datacube_ows.startup_utils import initialise_sentry80 initialise_sentry()81 monkeypatch.setenv("SENTRY_KEY", "dummy_key")82 monkeypatch.setenv("SENTRY_PROJECT", "dummy_project")83 log = MagicMock()84 try:85 initialise_sentry(log)86 except Exception:87 pass88def test_prometheus_inactive(monkeypatch):89 monkeypatch.setenv("prometheus_multiproc_dir", "")90 from datacube_ows.startup_utils import initialise_prometheus91 initialise_prometheus(None)92def test_supported_version():93 from datacube_ows.protocol_versions import SupportedSvcVersion94 ver = SupportedSvcVersion("wts", "1.2.3", "a", "b")95 assert ver.service == "wts"96 assert ver.service_upper == "WTS"97 assert ver.version == "1.2.3"98 assert ver.version_parts == [1, 2, 3]99 assert ver.router == "a"100 assert ver.exception_class == "b"101 from datacube_ows.protocol_versions import supported_versions102 supported = supported_versions()103 assert supported["wms"].versions[0].service == "wms"104def test_generate_locale_sel():105 app = flask.Flask("test_generate_locale_selector")106 from datacube_ows.startup_utils import generate_locale_selector107 with app.test_request_context(headers={"Accept-Language": "sw, fr;q=0.7, de;q=0.2"}):108 selector = generate_locale_selector(["en", "de", "sw"])109 assert selector() == "sw"110@pytest.fixture111def babel_cfg():112 cfg = MagicMock()113 cfg.internationalised = True114 cfg.locales = ["en", "de"]115 cfg.translations_dir = f"{os.path.dirname(__file__)}/translations"116 cfg.message_domain = "ows_cfg"117 return cfg118@pytest.fixture119def flask_app():120 app = flask.Flask("test_flask_app")121 return app122def test_init_babel_on(babel_cfg, flask_app):123 from datacube_ows.startup_utils import initialise_babel124 bab = initialise_babel(babel_cfg, flask_app)125 assert bab is not None126 assert bab.default_locale.language == "en"127def test_init_babel_off(babel_cfg, flask_app):128 from datacube_ows.startup_utils import initialise_babel129 babel_cfg.internationalised = False130 bab = initialise_babel(babel_cfg, flask_app)...
test_.py
Source:test_.py
1import setup.board as initialise2from . import rules3def test_naked_actual_numbers_rule():4 board = initialise.setup_board()5 board[(0, 8)] = {1}6 naked = initialise.get_col(board, (0, 8))7 updated = rules.actual_numbers_rule(naked)8 for y in range(8):9 assert 1 not in board[(0, y)]10 assert (0, y) in updated11 assert 1 in board[(0, 8)]12 assert (0, 8) not in updated13def test_hidden_actual_numbers_rule():14 board = initialise.setup_board()15 for y in range(8):16 board[(0, y)] = set(range(1, 9))17 hidden = initialise.get_col(board, (0, 8))18 updated = rules.actual_numbers_rule(hidden)19 assert updated == {(0, 8)}20 assert board[(0, 8)] == {9}21def test_multiples_sort():22 board = initialise.setup_board()23 slice = initialise.get_col(board, (0, 0))24 slice[0, 4] = {1, 2, 3}25 sorted = rules.multiples_sort(slice)26 assert sorted[0] == (3, {1, 2, 3}, (0, 4))27def test_find_multiples():28 board = initialise.setup_board()29 slice = initialise.get_col(board, (0, 0))30 slice[0, 4] = {1, 2}31 slice[0, 5] = {1, 2}32 multiples = rules.find_multiples(slice)33 assert len(multiples) == 134 assert multiples[0] == ({(0, 4), (0, 5)}, {1, 2})35def test_naked_multiples_rule():36 board = initialise.setup_board()37 slice = initialise.get_col(board, (0, 0))38 slice[0, 7] = {1, 2}39 slice[0, 8] = {1, 2}40 updated = rules.multiples_rule(slice)41 assert len(updated) == 742 for y in range(7):43 assert (0, y) in updated44 assert 1 not in slice[(0, y)]45 assert 2 not in slice[(0, y)]46 assert 1 not in board[(0, y)]47 assert 2 not in board[(0, y)]48def test_hidden_multiples_rule():49 board = initialise.setup_board()50 slice = initialise.get_col(board, (0, 0))51 for y in range(7):52 slice[0, y] = set(range(3, 10))53 board[(0, y)] = slice[(0, y)]54 slice[0, 7] = {1, 2, 3}55 slice[0, 8] = {1, 2, 4}56 for y in range(9):57 board[(0, y)] = slice[(0, y)]58 updated = rules.multiples_rule(slice)59 assert updated == {(0, 7), (0, 8)}60 assert slice[(0, 7)] == {1, 2}61 assert slice[(0, 8)] == {1, 2}62 assert board[(0, 7)] == {1, 2}63 assert board[(0, 8)] == {1, 2}64def test_find_intersection_values():65 board = initialise.setup_board()66 slice = initialise.get_col(board, (0, 0))67 for y in range(3, 9):68 slice[(0, y)] = set(range(1,7))69 slice[(0, 0)] = {1, 2, 8}70 slice[(0, 1)] = {5, 6, 7}71 slice[(0, 2)] = {3, 6, 9}72 intersect = {(0, 0), (0, 1), (0, 2)}73 values = rules.find_intersection_values(intersect, slice)74 assert values == {7, 8, 9}75def test_intersection_rule():76 board = initialise.setup_board()77 s1 = initialise.get_sqr(board, (0, 0))78 s2 = initialise.get_col(board, (0, 0))79 intersection = {(0, 0), (0, 1), (0, 2)}80 for point in set(s1.keys()) - intersection:81 s1[point].remove(1)82 for point in set(s2.keys()) - intersection:83 s2[point].remove(2)84 updated = rules.intersection_rule(s1, s2)85 for point in set(s1.keys()) - intersection:86 assert 2 not in s1[point]87 for point in set(s2.keys()) - intersection:88 assert 1 not in s2[point]...
setupQn.py
Source:setupQn.py
...16from pimms.apps.qn.initialiser.initialiseRefs import initialiseRefs17from pimms.apps.qn.initialiser.initialiseFiles import initialiseFiles18from pimms.apps.qn.initialiser.initialiseVars import initialiseVars19# Initialise the Questionnaire20initialise()21# load cmip5 input files22initialiseFiles()23# load variables associated with cmip5 input files24initialiseVars()25# load cmip5 input references26initialiseRefs()27# create experiments28experimentDir = os.path.join(settings.PROJECT_ROOT, "static/data/experiments")29for f in os.listdir(experimentDir):30 if f.endswith('.xml'):31 x = Experiment.fromXML(os.path.join(experimentDir, f))32# initialise a model template33initialiseModel()34# initialise a grid template...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!