How to use remove_output_dir method in SeleniumLibrary

Best Python code snippet using SeleniumLibrary

web_services.py

Source:web_services.py Github

copy

Full Screen

...132 for file in filePaths:133 z.write(file)134 zip_file.seek(0)135 print('{} file is created successfully!'.format(zip_filepath))136 self.remove_output_dir(output_path)137 return zip_file, zip_filepath138 def retrieve_file_paths(self, dir_name):139 # setup file paths variable140 file_paths = []141 # Read all directory, subdirectories and file lists142 for root, directories, files in os.walk(dir_name):143 for filename in files:144 # Create the full filepath by using os module.145 file_path = os.path.join(root, filename)146 file_paths.append(file_path)147 print("Filepaths:")148 print(file_paths)149 # return all paths150 return file_paths151 def remove_output_dir(self, output_path):152 shutil.rmtree(output_path)153 def remove_zip_file(self, zip_filepath, output_dir):154 os.remove(zip_filepath)...

Full Screen

Full Screen

multinest_sampler.py

Source:multinest_sampler.py Github

copy

Full Screen

1__author__ = 'aymgal'2import os3import json4import shutil5import numpy as np6from lenstronomy.Sampling.Samplers.base_nested_sampler import NestedSampler7import lenstronomy.Util.sampling_util as utils8__all__ = ['MultiNestSampler']9class MultiNestSampler(NestedSampler):10 """11 Wrapper for nested sampling algorithm MultInest by F. Feroz & M. Hobson12 papers : arXiv:0704.3704, arXiv:0809.3437, arXiv:1306.214413 pymultinest doc : https://johannesbuchner.github.io/PyMultiNest/pymultinest.html14 """15 def __init__(self, likelihood_module, prior_type='uniform', 16 prior_means=None, prior_sigmas=None, width_scale=1, sigma_scale=1,17 output_dir=None, output_basename='-',18 remove_output_dir=False, use_mpi=False):19 """20 :param likelihood_module: likelihood_module like in likelihood.py (should be callable)21 :param prior_type: 'uniform' of 'gaussian', for converting the unit hypercube to param cube22 :param prior_means: if prior_type is 'gaussian', mean for each param23 :param prior_sigmas: if prior_type is 'gaussian', std dev for each param24 :param width_scale: scale the widths of the parameters space by this factor25 :param sigma_scale: if prior_type is 'gaussian', scale the gaussian sigma by this factor26 :param output_dir: name of the folder that will contain output files27 :param output_basename: prefix for output files28 :param remove_output_dir: remove the output_dir folder after completion29 :param use_mpi: flag directly passed to MultInest sampler (NOT TESTED)30 """31 self._check_install()32 super(MultiNestSampler, self).__init__(likelihood_module, prior_type, 33 prior_means, prior_sigmas,34 width_scale, sigma_scale)35 # here we assume number of dimensons = number of parameters36 self.n_params = self.n_dims37 if output_dir is None:38 self._output_dir = 'multinest_out_default'39 else:40 self._output_dir = output_dir41 self._is_master = True42 self._use_mpi = use_mpi43 if self._use_mpi:44 from mpi4py import MPI45 self._comm = MPI.COMM_WORLD46 if self._comm.Get_rank() != 0:47 self._is_master = False48 else:49 self._comm = None50 if self._is_master:51 if os.path.exists(self._output_dir):52 shutil.rmtree(self._output_dir, ignore_errors=True)53 os.mkdir(self._output_dir)54 self.files_basename = os.path.join(self._output_dir, output_basename)55 # required for analysis : save parameter names in json file56 if self._is_master:57 with open(self.files_basename + 'params.json', 'w') as file:58 json.dump(self.param_names, file, indent=2)59 self._rm_output = remove_output_dir60 self._has_warned = False61 def prior(self, cube, ndim, nparams):62 """63 compute the mapping between the unit cube and parameter cube (in-place)64 :param cube: unit hypercube, sampled by the algorithm65 :param ndim: number of sampled parameters66 :param nparams: total number of parameters67 """68 cube_py = self._multinest2python(cube, ndim)69 if self.prior_type == 'gaussian':70 utils.cube2args_gaussian(cube_py, self.lowers, self.uppers, 71 self.means, self.sigmas, self.n_dims)72 elif self.prior_type == 'uniform':73 utils.cube2args_uniform(cube_py, self.lowers, self.uppers, self.n_dims)74 for i in range(self.n_dims):75 cube[i] = cube_py[i]76 def log_likelihood(self, args, ndim, nparams):77 """78 compute the log-likelihood given list of parameters79 :param args: parameter values80 :param ndim: number of sampled parameters81 :param nparams: total number of parameters82 :return: log-likelihood (from the likelihood module)83 """84 args_py = self._multinest2python(args, ndim)85 logL = self._ll(args_py)86 if not np.isfinite(logL):87 if not self._has_warned:88 print("WARNING : logL is not finite : return very low value instead")89 logL = -1e1590 self._has_warned = True91 return float(logL)92 def run(self, kwargs_run):93 """94 run the MultiNest nested sampler95 see https://johannesbuchner.github.io/PyMultiNest/pymultinest.html for content of kwargs_run96 :param kwargs_run: kwargs directly passed to pymultinest.run97 :return: samples, means, logZ, logZ_err, logL, stats98 """99 print("prior type :", self.prior_type)100 print("parameter names :", self.param_names)101 102 if self._pymultinest_installed:103 self._pymultinest.run(self.log_likelihood, self.prior, self.n_dims,104 outputfiles_basename=self.files_basename,105 resume=False, verbose=True,106 init_MPI=self._use_mpi, **kwargs_run)107 analyzer = self._Analyzer(self.n_dims, outputfiles_basename=self.files_basename)108 samples = analyzer.get_equal_weighted_posterior()[:, :-1]109 data = analyzer.get_data() # gets data from the *.txt output file110 stats = analyzer.get_stats()111 else:112 # in case MultiNest was not compiled properly, for unit tests113 samples = np.zeros((1, self.n_dims))114 data = np.zeros((self.n_dims, 3))115 stats = {116 'global evidence': np.zeros(self.n_dims),117 'global evidence error': np.zeros(self.n_dims),118 'modes': [{'mean': np.zeros(self.n_dims)}]119 }120 logL = -0.5 * data[:, 1] # since the second data column is -2*logL121 logZ = stats['global evidence']122 logZ_err = stats['global evidence error']123 means = stats['modes'][0]['mean'] # or better to use stats['marginals'][:]['median'] ???124 print("MultiNest output files have been saved to {}*"125 .format(self.files_basename))126 if self._rm_output and self._is_master:127 shutil.rmtree(self._output_dir, ignore_errors=True)128 print("MultiNest output directory removed")129 130 return samples, means, logZ, logZ_err, logL, stats131 def _multinest2python(self, multinest_list, num_dims):132 """convert ctypes list to standard python list"""133 python_list = []134 for i in range(num_dims):135 python_list.append(multinest_list[i])136 return python_list137 def _check_install(self):138 try:139 import pymultinest140 from pymultinest.analyse import Analyzer141 except:142 print("Warning : MultiNest/pymultinest not properly installed (results might be unexpected). \143 You can get it from : https://johannesbuchner.github.io/PyMultiNest/pymultinest.html")144 self._pymultinest_installed = False145 else:146 self._pymultinest_installed = True147 self._pymultinest = pymultinest...

