How to use _load_file method in molecule

Best Python code snippet using molecule_python

test_files.py

Source:test_files.py Github

copy

Full Screen

...16from ruamel.yaml.error import YAMLError17import elective18def test_load_toml_file_no_file():19 """Should handle no file."""20 actual = elective.FileConfiguration._load_file(21 fn="",22 raise_on_error=False,23 )24 expected = {}25 assert actual == expected26 with pytest.raises(elective.ElectiveFileLoadingError):27 elective.FileConfiguration._load_file(28 fn="",29 )30def test_load_toml_file_bad_file(fs):31 """Should handle a bad file."""32 # Need a fake file here.33 fn = "config.txt"34 fs.create_file(fn)35 with open(fn, "w") as file:36 file.write("TOML sucks")37 actual = elective.FileConfiguration._load_file(38 fn=fn,39 raise_on_error=False,40 )41 expected = {}42 assert actual == expected43 with pytest.raises(elective.ElectiveFileLoadingError):44 elective.FileConfiguration._load_file(fn)45def test_load_toml_file_good_file(fs):46 """Should handle good files."""47 # Need a fake file here.48 fn = "config.txt"49 fs.create_file(fn)50 with open(fn, "w") as file:51 file.write("[option]\n\ntoml = 'is cool'\n")52 actual = elective.FileConfiguration._load_file(fn)53 expected = {54 "option": {55 "toml": "is cool",56 },57 }58 assert actual == expected59 fn = "config2.txt"60 fs.create_file(fn)61 with open(fn, "w") as file:62 file.write(63 """\64[option]65toml = 'is cool'66[tool]67[tool.option]68yaml = 'is not cool'69"""70 )71 actual = elective.FileConfiguration._load_file(fn, section="[tool.option]")72 expected = {73 "yaml": "is not cool",74 }75 assert actual == expected76def test_load_json_file_no_file():77 """Should handle no file."""78 actual = elective.FileConfiguration._load_file(79 "",80 loader=json.load,81 decode_exc=json.JSONDecodeError,82 raise_on_error=False,83 )84 expected = {}85 assert actual == expected86 with pytest.raises(elective.ElectiveFileLoadingError):87 elective.FileConfiguration._load_file(88 "",89 loader=json.load,90 decode_exc=json.JSONDecodeError,91 )92def test_load_json_file_bad_file(fs):93 """Should handle a bad file."""94 # Need a fake file here.95 fn = "config.txt"96 fs.create_file(fn)97 with open(fn, "w") as file:98 file.write("JSON sucks")99 actual = elective.FileConfiguration._load_file(100 fn,101 loader=json.load,102 decode_exc=json.JSONDecodeError,103 raise_on_error=False,104 )105 expected = {}106 assert actual == expected107 with pytest.raises(elective.ElectiveFileLoadingError):108 elective.FileConfiguration._load_file(109 "",110 loader=json.load,111 decode_exc=json.JSONDecodeError,112 )113def test_load_json_file_good_file(fs):114 """Should handle good files."""115 # Need a fake file here.116 fn = "config.txt"117 fs.create_file(fn)118 with open(fn, "w") as file:119 file.write('{"option": {\n "json": "is cool"\n }\n}\n')120 actual = elective.FileConfiguration._load_file(121 fn,122 loader=json.load,123 decode_exc=json.JSONDecodeError,124 )125 expected = {126 "option": {127 "json": "is cool",128 },129 }130 assert actual == expected131 fn = "config2.txt"132 fs.create_file(fn)133 with open(fn, "w") as file:134 file.write(135 """\136{137 "option": {138 "json": "is cool"139 },140 "tool": {141 "option": {142 "yaml": "is not cool"143 }144 }145}146"""147 )148 actual = elective.FileConfiguration._load_file(149 fn,150 loader=json.load,151 decode_exc=json.JSONDecodeError,152 section="[tool.option]",153 )154 expected = {155 "yaml": "is not cool",156 }157 assert actual == expected158def test_load_bespon_file_no_file():159 """Should handle no file."""160 actual = elective.FileConfiguration._load_file(161 "",162 loader=bespon.load,163 decode_exc=bespon.erring.DecodingException,164 raise_on_error=False,165 )166 expected = {}167 assert actual == expected168 with pytest.raises(elective.ElectiveFileLoadingError):169 elective.FileConfiguration._load_file(170 "",171 loader=bespon.load,172 decode_exc=bespon.erring.DecodingException,173 )174def test_load_bespon_file_bad_file(fs):175 """Should handle a bad file."""176 # Need a fake file here.177 fn = "config.txt"178 fs.create_file(fn)179 with open(fn, "w") as file:180 file.write("BespON sucks")181 actual = elective.FileConfiguration._load_file(182 fn,183 loader=bespon.load,184 decode_exc=bespon.erring.DecodingException,185 raise_on_error=False,186 )187 expected = {}188 assert actual == expected189 with pytest.raises(elective.ElectiveFileLoadingError):190 elective.FileConfiguration._load_file(191 fn,192 loader=bespon.load,193 decode_exc=bespon.erring.DecodingException,194 )195def test_load_bespon_file_good_file(fs):196 """Should handle good files."""197 # Need a fake file here.198 fn = "config.txt"199 fs.create_file(fn)200 content = r"""option =201 bespon = "is cool"202 """203 with open(fn, "w") as file:204 file.write(content)205 actual = elective.FileConfiguration._load_file(206 fn,207 loader=bespon.load,208 decode_exc=bespon.erring.DecodingException,209 )210 expected = {211 "option": {212 "bespon": "is cool",213 },214 }215 assert actual == expected216 fn = "config2.txt"217 fs.create_file(fn)218 content = """\219 option =220 bespon = "is cool"221 tool =222 option =223 yaml = "is not cool"224 """225 with open(fn, "w") as file:226 file.write(content)227 actual = elective.FileConfiguration._load_file(228 fn,229 loader=bespon.load,230 decode_exc=bespon.erring.DecodingException,231 section="[tool.option]",232 )233 expected = {234 "yaml": "is not cool",235 }236 assert actual == expected237def test_load_yaml_file_no_file():238 """Should handle no file."""239 actual = elective.FileConfiguration._load_file(240 "",241 loader=YAML(typ="safe").load,242 decode_exc=YAMLError,243 raise_on_error=False,244 )245 expected = {}246 assert actual == expected247 with pytest.raises(elective.ElectiveFileLoadingError):248 elective.FileConfiguration._load_file(249 "",250 loader=YAML(typ="safe").load,251 decode_exc=YAMLError,252 )253def test_load_yaml_file_bad_file(fs):254 """Should handle a bad file."""255 # Need a fake file here.256 fn = "config.txt"257 fs.create_file(fn)258 content = """\259 ---260 :261 """262 with open(fn, "w") as file:263 file.write(content)264 actual = elective.FileConfiguration._load_file(265 fn,266 loader=YAML(typ="safe").load,267 decode_exc=YAMLError,268 raise_on_error=False,269 )270 expected = {}271 assert actual == expected272 with pytest.raises(elective.ElectiveFileLoadingError):273 elective.FileConfiguration._load_file(274 fn,275 loader=YAML(typ="safe").load,276 decode_exc=YAMLError,277 )278def test_load_yaml_file_good_file(fs):279 """Should handle good files."""280 # Need a fake file here.281 fn = "config.txt"282 fs.create_file(fn)283 content = "---\noption:\n yaml: is cool\n"284 with open(fn, "w") as file:285 file.write(content)286 actual = elective.FileConfiguration._load_file(287 fn,288 loader=YAML(typ="safe").load,289 decode_exc=YAMLError,290 )291 expected = {292 "option": {293 "yaml": "is cool",294 },295 }296 assert actual == expected297 fn = "config2.txt"298 fs.create_file(fn)299 content = "---\noption:\n yaml: is cool\ntool:\n option:\n yaml: is not cool\n"300 with open(fn, "w") as file:301 file.write(content)302 actual = elective.FileConfiguration._load_file(303 fn,304 loader=YAML(typ="safe").load,305 decode_exc=YAMLError,306 section="[tool.option]",307 )308 expected = {309 "yaml": "is not cool",310 }311 assert actual == expected312def test_load(fs):313 """Should load a configuration."""314 # Need a fake file here.315 name = "client"316 toml_fn = f".{name}.toml"...

