How to use load_configuration method in Behave

Best Python code snippet using behave

gameserver-daemon.py

Source:gameserver-daemon.py Github

copy

Full Screen

...22CONFIG_FILE = "server.conf"23# Don't touch this. This is ConfigParser's shortcut.24parser = ConfigParser.RawConfigParser()25# Method to load up a configuration file26def load_configuration(config):27 parser.read(config)28 gameserver = parser._sections29 return gameserver30# Load the current configuration and a default suite of args for argparser31if os.path.isfile(CONFIG_FILE):32 gameserver = load_configuration(CONFIG_FILE)33 steam_appid = gameserver['steamcmd']['appid']34 steamcmd_path = gameserver['steamcmd']['path']35 gamedir = os.path.join(steamcmd_path, steam_appid)36 engine = gameserver['steamcmd']['engine']37else:38 gameserver = False39 steam_appid = False40 steamcmd_path = False41 engine = False42# The default argparse description43argparser = argparse.ArgumentParser(description="f0rkz gameserver daemon. Used to manage gameserver files.")44# Check if steam_appid is loaded up45if steam_appid:46 # Basic shared items47 argparser.add_argument("--configure", help="Run the configuration tool and exit.", action="store_true")48 argparser.add_argument("--installcontent", help="Install a game's content.", action="store_true")49 argparser.add_argument("-u", "--update", help="Update the gameserver files.", action="store_true")50 argparser.add_argument("--validate", help="Use the validate switch for steamcmd. This will update the game if no other options are set.", action="store_true")51 argparser.add_argument("--steamcmd", help="Install steamcmd to the configured directory.", action="store_true")52 # Begin loading each option for the configured game53 if engine == 'srcds':54 # Stuff for srcds55 argparser.add_argument("--runscript", help="Generate the runscript.txt file.", action="store_true")56 argparser.add_argument("--servercfg", help="Generate the server.cfg file", action="store_true")57 argparser.add_argument("--motd", help="Generate the motd.txt", action="store_true")58 argparser.add_argument("--start", help="Start the gameserver.", action="store_true")59 argparser.add_argument("--stop", help="Stop the gameserver.", action="store_true")60 argparser.add_argument("--restart", help="Restart the gameserver.", action="store_true")61 if engine == 'hlds':62 # Stuff for hlds63 argparser.add_argument("--runscript", help="Generate the runscript.txt file.", action="store_true")64 argparser.add_argument("--servercfg", help="Generate the server.cfg file", action="store_true")65 argparser.add_argument("--start", help="Start the gameserver.", action="store_true")66 argparser.add_argument("--stop", help="Stop the gameserver.", action="store_true")67 argparser.add_argument("--restart", help="Restart the gameserver.", action="store_true")68 if engine == 'unreal':69 # Stuff for unreal70 argparser.add_argument("--start", help="Start the gameserver.", action="store_true")71 argparser.add_argument("--stop", help="Stop the gameserver.", action="store_true")72 argparser.add_argument("--restart", help="Restart the gameserver.", action="store_true")73else:74 argparser.add_argument("--configure", help="Run the configuration tool.", action="store_true")75# Load up the arguments processed above76args = argparser.parse_args()77# Give the user a message if no config file is found.78if not os.path.isfile(CONFIG_FILE) and not args.configure:79 sys.exit("No configuration file found. Run: python gameserver-daemon.py --configure")80# --------------------------------------------81# Begin configuration of SRCDS and gameserver82# --------------------------------------------83try:84 if os.path.isfile(CONFIG_FILE) and args.configure:85 user_input = raw_input("server.conf already exists, overwrite? [Y/n]: ")86 if str.lower(user_input) == "y":87 subprocess.call("rm {}".format(CONFIG_FILE), shell=True)88 else:89 sys.exit("Configuration will not be removed. Exiting.")90except AttributeError:91 pass92try:93 if not os.path.isfile(CONFIG_FILE) and args.configure:94 base_config = GameServer(gsconfig = gameserver)95 base_config.configure()96 # Load up the configuration after the base is installed97 gameserver = load_configuration(CONFIG_FILE)98 steam_appid = gameserver['steamcmd']['appid']99 steamcmd_path = gameserver['steamcmd']['path']100 engine = gameserver['steamcmd']['engine']101 # Begin the game engine shared configuration102 # SRCDS configuration103 if engine == 'srcds':104 engine_config = SRCDS(gsconfig = gameserver)105 engine_config.configure()106 elif engine == 'hlds':107 engine_config = HLDS(gsconfig = gameserver)108 engine_config.configure()109 # Unreal configuration110 elif engine == 'unreal':111 engine_config = Unreal(gsconfig = gameserver)112 engine_config.configure()113 # Begin the gameserver's configuration modules114 # CSGO115 if steam_appid == '740':116 game_config = CSGOServer(gsconfig = gameserver)117 game_config.configure()118 # TF2119 elif steam_appid == '232250':120 game_config = TF2Server(gsconfig = gameserver)121 game_config.configure()122 # HL2DM123 elif steam_appid == '232370':124 game_config = HL2DMServer(gsconfig = gameserver)125 game_config.configure()126 # BMS127 elif steam_appid == '346680':128 game_config = BMSServer(gsconfig = gameserver)129 game_config.configure()130 # left4dead2131 elif steam_appid == '222860':132 game_config = L4D2Server(gsconfig = gameserver)133 game_config.configure()134 # ARK135 elif steam_appid == '376030':136 game_config = ARKServer(gsconfig = gameserver)137 game_config.configure()138 # GSMOD139 elif steam_appid == '4020':140 game_config = GSModServer(gsconfig = gameserver)141 game_config.configure()142 # SvenCoopServer143 elif steam_appid == '276060':144 game_config = SvenCoopServer(gsconfig = gameserver)145 game_config.configure()146except AttributeError:147 pass148# --------------------------------------------149# Steamcmd operations150# --------------------------------------------151# Steam cmd install152try:153 if os.path.isfile(CONFIG_FILE) and args.steamcmd:154 gameserver = load_configuration(CONFIG_FILE)155 steamcmd = GameServer(gsconfig = gameserver)156 steamcmd.install_steamcmd()157except AttributeError:158 pass159# Installs a game's content for garry's mod160try:161 if os.path.isfile(CONFIG_FILE) and args.installcontent:162 install_files = GameServer(gsconfig = gameserver)163 install_files.install_content()164except AttributeError:165 pass166# Update gamefiles167try:168 if os.path.isfile(CONFIG_FILE) and args.update:169 gameserver = load_configuration(CONFIG_FILE)170 update = GameServer(gsconfig = gameserver)171 install_dir = os.path.join(gameserver['steamcmd']['path'], '')172 if not os.path.isfile(os.path.join(install_dir, 'steamcmd.sh')):173 print "Steamcmd was not found. Installing steamcmd."174 update.install_steamcmd()175 if args.validate:176 update.update_game_validate()177 else:178 update.update_game_novalidate()179except AttributeError:180 pass181# --------------------------------------------182# Game specific operations183# server.cfg, motd, runscript, etc...184# --------------------------------------------185try:186 if engine == 'srcds' or engine == 'hlds' and os.path.isdir(steamcmd_path):187 # Check if the game is installed before running these.188 if os.path.isdir(gamedir):189 # MOTD190 if os.path.isfile(CONFIG_FILE) and engine == 'srcds' and args.motd:191 gameserver = load_configuration(CONFIG_FILE)192 motd = SRCDS(gsconfig = gameserver)193 motd.create_motd()194 # Runscript creation195 if os.path.isfile(CONFIG_FILE) and engine == 'srcds' and args.runscript:196 gameserver = load_configuration(CONFIG_FILE)197 runscript = SRCDS(gsconfig = gameserver)198 runscript.create_runscript()199 elif os.path.isfile(CONFIG_FILE) and engine == 'hlds' and args.runscript:200 gameserver = load_configuration(CONFIG_FILE)201 runscript = HLDS(gsconfig = gameserver)202 runscript.create_runscript()203 # Server.cfg creation204 if os.path.isfile(CONFIG_FILE) and engine == 'srcds' and args.servercfg:205 gameserver = load_configuration(CONFIG_FILE)206 servercfg = SRCDS(gsconfig = gameserver)207 servercfg.create_servercfg()208 elif os.path.isfile(CONFIG_FILE) and engine == 'hlds' and args.servercfg:209 gameserver = load_configuration(CONFIG_FILE)210 servercfg = HLDS(gsconfig = gameserver)211 servercfg.create_servercfg()212 else:213 sys.exit("Game is not installed. Use the --update command to install the game files.")214except AttributeError:215 pass216# --------------------------------------------217# Server related operations218# Start, stop, restart, etc.219# --------------------------------------------220# Start operations221try:222 if engine == 'srcds' or engine == 'hlds' or engine == 'unreal' and os.path.isdir(steamcmd_path):223 # Check if the game is installed224 if os.path.isdir(gamedir):225 # CSGO226 if steam_appid == '740' and args.start:227 gameserver = load_configuration(CONFIG_FILE)228 csgo = CSGOServer(gsconfig = gameserver)229 csgo.start()230 # TF2231 elif steam_appid == '232250' and args.start:232 gameserver = load_configuration(CONFIG_FILE)233 tf2 = TF2Server(gsconfig = gameserver)234 tf2.start()235 # HL2DM236 elif steam_appid == '232370' and args.start:237 gameserver = load_configuration(CONFIG_FILE)238 hl2dm = HL2DMServer(gsconfig = gameserver)239 hl2dm.start()240 # BMS241 elif steam_appid == '346680' and args.start:242 gameserver = load_configuration(CONFIG_FILE)243 bms = BMSServer(gsconfig = gameserver)244 bms.start()245 # left4dead2246 elif steam_appid == '222860' and args.start:247 gameserver = load_configuration(CONFIG_FILE)248 l4d2 = L4D2Server(gsconfig = gameserver)249 l4d2.start()250 # ARK251 elif steam_appid == '376030' and args.start:252 gameserver = load_configuration(CONFIG_FILE)253 ark = ARKServer(gsconfig = gameserver)254 ark.start()255 # GSMOD256 elif steam_appid == '4020' and args.start:257 gameserver = load_configuration(CONFIG_FILE)258 gsmod = GSModServer(gsconfig = gameserver)259 gsmod.start()260 # Sven coop261 elif steam_appid == '276060' and args.start:262 gameserver = load_configuration(CONFIG_FILE)263 svencoop = SvenCoopServer(gsconfig = gameserver)264 svencoop.start()265 # Stop operations266 # CSGO267 if steam_appid == '740' and args.stop:268 gameserver = load_configuration(CONFIG_FILE)269 csgo = CSGOServer(gsconfig = gameserver)270 csgo.stop()271 # TF2272 elif steam_appid == '232250' and args.stop:273 gameserver = load_configuration(CONFIG_FILE)274 tf2 = TF2Server(gsconfig = gameserver)275 tf2.stop()276 # HL2DM277 elif steam_appid == '232370' and args.stop:278 gameserver = load_configuration(CONFIG_FILE)279 hl2dm = HL2DMServer(gsconfig = gameserver)280 hl2dm.stop()281 # BMS282 elif steam_appid == '346680' and args.stop:283 gameserver = load_configuration(CONFIG_FILE)284 bms = BMSServer(gsconfig = gameserver)285 bms.stop()286 # left4dead2287 elif steam_appid == '222860' and args.stop:288 gameserver = load_configuration(CONFIG_FILE)289 l4d2 = L4D2Server(gsconfig = gameserver)290 l4d2.stop()291 # ARK292 elif steam_appid == '376030' and args.stop:293 gameserver = load_configuration(CONFIG_FILE)294 ark = ARKServer(gsconfig = gameserver)295 ark.stop()296 # GSMOD297 elif steam_appid == '4020' and args.stop:298 gameserver = load_configuration(CONFIG_FILE)299 gsmod = GSModServer(gsconfig = gameserver)300 gsmod.stop()301 # SvenCoop302 elif steam_appid == '276060' and args.stop:303 gameserver = load_configuration(CONFIG_FILE)304 svencoop = SvenCoopServer(gsconfig = gameserver)305 svencoop.stop()306 # Restart operations307 # CSGO308 if steam_appid == '740' and args.restart:309 gameserver = load_configuration(CONFIG_FILE)310 csgo = CSGOServer(gsconfig = gameserver)311 csgo.stop()312 csgo.start()313 # TF2314 elif steam_appid == '232250' and args.restart:315 gameserver = load_configuration(CONFIG_FILE)316 tf2 = TF2Server(gsconfig = gameserver)317 tf2.stop()318 tf2.start()319 # HL2DM320 elif steam_appid == '232370' and args.restart:321 gameserver = load_configuration(CONFIG_FILE)322 hl2dm = HL2DMServer(gsconfig = gameserver)323 hl2dm.stop()324 hl2dm.start()325 # BMS326 elif steam_appid == '346680' and args.restart:327 gameserver = load_configuration(CONFIG_FILE)328 bms = BMSServer(gsconfig = gameserver)329 bms.stop()330 bms.start()331 # left4dead2332 elif steam_appid == '222860' and args.restart:333 gameserver = load_configuration(CONFIG_FILE)334 l4d2 = L4D2Server(gsconfig = gameserver)335 l4d2.stop()336 l4d2.start()337 # ARK338 elif steam_appid == '376030' and args.restart:339 gameserver = load_configuration(CONFIG_FILE)340 ark = ARKServer(gsconfig = gameserver)341 ark.stop()342 ark.start()343 # GSMOD344 elif steam_appid == '4020' and args.restart:345 gameserver = load_configuration(CONFIG_FILE)346 gsmod = GSModServer(gsconfig = gameserver)347 gsmod.stop()348 gsmod.start()349 # SvenCoop350 elif steam_appid == '4020' and args.restart:351 gameserver = load_configuration(CONFIG_FILE)352 svencoop = SvenCoopServer(gsconfig = gameserver)353 svencoop.stop()354 svencoop.start()355 else:356 sys.exit("Game is not installed. Use the --update command to install the game files.")357except (AttributeError, NameError):...