Full Screen

Full Screen

smrf_test_case.py

Source:smrf_test_case.py Github

copy

Full Screen

...59 cls.create_output_dir()60 cls.configure()61 @classmethod62 def tearDownClass(cls):63 cls.remove_output_dir()64 delattr(cls, 'output_dir')65 @classmethod66 def create_output_dir(cls):67 folder = os.path.join(cls._base_config.cfg['output']['out_location'])68 # Remove any potential files to ensure fresh run69 if os.path.isdir(folder):70 shutil.rmtree(folder)71 os.makedirs(folder)72 cls.output_dir = Path(folder)73 @classmethod74 def remove_output_dir(cls):75 if hasattr(cls, 'output_dir') and \76 os.path.exists(cls.output_dir):77 shutil.rmtree(cls.output_dir)78 @classmethod79 def thread_config(cls):80 config = cls.base_config_copy()81 config.raw_cfg['system'].update(cls.THREAD_CONFIG)82 config.apply_recipes()83 config = cast_all_variables(config, config.mcfg)84 return config85 @staticmethod86 def can_i_run_smrf(config):87 """88 Test whether a config is possible to run...

Full Screen

Full Screen

lakes_test_case.py

Source:lakes_test_case.py Github

copy

Full Screen

...27 cls.load_base_config()28 cls.create_output_dir()29 @classmethod30 def tearDownClass(cls):31 cls.remove_output_dir()32 def tearDown(self):33 logging.shutdown()34 @classmethod35 def create_output_dir(cls):36 folder = os.path.join(37 cls._base_config.cfg['generate_topo']['output_folder'])38 # Remove any potential files to ensure fresh run39 if os.path.isdir(folder):40 shutil.rmtree(folder)41 os.makedirs(folder)42 cls.output_dir = Path(folder)43 @classmethod44 def remove_output_dir(cls):45 if hasattr(cls, 'output_dir') and \46 os.path.exists(cls.output_dir):47 shutil.rmtree(cls.output_dir)48 @staticmethod49 def assert_gold_equal(gold, not_gold, error_msg):50 """Compare two arrays51 Arguments:52 gold {array} -- gold array53 not_gold {array} -- not gold array54 error_msg {str} -- error message to display55 """56 if os.getenv('NOT_ON_GOLD_HOST') is None:57 try:58 np.testing.assert_array_equal(...

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