Full Screen

Full Screen

domains.py

Source:domains.py Github

copy

Full Screen

...18 self.white = set([]) # Ãâ¼ìÓòÃû(²»°üÀ¨outlier)19 self.outlier = set([]) # cdnµÈÓòÃû20 self.train_w = set([]) # ѵÁ·Ê±µÄ°×Ñù±¾21 self.train_b = set([]) # ѵÁ·Ê±µÄºÚÑù±¾22 def _load_file(self,f, dset):23 '''24 @f: file name, ÿÐÐÊÇÒ»¸öÓòÃû(a.com)£¬Ã»ÓÐÆäËüÐÅÏ¢25 @dset: domain set, °ÑÎļþ@fÖеÄÓòÃû¼ÓÈë@dset26 ''' 27 for line in open(f):28 ext = tldextract.extract(line.strip())29 dset.add(".".join(ext[1:]))30 def _load_phishtank(self,dset):31 with open(self.dpath+os.sep+"hosts_phishtank.csv", 'rb') as csvfile:32 reader = csv.reader(csvfile)33 for row in reader:34 ext = tldextract.extract(urlparse(row[1]).netloc)35 # print ".".join(ext[1:])36 dset.add(".".join(ext[1:]))37 def _load_alexa(self,begin=0, end=10000):38 df = pd.read_csv(self.dpath+os.sep+"top-1m.csv", names=['rank', 'domain'], header=None, encoding='utf-8')39 return set(list(df[(df['rank'] <= end) & (df['rank'] >= begin)]['domain']))40 def _load_botnet_r(self): 41 self._load_file(self.dpath+os.sep+"hosts_badzeus.txt", self.botnet_r)42 self._load_file(self.dpath+os.sep+"hosts_spyeye.txt", self.botnet_r)43 self._load_file(self.dpath+os.sep+"hosts_palevo.txt", self.botnet_r)44 self._load_file(self.dpath+os.sep+"hosts_feodo.txt", self.botnet_r)45 self._load_file(self.dpath+os.sep+"ud_black.txt", self.botnet_r)46 def _load_botnet_e(self):47 self._load_file(self.dpath+os.sep+"hosts_badzeus.txt", self.botnet_e)48 self._load_file(self.dpath+os.sep+"hosts_spyeye.txt", self.botnet_e)49 self._load_file(self.dpath+os.sep+"hosts_palevo.txt", self.botnet_e)50 self._load_file(self.dpath+os.sep+"hosts_feodo.txt", self.botnet_e)51 self._load_file(self.dpath+os.sep+"hosts_cybercrime.txt", self.botnet_e)52 53 def _load_malware(self):54 self._load_file(self.dpath+os.sep+"hosts_badzeus.txt", self.malware)55 self._load_file(self.dpath+os.sep+"hosts_spyeye.txt", self.malware)56 self._load_file(self.dpath+os.sep+"hosts_palevo.txt", self.malware)57 self._load_file(self.dpath+os.sep+"hosts_feodo.txt", self.malware)58 self._load_file(self.dpath+os.sep+"hosts_cybercrime.txt", self.malware)59 self._load_file(self.dpath+os.sep+"hosts_malwaredomains.txt", self.malware)60 self._load_file(self.dpath+os.sep+"hosts_malwaredomainlist.txt", self.malware)61 self._load_file(self.dpath+os.sep+"hosts_hphosts.txt", self.malware)62 self._load_phishtank(self.malware)63 def _load_outlier(self):64 self._load_file(self.dpath+os.sep+"domain_whitelist.txt", self.outlier)65 self._load_file(self.dpath+os.sep+"cdn.txt", self.outlier)66 self._load_file(self.dpath+os.sep+"cdn_new.txt", self.outlier) 67 def _load_white(self):68 w = self._load_alexa(self.alexa_w[0],self.alexa_w[1])69 self.white |= w70 71 def _load_train_w(self):72 w = self._load_alexa(self.alexa_t[0],self.alexa_t[1])73 self.train_w |= w74 def _info(self):75 logger = logging.getLogger("ffd")76 logger.info('domains._info, domains load from data files: ')77 logger.info("%10s : %d"%('botnet_r',len(self.botnet_r)))78 logger.info("%10s : %d"%('botnet_e',len(self.botnet_e)))79 logger.info("%10s : %d"%('malware',len(self.malware)))80 logger.info("%10s : %d"%('mal2bot',len(self.mal2bot)))...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...13 phi_[phi_ < 0.] += 2*np.pi14 return psi_, phi_1516# Load all variable in a pickle file17def _load_file(name):18 def __load_variable(files = []):19 while True:20 try:21 files.append(pickle.load(f))22 except:23 return files24 with open(name, 'rb') as f:25 files = __load_variable()26 return files2728# Group down together the entired dataset in predictions and covariates29def _save_file(X_, name):30 with open(name, 'wb') as f:31 pickle.dump(X_, f)32 print(name)3334# Get MPI node information35def _get_node_info(verbose = False):36 comm = MPI.COMM_WORLD37 size = comm.Get_size()38 rank = comm.Get_rank()39 name = MPI.Get_processor_name()40 if verbose:41 print('>> MPI: Name: {} Rank: {} Size: {}'.format(name, rank, size) )42 return int(rank), int(size), comm4344# Define a euclidian frame of coordenate s45def _euclidian_coordiantes(N_x, N_y):46 return np.meshgrid(np.linspace(0, N_x - 1, N_x), np.linspace(0, N_y - 1, N_y))4748# Path names and software directories49def _load_segm_models(segm_models_folder):5051 # Generative Models52 nbc_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'nbc_030.pkl') )53 kms_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'kms_021.pkl') )54 gmm_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'gmm_030.pkl') )55 gda_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'gda_032.pkl') )5657 # Discriminative Models58 rrc_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'rrc_131.pkl') )59 svc_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'svc_130.pkl') )60 gpc_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'gpc_130.pkl') )6162 # MRF Models63 mrf_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'mrf_132.pkl') )64 icm_mrf_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'icm-mrf_121.pkl') )65 sa_mrf_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'sa-mrf_132.pkl') )66 sa_icm_mrf_ = _load_file(name = '{}/{}'.format(segm_models_folder, r'sa-icm-mrf_221.pkl') )6768 names_ = [r'NBC', r'k-means', r'GMM', r'GDA', r'RRC', r'SVC', r'GPC', r'MRF', r'ICM-MRF']69 models_ = [nbc_, kms_, gmm_, gda_, rrc_, svc_, gpc_, mrf_, icm_mrf_]70 return names_, models_71 ...

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