Full Screen

Full Screen

test_check_duo.py

Source:test_check_duo.py Github

copy

Full Screen

...25 "name": "foobar",26 "expiry": "10"27 }28 }""")29 configuration = self.load_configuration(configuration_path)30 self.assertEqual(configuration, {31 "username": "foobar",32 "password": "bazbat",33 "duo": {34 "ikey": "asdf",35 "skey": "fdsa",36 "host": "api-1234.example.com",37 },38 "cache": {39 "host": "foo.local",40 },41 "session": {42 "name": "foobar",43 "expiry": 10,44 },45 })46 def test_missing_configuration(self):47 with tempfile.TemporaryDirectory() as t:48 configuration_path = os.path.join(t, "configuration.json")49 with self.assertRaises(self.checker.ConfigurationError):50 self.load_configuration(configuration_path)51 def test_invalid_configuration(self):52 with tempfile.TemporaryDirectory() as t:53 configuration_path = os.path.join(t, "configuration.json")54 with open(configuration_path, "wt") as f:55 f.write("""{56 "username": " foobar ",57 "password": " bazbat ",58 "duo": {59 "ikey": "asdf ",60 "skey": " fdsa ",61 "host": " api-1234.example.com ",62 }63 }""")64 with self.assertRaises(self.checker.ConfigurationError):65 self.load_configuration(configuration_path)66 def test_missing_username(self):67 with tempfile.TemporaryDirectory() as t:68 configuration_path = os.path.join(t, "configuration.json")69 with open(configuration_path, "wt") as f:70 f.write("""{71 "password": " bazbat ",72 "duo": {73 "ikey": "asdf ",74 "skey": " fdsa ",75 "host": " api-1234.example.com "76 }77 }""")78 with self.assertRaises(self.checker.ConfigurationError):79 self.load_configuration(configuration_path)80 with open(configuration_path, "wt") as f:81 f.write("""{82 "username": null,83 "password": " bazbat ",84 "duo": {85 "ikey": "asdf ",86 "skey": " fdsa ",87 "host": " api-1234.example.com "88 }89 }""")90 with self.assertRaises(self.checker.ConfigurationError):91 self.load_configuration(configuration_path)92 with open(configuration_path, "wt") as f:93 f.write("""{94 "username": "",95 "password": " bazbat ",96 "duo": {97 "ikey": "asdf ",98 "skey": " fdsa ",99 "host": " api-1234.example.com "100 }101 }""")102 with self.assertRaises(self.checker.ConfigurationError):103 self.load_configuration(configuration_path)104 def test_missing_password(self):105 with tempfile.TemporaryDirectory() as t:106 configuration_path = os.path.join(t, "configuration.json")107 with open(configuration_path, "wt") as f:108 f.write("""{109 "username": " foobar ",110 "duo": {111 "ikey": "asdf ",112 "skey": " fdsa ",113 "host": " api-1234.example.com "114 }115 }""")116 with self.assertRaises(self.checker.ConfigurationError):117 self.load_configuration(configuration_path)118 with open(configuration_path, "wt") as f:119 f.write("""{120 "username": " foobar ",121 "password": null,122 "duo": {123 "ikey": "asdf ",124 "skey": " fdsa ",125 "host": " api-1234.example.com "126 }127 }""")128 with self.assertRaises(self.checker.ConfigurationError):129 self.load_configuration(configuration_path)130 with open(configuration_path, "wt") as f:131 f.write("""{132 "username": " foobar ",133 "password": "",134 "duo": {135 "ikey": "asdf ",136 "skey": " fdsa ",137 "host": " api-1234.example.com "138 }139 }""")140 with self.assertRaises(self.checker.ConfigurationError):141 self.load_configuration(configuration_path)142 def test_missing_duo(self):143 with tempfile.TemporaryDirectory() as t:144 configuration_path = os.path.join(t, "configuration.json")145 with open(configuration_path, "wt") as f:146 f.write("""{147 "username": " foobar ",148 "password": " bazbat ",149 }""")150 with self.assertRaises(self.checker.ConfigurationError):151 self.load_configuration(configuration_path)152 with open(configuration_path, "wt") as f:153 f.write("""{154 "username": " foobar ",155 "password": " bazbat ",156 "duo": null157 }""")158 with self.assertRaises(self.checker.ConfigurationError):159 self.load_configuration(configuration_path)160 with open(configuration_path, "wt") as f:161 f.write("""{162 "username": " foobar ",163 "password": " bazbat ",164 "duo": {}165 }""")166 with self.assertRaises(self.checker.ConfigurationError):167 self.load_configuration(configuration_path)168 with open(configuration_path, "wt") as f:169 f.write("""{170 "username": " foobar ",171 "password": " bazbat ",172 "duo": ""173 }""")174 with self.assertRaises(self.checker.ConfigurationError):175 self.load_configuration(configuration_path)176 def test_missing_ikey(self):177 with tempfile.TemporaryDirectory() as t:178 configuration_path = os.path.join(t, "configuration.json")179 with open(configuration_path, "wt") as f:180 f.write("""{181 "username": " foobar ",182 "password": " fdskal ",183 "duo": {184 "skey": " fdsa ",185 "host": " api-1234.example.com "186 }187 }""")188 with self.assertRaises(self.checker.ConfigurationError):189 self.load_configuration(configuration_path)190 with open(configuration_path, "wt") as f:191 f.write("""{192 "username": " foobar ",193 "password": " fdskal ",194 "duo": {195 "ikey": null,196 "skey": " fdsa ",197 "host": " api-1234.example.com "198 }199 }""")200 with self.assertRaises(self.checker.ConfigurationError):201 self.load_configuration(configuration_path)202 with open(configuration_path, "wt") as f:203 f.write("""{204 "username": " foobar ",205 "password": " fdskal ",206 "duo": {207 "ikey": "",208 "skey": " fdsa ",209 "host": " api-1234.example.com "210 }211 }""")212 with self.assertRaises(self.checker.ConfigurationError):213 self.load_configuration(configuration_path)214 def test_missing_skey(self):215 with tempfile.TemporaryDirectory() as t:216 configuration_path = os.path.join(t, "configuration.json")217 with open(configuration_path, "wt") as f:218 f.write("""{219 "username": " foobar ",220 "password": " fdskal ",221 "duo": {222 "ikey": "asdf ",223 "host": " api-1234.example.com "224 }225 }""")226 with self.assertRaises(self.checker.ConfigurationError):227 self.load_configuration(configuration_path)228 with open(configuration_path, "wt") as f:229 f.write("""{230 "username": " foobar ",231 "password": " fdskal ",232 "duo": {233 "ikey": "asdf ",234 "skey": null,235 "host": " api-1234.example.com "236 }237 }""")238 with self.assertRaises(self.checker.ConfigurationError):239 self.load_configuration(configuration_path)240 with open(configuration_path, "wt") as f:241 f.write("""{242 "username": " foobar ",243 "password": " fdskal ",244 "duo": {245 "ikey": "asdf ",246 "skey": "",247 "host": " api-1234.example.com "248 }249 }""")250 with self.assertRaises(self.checker.ConfigurationError):251 self.load_configuration(configuration_path)252 def test_missing_host(self):253 with tempfile.TemporaryDirectory() as t:254 configuration_path = os.path.join(t, "configuration.json")255 with open(configuration_path, "wt") as f:256 f.write("""{257 "username": " foobar ",258 "password": " fdskal ",259 "duo": {260 "ikey": "asdf ",261 "skey": " fdsa "262 }263 }""")264 with self.assertRaises(self.checker.ConfigurationError):265 self.load_configuration(configuration_path)266 with open(configuration_path, "wt") as f:267 f.write("""{268 "username": " foobar ",269 "password": " fdskal ",270 "duo": {271 "ikey": "asdf ",272 "skey": " fdsa ",273 "host": null274 }275 }""")276 with self.assertRaises(self.checker.ConfigurationError):277 self.load_configuration(configuration_path)278 with open(configuration_path, "wt") as f:279 f.write("""{280 "username": " foobar ",281 "password": " fdskal ",282 "duo": {283 "ikey": "asdf ",284 "skey": " fdsa ",285 "host": ""286 }287 }""")288 with self.assertRaises(self.checker.ConfigurationError):289 self.load_configuration(configuration_path)290 @unittest.skip291 def test_duo_push(self):292 self.assertTrue(self.checker.call_duo(293 username="paul",294 configuration={295 "ikey": "asdf",296 "skey": "fdsa",297 "host": "api-abc123.duosecurity.com",298 },299 ))300if __name__ == '__main__':...

Full Screen

Full Screen

test_conf_loader.py

Source:test_conf_loader.py Github

copy

Full Screen

...9@pytest.mark.parametrize(10 "path", ["hydra/test_utils/configs", "pkg://hydra.test_utils.configs"]11)12class TestConfigLoader:13 def test_load_configuration(self, path):14 config_loader = ConfigLoader(15 config_search_path=create_search_path([path]),16 strict_cfg=False,17 config_file="config.yaml",18 )19 cfg = config_loader.load_configuration(overrides=["abc=123"])20 del cfg["hydra"]21 assert cfg == OmegaConf.create({"normal_yaml_config": True, "abc": 123})22 def test_load_with_missing_default(self, path):23 config_loader = ConfigLoader(24 config_search_path=create_search_path([path]),25 strict_cfg=False,26 config_file="missing-default.yaml",27 )28 with pytest.raises(MissingConfigException):29 config_loader.load_configuration()30 def test_load_with_missing_optional_default(self, path):31 config_loader = ConfigLoader(32 config_search_path=create_search_path([path]),33 strict_cfg=False,34 config_file="missing-optional-default.yaml",35 )36 cfg = config_loader.load_configuration()37 del cfg["hydra"]38 assert cfg == {}39 def test_load_with_optional_default(self, path):40 config_loader = ConfigLoader(41 config_search_path=create_search_path([path]),42 strict_cfg=False,43 config_file="optional-default.yaml",44 )45 cfg = config_loader.load_configuration()46 del cfg["hydra"]47 assert cfg == dict(foo=10)48 def test_load_changing_group_in_default(self, path):49 config_loader = ConfigLoader(50 config_search_path=create_search_path([path]),51 strict_cfg=False,52 config_file="optional-default.yaml",53 )54 cfg = config_loader.load_configuration(["group1=file2"])55 del cfg["hydra"]56 assert cfg == dict(foo=20)57 def test_load_adding_group_not_in_default(self, path):58 config_loader = ConfigLoader(59 config_search_path=create_search_path([path]),60 strict_cfg=False,61 config_file="optional-default.yaml",62 )63 cfg = config_loader.load_configuration(["group2=file1"])64 del cfg["hydra"]65 assert cfg == dict(foo=10, bar=100)66 def test_change_run_dir_with_override(self, path):67 config_loader = ConfigLoader(68 config_search_path=create_search_path([path]),69 strict_cfg=False,70 config_file="overriding_run_dir.yaml",71 )72 cfg = config_loader.load_configuration(overrides=["hydra.run.dir=abc"])73 assert cfg.hydra.run.dir == "abc"74 def test_change_run_dir_with_config(self, path):75 config_loader = ConfigLoader(76 config_search_path=create_search_path([path]),77 strict_cfg=False,78 config_file="overriding_run_dir.yaml",79 )80 cfg = config_loader.load_configuration(overrides=[])81 assert cfg.hydra.run.dir == "cde"82 def test_load_strict(self, path):83 """84 Ensure that in strict mode we can override only things that are already in the config85 :return:86 """87 config_loader = ConfigLoader(88 config_search_path=create_search_path([path]),89 config_file="compose.yaml",90 strict_cfg=True,91 )92 # Test that overriding existing things works in strict mode93 cfg = config_loader.load_configuration(overrides=["foo=ZZZ"])94 del cfg["hydra"]95 assert cfg == {"foo": "ZZZ", "bar": 100}96 # Test that accessing a key that is not there will fail97 with pytest.raises(KeyError):98 cfg.not_here99 # Test that bad overrides triggers the KeyError100 with pytest.raises(KeyError):101 config_loader.load_configuration(overrides=["f00=ZZZ"])102 def test_load_history(self, path):103 config_loader = ConfigLoader(104 config_search_path=create_search_path([path]),105 strict_cfg=False,106 config_file="missing-optional-default.yaml",107 )108 config_loader.load_configuration()109 assert config_loader.get_load_history() == [110 ("hydra.yaml", "pkg://hydra.conf", "hydra"),111 ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),112 ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),113 ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),114 ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),115 ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),116 ("missing-optional-default.yaml", path, "test"),117 ("foo/missing.yaml", None, None),118 ]119 def test_load_history_with_basic_launcher(self, path):120 config_loader = ConfigLoader(121 config_search_path=create_search_path([path]),122 strict_cfg=False,123 config_file="custom_default_launcher.yaml",124 )125 config_loader.load_configuration(overrides=["hydra/launcher=basic"])126 assert config_loader.get_load_history() == [127 ("hydra.yaml", "pkg://hydra.conf", "hydra"),128 ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),129 ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),130 ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),131 ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),132 ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),133 ("custom_default_launcher.yaml", path, "test"),134 ]135 def test_load_yml_file(self, path):136 config_loader = ConfigLoader(137 config_search_path=create_search_path([path]),138 strict_cfg=False,139 config_file="config.yml",140 )141 cfg = config_loader.load_configuration()142 del cfg["hydra"]143 assert cfg == dict(yml_file_here=True)144@pytest.mark.parametrize(145 "primary,merged,result",146 [147 ([], [], []),148 ([{"a": 10}], [], [{"a": 10}]),149 ([{"a": 10}, {"b": 20}], [{"a": 20}], [{"a": 20}, {"b": 20}]),150 (151 [152 {"hydra_logging": "default"},153 {"job_logging": "default"},154 {"launcher": "basic"},155 {"sweeper": "basic"},156 ],157 [{"optimizer": "nesterov"}, {"launcher": "basic"}],158 [159 {"hydra_logging": "default"},160 {"job_logging": "default"},161 {"launcher": "basic"},162 {"sweeper": "basic"},163 {"optimizer": "nesterov"},164 ],165 ),166 ],167)168def test_merge_default_lists(primary, merged, result):169 ConfigLoader._merge_default_lists(primary, merged)170 assert primary == result171@pytest.mark.parametrize(172 "config_file, overrides",173 [174 # remove from config175 ("removing-hydra-launcher-default.yaml", []),176 # remove from override177 ("config.yaml", ["hydra/launcher=null"]),178 # remove from both179 ("removing-hydra-launcher-default.yaml", ["hydra/launcher=null"]),180 # second overrides removes181 ("config.yaml", ["hydra/launcher=submitit", "hydra/launcher=null"]),182 ],183)184def test_default_removal(config_file, overrides):185 config_loader = ConfigLoader(186 config_search_path=create_search_path(["hydra/test_utils/configs"]),187 strict_cfg=False,188 config_file=config_file,189 )190 config_loader.load_configuration(overrides=overrides)191 assert config_loader.get_load_history() == [192 ("hydra.yaml", "pkg://hydra.conf", "hydra"),193 ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),194 ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),195 ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),196 ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),197 (config_file, "hydra/test_utils/configs", "test"),198 ]199def test_defaults_not_list_exception():200 config_loader = ConfigLoader(201 config_search_path=create_search_path(["hydra/test_utils/configs"]),202 strict_cfg=False,203 config_file="defaults_not_list.yaml",204 )205 with pytest.raises(ValueError):206 config_loader.load_configuration(overrides=[])207@pytest.mark.parametrize(208 "module_name, resource_name",209 [210 ("hydra.test_utils", ""),211 ("hydra.test_utils", "__init__.py"),212 ("hydra.test_utils", "configs"),213 ("hydra.test_utils", "configs/config.yaml"),214 ("hydra.test_utils.configs", ""),215 ("hydra.test_utils.configs", "config.yaml"),216 ("hydra.test_utils.configs", "group1"),217 ("hydra.test_utils.configs", "group1/file1.yaml"),218 ],219)220def test_resource_exists(module_name, resource_name):221 assert pkg_resources.resource_exists(module_name, resource_name) is True222def test_override_hydra_config_value_from_config_file():223 config_loader = ConfigLoader(224 config_search_path=create_search_path(["hydra/test_utils/configs"]),225 strict_cfg=False,226 config_file="overriding_output_dir.yaml",227 )228 cfg = config_loader.load_configuration(overrides=[])229 assert cfg.hydra.run.dir == "foo"230def test_override_hydra_config_group_from_config_file():231 config_loader = ConfigLoader(232 config_search_path=create_search_path(["hydra/test_utils/configs"]),233 strict_cfg=False,234 config_file="overriding_logging_default.yaml",235 )236 config_loader.load_configuration(overrides=[])237 assert config_loader.get_load_history() == [238 ("hydra.yaml", "pkg://hydra.conf", "hydra"),239 ("hydra/hydra_logging/hydra_debug.yaml", "pkg://hydra.conf", "hydra"),240 ("hydra/job_logging/disabled.yaml", "pkg://hydra.conf", "hydra"),241 ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),242 ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),243 ("overriding_logging_default.yaml", "hydra/test_utils/configs", "test"),244 ]245def test_list_groups():246 config_loader = ConfigLoader(247 config_search_path=create_search_path(["hydra/test_utils/configs"]),248 strict_cfg=False,249 config_file="overriding_output_dir.yaml",250 )251 assert sorted(config_loader.list_groups("")) == [252 "completion_test",253 "group1",254 "group2",255 "hydra",256 ]257 assert sorted(config_loader.list_groups("hydra")) == [258 "hydra_logging",259 "job_logging",260 "launcher",261 "output",262 "sweeper",263 ]264def test_non_config_group_default():265 config_loader = ConfigLoader(266 config_search_path=create_search_path(["hydra/test_utils/configs"]),267 strict_cfg=False,268 config_file="non_config_group_default.yaml",269 )270 config_loader.load_configuration()271 assert config_loader.get_load_history() == [272 ("hydra.yaml", "pkg://hydra.conf", "hydra"),273 ("hydra/hydra_logging/default.yaml", "pkg://hydra.conf", "hydra"),274 ("hydra/job_logging/default.yaml", "pkg://hydra.conf", "hydra"),275 ("hydra/launcher/basic.yaml", "pkg://hydra.conf", "hydra"),276 ("hydra/sweeper/basic.yaml", "pkg://hydra.conf", "hydra"),277 ("hydra/output/default.yaml", "pkg://hydra.conf", "hydra"),278 ("non_config_group_default.yaml", "hydra/test_utils/configs", "test"),279 ("some_config.yaml", "hydra/test_utils/configs", "test"),...

Full Screen

Full Screen

idarest_mixins.py

Source:idarest_mixins.py Github

copy

Full Screen

...62 IdaRestConfiguration._each(args, by)63 return ns.obj64 65 @classmethod66 def load_configuration(self):67 # default68 69 # load configuration from file70 try:71 f = open(self.CFG_FILE, "r")72 self.config.update(json.load(f))73 f.close()74 print("[IdaRestConfiguration::load_configuration] loaded global config file")75 except IOError:76 print("[IdaRestConfiguration::load_configuration] failed to load global config file, using defaults")77 except Exception as e:78 print("[IdaRestConfiguration::load_configuration] failed to load global config file: {0}".format(str(e)))79 80 # use default values if not defined in config file...

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