Best Python code snippet using lisa_python
tradefed_test_unittest.py
Source:tradefed_test_unittest.py
...4import common5import os6import unittest7import tradefed_test8def _load_data(filename):9 """Loads the test data of the given file name."""10 with open(os.path.join(os.path.dirname(os.path.realpath(__file__)),11 'tradefed_test_unittest_data', filename), 'r') as f:12 return f.read()13class TradefedTestTest(unittest.TestCase):14 """Unittest for tradefed_test."""15 def test_parse_tradefed_result(self):16 """Test for parse_tradefed_result."""17 waivers = set([18 'android.app.cts.SystemFeaturesTest#testUsbAccessory',19 'android.widget.cts.GridViewTest#testSetNumColumns',20 ])21 # b/35605415 and b/3652062322 # http://pantheon/storage/browser/chromeos-autotest-results/108103986-chromeos-test/23 # CTS: Tradefed may split a module to multiple chunks.24 # Besides, the module name may not end with "TestCases".25 waived, _ = tradefed_test.parse_tradefed_result(26 _load_data('CtsHostsideNetworkTests.txt'),27 waivers=waivers)28 self.assertEquals(0, len(waived))29 # b/3553039430 # http://pantheon/storage/browser/chromeos-autotest-results/108291418-chromeos-test/31 # Crashed, but the automatic retry by tradefed executed the rest.32 waived, _ = tradefed_test.parse_tradefed_result(33 _load_data('CtsMediaTestCases.txt'),34 waivers=waivers)35 self.assertEquals(0, len(waived))36 # b/3553039437 # http://pantheon/storage/browser/chromeos-autotest-results/106540705-chromeos-test/38 # Crashed in the middle, and the device didn't came back.39 waived, _ = tradefed_test.parse_tradefed_result(40 _load_data('CtsSecurityTestCases.txt'),41 waivers=waivers)42 self.assertEquals(0, len(waived))43 # b/3662918744 # http://pantheon/storage/browser/chromeos-autotest-results/108855595-chromeos-test/45 # Crashed in the middle. Tradefed decided not to continue.46 waived, _ = tradefed_test.parse_tradefed_result(47 _load_data('CtsViewTestCases.txt'),48 waivers=waivers)49 self.assertEquals(0, len(waived))50 # b/3637569051 # http://pantheon/storage/browser/chromeos-autotest-results/109040174-chromeos-test/52 # Mixture of real failures and waivers.53 waived, _ = tradefed_test.parse_tradefed_result(54 _load_data('CtsAppTestCases.txt'),55 waivers=waivers)56 self.assertEquals(1, len(waived))57 # ... and the retry of the above failing iteration.58 waived, _ = tradefed_test.parse_tradefed_result(59 _load_data('CtsAppTestCases-retry.txt'),60 waivers=waivers)61 self.assertEquals(1, len(waived))62 # http://pantheon/storage/browser/chromeos-autotest-results/116875512-chromeos-test/63 # When a test case crashed during teardown, tradefed prints the "fail"64 # message twice. Tolerate it and still return an (inconsistent) count.65 waived, _ = tradefed_test.parse_tradefed_result(66 _load_data('CtsWidgetTestCases.txt'),67 waivers=waivers)68 self.assertEquals(1, len(waived))69 # http://pantheon/storage/browser/chromeos-autotest-results/117914707-chromeos-test/70 # When a test case unrecoverably crashed during teardown, tradefed71 # prints the "fail" and failure summary message twice. Tolerate it.72 waived, _ = tradefed_test.parse_tradefed_result(73 _load_data('CtsPrintTestCases.txt'),74 waivers=waivers)75 self.assertEquals(0, len(waived))76 gts_waivers = set([77 ('com.google.android.placement.gts.CoreGmsAppsTest#' +78 'testCoreGmsAppsPreloaded'),79 ('com.google.android.placement.gts.CoreGmsAppsTest#' +80 'testGoogleDuoPreloaded'),81 'com.google.android.placement.gts.UiPlacementTest#testPlayStore'82 ])83 # crbug.com/74811684 # http://pantheon/storage/browser/chromeos-autotest-results/130080763-chromeos-test/85 # 3 ABIS: x86, x86_64, and armeabi-v7a86 waived, _ = tradefed_test.parse_tradefed_result(87 _load_data('GtsPlacementTestCases.txt'),88 waivers=gts_waivers)89 self.assertEquals(9, len(waived))90 # b/6409570291 # http://pantheon/storage/browser/chromeos-autotest-results/130211812-chromeos-test/92 # The result of the last chunk not reported by tradefed.93 # The actual dEQP log is too big, hence the test data here is trimmed.94 waived, _ = tradefed_test.parse_tradefed_result(95 _load_data('CtsDeqpTestCases-trimmed.txt'),96 waivers=waivers)97 self.assertEquals(0, len(waived))98 # b/8016077299 # http://pantheon/storage/browser/chromeos-autotest-results/201962931-kkanchi/100 # The newer tradefed requires different parsing to count waivers.101 waived, _ = tradefed_test.parse_tradefed_result(102 _load_data('CtsAppTestCases_P_simplified.txt'),103 waivers=waivers)104 self.assertEquals(1, len(waived))105 # b/66899135, tradefed may reported inaccuratly with `list results`.106 # Check if summary section shows that the result is inacurrate.107 _, accurate = tradefed_test.parse_tradefed_result(108 _load_data('CtsAppTestCases_P_simplified.txt'),109 waivers=waivers)110 self.assertTrue(accurate)111 _, accurate = tradefed_test.parse_tradefed_result(112 _load_data('CtsDeqpTestCases-trimmed-inaccurate.txt'),113 waivers=waivers)114 self.assertFalse(accurate)115if __name__ == '__main__':...
Preprocessing.py
Source:Preprocessing.py
...9 self.fd = {"train":TRAINFOLD, "test":TESTFOLD}10 self.fl = {"train":TRAINLIST, "test":TESTLIST}11 self.ft = {"train":TRAINFEATURE, "test":TESTFEATURE}12 13 def _load_data(self, file_path, data_type='original'):14 if data_type == 'original':15 data = pd.read_csv(file_path, sep="\s+").iloc[:,0:WINDOW_WIDTH]16 elif data_type == 'features':17 data = pd.read_csv(file_path, sep="\s+")18 return data19 def _choose_status(self, status="train"):20 if status == "train":21 return self.fd["train"], self.fl["train"], self.ft["train"]22 else:23 return self.fd["test"], self.fl["test"], self.ft["test"]24 25 def _get_one_hot(self, label, N):26 size = list(label.size())27 label = label.view(-1) - 128 ones = torch.sparse.torch.eye(N)29 ones = ones.index_select(0, label) 30 size.append(N) 31 return ones.view(*size)32 33 def _concatenate(self, pair, dataX, dataY, amount, random=True):34 actionA = dataX[np.argwhere(dataY==pair[0])[:,0]]35 actionB = dataX[np.argwhere(dataY==pair[1])[:,0]]36 for n in range(amount):37 temp = actionA38 for i in range(len(actionA)):39 if random:40 cut = np.random.randint(0, 128)41 else:42 cut = 6443 selection = np.random.randint(0,len(actionB))44 temp[i,:,cut:]= actionB[selection,:,cut:]45 if n == 0:46 output = temp47 else:48 output = np.concatenate((output,temp), axis=0)49 return len(output), output50 51 def _stack(self, dataX, fl, fd):52 for i in range(1, len(fl)):53 fp = fd + fl[i]54 new = self._load_data(fp)55 if i == 1:56 dataX = np.stack([dataX,new],axis=len(dataX.shape))57 else:58 dataX = np.dstack([dataX,new])59 dataX = np.swapaxes(dataX,1,2)60 return dataX61 62 def original(self, status):63 fd, fl, ft = self._choose_status(status)64 dataX = self._load_data(fd + fl[0])65 dataX = self._stack(dataX, fl, fd)66 dataX = torch.FloatTensor(dataX)67 dataY = torch.LongTensor(np.asarray(self._load_data(ft[1])))68 # dataY = self._get_one_hot(dataY, 6)69 return dataX, dataY70 71 def features(self, status):72 fd, fl, ft = self._choose_status(status)73 dataX = torch.FloatTensor(np.asarray(self._load_data(ft[0], 'features').iloc[:,0:NUM_FEATURES_USED]))74 dataY = torch.LongTensor(np.asarray(self._load_data(ft[1], 'features')))75 return dataX, dataY76 def statistics(self, status):77 fd, fl, ft = self._choose_status(status)78 dataX = np.asarray(self._load_data(ft[0], 'features').iloc[:,0:NUM_FEATURES_USED])79 dataY = np.asarray(self._load_data(ft[1], 'features'))80 return dataX, dataY81 def trans(self, status):82 fd, fl, ft = self._choose_status(status)83 dataX = self._load_data(fd + fl[0])84 dataX = self._stack(dataX, fl, fd)85 dataY = np.asarray(self._load_data(ft[1]).values)86 for i in range(NUM_CLASSES):87 pair = PAIR[i+1]88 num, concatenation = self._concatenate(pair, dataX, dataY, 2, False)89 if i == 0:90 outputX = torch.FloatTensor(concatenation)91 outputY = torch.LongTensor(np.repeat(i+1, num))92 else:93 outputX = torch.cat([outputX, torch.FloatTensor(concatenation)])94 outputY = torch.cat([outputY, torch.LongTensor(np.repeat(i+1, num))])95 return outputX, outputY96if __name__ == "__main__":97 prepare_data = Preprocessing()98 training_data_X, training_data_y = prepare_data.original("train")99 testing_data_X, testing_data_y = prepare_data.original("test")...
data.py
Source:data.py
1import json2import os3def _load_data(filename):4 with open(5 os.path.join(os.path.dirname(__file__), '_data', filename)6 ) as contents:7 if filename.endswith('.json'):8 return json.load(contents)9 return [line.strip() for line in contents.readlines()]10def find_canonical(item, graph, key):11 if item['meta']['canonical']:12 return key, item['names']['en-GB']13 return find_canonical(14 graph[item['edges']['from'][0]],15 graph,16 key,17 )18# Copied from19# https://github.com/alphagov/govuk-country-and-territory-autocomplete20# /blob/b61091a502983fd2a77b3cdb5f94a604412eb09321# /dist/location-autocomplete-graph.json22_graph = _load_data('location-autocomplete-graph.json')23UK = 'United Kingdom'24ENDED_COUNTRIES = _load_data('ended-countries.json')25ADDITIONAL_SYNONYMS = list(_load_data('synonyms.json').items())26WELSH_NAMES = list(_load_data('welsh-names.json').items())27_UK_ISLANDS_LIST = _load_data('uk-islands.txt')28_EUROPEAN_ISLANDS_LIST = _load_data('european-islands.txt')29CURRENT_AND_ENDED_COUNTRIES_AND_TERRITORIES = [30 find_canonical(item, _graph, item['names']['en-GB'])31 for item in _graph.values()32]33COUNTRIES_AND_TERRITORIES = []34for synonym, canonical in CURRENT_AND_ENDED_COUNTRIES_AND_TERRITORIES:35 if canonical in _UK_ISLANDS_LIST:36 COUNTRIES_AND_TERRITORIES.append((synonym, UK))37 elif canonical in ENDED_COUNTRIES:38 succeeding_country = ENDED_COUNTRIES[canonical]39 if succeeding_country:40 COUNTRIES_AND_TERRITORIES.append((synonym, succeeding_country))41 COUNTRIES_AND_TERRITORIES.append((canonical, succeeding_country))42 else:43 COUNTRIES_AND_TERRITORIES.append((synonym, canonical))44UK_ISLANDS = [45 (synonym, UK) for synonym in _UK_ISLANDS_LIST46]47EUROPEAN_ISLANDS = [48 (synonym, synonym) for synonym in _EUROPEAN_ISLANDS_LIST49]50# Copied from https://www.royalmail.com/international-zones#europe51# Modified to use the canonical names for countries where incorrect52ROYAL_MAIL_EUROPEAN = _load_data('europe.txt')53class Postage:54 UK = 'united-kingdom'55 EUROPE = 'europe'...
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!!