Best Python code snippet using localstack_python
base.py
Source:base.py
...10from relationGraph import Relation, RelationGraph, MatrixOfRelationGraph11import numpy as np12from skfusion.fusion import ObjectType, Relation, FusionGraph13__all__ = ['load_dicty', 'load_pharma', 'load_movielens']14def load_source(source_path, delimiter=',', filling_value='0'):15 """Load and return a data source.16 Parameters17 ----------18 delimiter : str, optional (default=',')19 The string used to separate values. By default, comma acts as delimiter.20 filling_value : variable, optional (default='0')21 The value to be used as default when the data are missing.22 Returns23 -------24 data : DataSource25 Dictionary-like object, the interesting attributes are:26 'data', the data to learn, 'obj1_names', the meaning of row objects,27 'obj2_names', the meaning of column objects.28 """29 module_path = dirname(__file__)30 data_file = gzip.open(join(module_path, 'data', source_path))31 row_names = np.array(next(data_file).decode('utf-8').strip().replace(', ', ' ').replace('.,', '.').split(delimiter))32 col_names = np.array(next(data_file).decode('utf-8').strip().replace(', ', ' ').replace('.,', '.').split(delimiter))33 data = np.genfromtxt(data_file, delimiter=delimiter, missing_values=[''],34 filling_values=filling_value)35 return data, row_names, col_names36def load_dicty():37 """Construct fusion graph from molecular biology of Dictyostelium."""38 gene = ObjectType('Gene', 50)39 go_term = ObjectType('GO term', 15)40 exprc = ObjectType('Experimental condition', 5)41 data, rn, cn = load_source(join('dicty', 'dicty.gene_annnotations.csv.gz'))42 ann = Relation(data=data, row_type=gene, col_type=go_term, name='ann',43 row_names=rn, col_names=cn)44 data, rn, cn = load_source(join('dicty', 'dicty.gene_expression.csv.gz'))45 expr = Relation(data=data, row_type=gene, col_type=exprc, name='expr',46 row_names=rn, col_names=cn)47 expr.data = np.log(np.maximum(expr.data, np.finfo(np.float).eps))48 data, rn, cn = load_source(join('dicty', 'dicty.ppi.csv.gz'))49 ppi = Relation(data=data, row_type=gene, col_type=gene, name='ppi',50 row_names=rn, col_names=cn)51 return FusionGraph([ann, expr, ppi])52def load_pharma():53 """Construct fusion graph from the pharmacology domain."""54 action=ObjectType('Action', 5)55 pmid=ObjectType('PMID', 5)56 depositor=ObjectType('Depositor', 5)57 fingerprint=ObjectType('Fingerprint', 20)58 depo_cat=ObjectType('Depositor category', 5)59 chemical=ObjectType('Chemical', 10)60 data, rn, cn = load_source(join('pharma', 'pharma.actions.csv.gz'))61 actions = Relation(data=data, row_type=chemical, col_type=action,62 row_names=rn, col_names=cn)63 data, rn, cn = load_source(join('pharma', 'pharma.pubmed.csv.gz'))64 pubmed = Relation(data=data, row_type=chemical, col_type=pmid,65 row_names=rn, col_names=cn)66 data, rn, cn = load_source(join('pharma', 'pharma.depositors.csv.gz'))67 depositors = Relation(data=data, row_type=chemical, col_type=depositor,68 row_names=rn, col_names=cn)69 data, rn, cn = load_source(join('pharma', 'pharma.fingerprints.csv.gz'))70 fingerprints = Relation(data=data, row_type=chemical, col_type=fingerprint,71 row_names=rn, col_names=cn)72 data, rn, cn = load_source(join('pharma', 'pharma.depo_cats.csv.gz'))73 depo_cats = Relation(data=data, row_type=depositor, col_type=depo_cat,74 row_names=rn, col_names=cn)75 data, rn, cn = load_source(join('pharma', 'pharma.tanimoto.csv.gz'))76 tanimoto = Relation(data=data, row_type=chemical, col_type=chemical,77 row_names=rn, col_names=cn)78 return FusionGraph([actions, pubmed, depositors, fingerprints, depo_cats, tanimoto])79def load_movielens(ratings=True, movie_genres=True, movie_actors=True):80 module_path = join(dirname(__file__), 'data', 'movielens')81 if ratings:82 ratings_data = defaultdict(dict)83 with gzip.open(join(module_path, 'ratings.csv.gz'), 'rt', encoding='utf-8') as f:84 f.readline()85 for line in f:86 line = line.strip().split(',')87 ratings_data[int(line[0])][int(line[1])] = float(line[2])88 else:89 ratings_data = None90 if movie_genres:91 movie_genres_data = {}92 with gzip.open(join(module_path, 'movies.csv.gz'), 'rt', encoding='utf-8') as f:93 f.readline()94 lines = csv.reader(f)95 for line in lines:96 movie_genres_data[int(line[0])] = line[2].split('|')97 else:98 movie_genres_data = None99 if movie_actors:100 movie_actors_data = {}101 with gzip.open(join(module_path, 'actors.csv.gz'), 'rt', encoding='utf-8') as f:102 f.readline()103 lines = csv.reader(f)104 for line in lines:105 movie_actors_data[int(line[0])] = line[2].split('|')106 else:107 movie_actors_data = None108 return ratings_data, movie_genres_data, movie_actors_data109def show_data_dicty():110 data1, rn1, cn1 = load_source(join('dicty', 'dicty.gene_annnotations.csv.gz'))111 data2, rn2, cn2 = load_source(join('dicty', 'dicty.gene_expression.csv.gz'))112 data3, rn3, cn3 = load_source(join('dicty', 'dicty.ppi.csv.gz'))113 print('Gene - GO term')114 print('Data1: ' + str(data1.shape))115 print('Gene - Experiment conditions')116 print('Data2: ' + str(data2.shape))117 print('Gene - Gene')118 print('Data3: ' + str(data3.shape))119 print()120 print('Subset (data1 - data2): ' + str(len(set(rn1) & set(rn2))))121 print('Subset (data1 - data3): ' + str(len(set(rn1) & set(rn3))))122 print('Subset (data2 - data3): ' + str(len(set(rn2) & set(rn3))))123 print('Subset (data1 - data2 - data3): ' + str(len(set(rn1) & set(rn2) & set(rn3))))124def show_data_pharma():125 data1, rn1, cn1 = load_source(join('pharma', 'pharma.actions.csv.gz'))126 data2, rn2, cn2 = load_source(join('pharma', 'pharma.pubmed.csv.gz'))127 data3, rn3, cn3 = load_source(join('pharma', 'pharma.depositors.csv.gz'))128 data4, rn4, cn4 = load_source(join('pharma', 'pharma.fingerprints.csv.gz'))129 data5, rn5, cn5 = load_source(join('pharma', 'pharma.depo_cats.csv.gz'))130 data6, rn6, cn6 = load_source(join('pharma', 'pharma.tanimoto.csv.gz'))131 print("Chemical - Action")132 print('Data1: ' + str(data1.shape))133 print('Chemical - PMID')134 print('Data2: ' + str(data2.shape))135 print('Chemical - Depositor')136 print('Data3: ' + str(data3.shape))137 print('Chemical - Fingerprint')138 print('Data4: ' + str(data4.shape))139 print('Depositor - Depositor cateoory')140 print('Data5: ' + str(data5.shape))141 print('Chemical - chemical')142 print('Data6: ' + str(data6.shape))143 print()144 print('Subset(data1 - data2): ' + str(len(set(rn1) & set(rn2))))...
test_conf.py
Source:test_conf.py
...3import os4from mock import Mock5from thefuck import const6@pytest.fixture7def load_source(mocker):8 return mocker.patch('thefuck.conf.load_source')9def test_settings_defaults(load_source, settings):10 load_source.return_value = object()11 settings.init()12 for key, val in const.DEFAULT_SETTINGS.items():13 assert getattr(settings, key) == val14class TestSettingsFromFile(object):15 def test_from_file(self, load_source, settings):16 load_source.return_value = Mock(rules=['test'],17 wait_command=10,18 require_confirmation=True,19 no_colors=True,20 priority={'vim': 100},21 exclude_rules=['git'])...
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!!