Best Python code snippet using molotov_python
test_restore_state.py
Source: test_restore_state.py
1import os2import sys3import unittest4from nose.plugins.attrib import attr5import shutil6import numpy as np7from unittest import mock8from ConfigSpace.hyperparameters import UniformFloatHyperparameter9from smac.configspace import ConfigurationSpace10from smac.smac_cli import SMACCLI11from smac.scenario.scenario import Scenario12from smac.facade.smac_facade import SMAC13from smac.optimizer.smbo import SMBO14from smac.stats.stats import Stats15class TestSMACCLI(unittest.TestCase):16 def setUp(self):17 base_directory = os.path.split(__file__)[0]18 base_directory = os.path.abspath(19 os.path.join(base_directory, '..', '..'))20 self.current_dir = os.getcwd()21 os.chdir(base_directory)22 output_one_dir = "test/test_files/test_restore_state" # From scenario_one.txt23 self.output_one = output_one_dir + "/run_1"24 output_two_dir = "test/test_files/test_restored_state" # From scenario_two.txt25 self.output_two = output_two_dir + "/run_1"26 self.smaccli = SMACCLI()27 self.scenario_one = "test/test_files/restore_scenario_one.txt"28 self.scenario_two = "test/test_files/restore_scenario_two.txt"29 self.output_dirs = [output_one_dir, output_two_dir]30 def tearDown(self):31 for output_dir in self.output_dirs:32 if output_dir:33 shutil.rmtree(output_dir, ignore_errors=True)34 #pass35 os.chdir(self.current_dir)36 @attr('slow')37 def test_run_and_restore(self):38 """39 Testing basic restore functionality.40 """41 # Run for 5 algo-calls42 testargs = ["python", "scripts/smac", "--scenario_file",43 self.scenario_one, "--verbose", "DEBUG"]44 self.smaccli.main_cli(testargs[2:])45 # Increase limit and run for 10 (so 5 more) by using restore_state46 testargs = ["python", "scripts/smac", "--restore_state",47 self.output_one, "--scenario_file",48 self.scenario_two, "--verbose", "DEBUG"]49 self.smaccli.main_cli(testargs[2:])50 def test_missing_dir(self):51 """52 Testing error if dir is missing.53 """54 testargs = ["python", "scripts/smac", "--restore_state",55 "nonsense_test_dir", "--scenario_file",56 self.scenario_two, "--verbose", "DEBUG"]57 self.assertRaises(FileNotFoundError, lambda: self.smaccli.main_cli(testargs[2:]))58 def test_illegal_input(self):59 """60 Testing illegal input in smbo61 """62 cs = ConfigurationSpace()63 cs.add_hyperparameter(UniformFloatHyperparameter('test', 1, 10, 5))64 scen = Scenario({'run_obj': 'quality', 'cs': cs})65 stats = Stats(scen)66 # Recorded runs but no incumbent.67 stats.ta_runs = 1068 smac = SMAC(scen, stats=stats, rng=np.random.RandomState(42))69 self.output_dirs.append(scen.output_dir)70 self.assertRaises(ValueError, smac.optimize)71 # Incumbent but no recoreded runs.72 incumbent = cs.get_default_configuration()73 smac = SMAC(scen, restore_incumbent=incumbent,74 rng=np.random.RandomState(42))75 self.assertRaises(ValueError, smac.optimize)76 @attr('slow')77 def test_same_dir(self):78 """79 Testing possible error using same dir for restore80 """81 # Run for 5 algo-calls82 testargs = ["python", "scripts/smac", "--scenario",83 self.scenario_one, "--verbose", "DEBUG"]84 self.smaccli.main_cli(testargs[2:])85 # Increase limit and run for 10 (so 5 more) by using restore_state86 testargs = ["python", "scripts/smac", "--restore_state",87 self.output_one, "--scenario",88 self.scenario_two, "--verbose", "DEBUG"]89 # TODO: fix90 try:91 self.smaccli.main_cli(testargs[2:])92 except FileNotFoundError:93 pass94 self.assertTrue(os.path.exists(self.output_one))95 self.assertFalse(os.path.exists(self.output_one + '.OLD'))96 self.assertTrue(os.path.exists(self.output_two))...
scenario_two.py
Source: scenario_two.py
...16from scheduler import scheduler17from simulation import run_scenario18# Scenario 2: Same as scenario 1, but with server failure and19# master election at T=120.20def scenario_two(reporter):21 job = scenario_one(reporter)22 scheduler.add_relative(120, lambda: job.lose_master())23 scheduler.add_relative(140, lambda: job.trigger_master_election())24 reporter.set_filename('scenario_two')25if __name__ == '__main__':...
i5scenarios.py
Source: i5scenarios.py
...15# res = await session.get('http://localhost:5000/api').json()16# assert res['Hello'] == 'World!'17# print('#'*10, res)18@scenario(30)19async def scenario_two(session):20 somedata = json.dumps({'OK': 1})21 async with session.post(_API, data=somedata) as resp:22 assert resp.status == 20023# @scenario(30)24# async def scenario_two(session):25# somedata = json.dumps({'OK': 1})26# res = await session.post('http://localhost:5000/api', data=somedata)...
Check out the latest blogs from LambdaTest on this topic:
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
The best agile teams are built from people who work together as one unit, where each team member has both the technical and the personal skills to allow the team to become self-organized, cross-functional, and self-motivated. These are all big words that I hear in almost every agile project. Still, the criteria to make a fantastic agile team are practically impossible to achieve without one major factor: motivation towards a common goal.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.
With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.
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!!