Best Python code snippet using lemoncheesecake
reducer.py
Source:reducer.py
1import argparse2import random3import sys4random.seed(0)5# Take a list of files of the format loop_NAME_Number.c6# and produce a deterministic, reduced list of those7# files where each NAME is represented proportionally8# (each NAME) is a benchmark suite.9def get_name(f):10 try:11 nam = f.split('_')[1]12 return nam13 except:14 # For backwards compatability --- previous versions15 # did not distinguish by suite.16 print("Warning: no benchmark suite found", file=sys.stderr)17 return ""18if __name__ == "__main__":19 parser = argparse.ArgumentParser()20 # Two modes --- either reduce to a particular fraction of benchmarks or21 # to a praticular number of benchmarks22 parser.add_argument('--rate', dest="reduction_rate", type=float, default=None)23 parser.add_argument('--number', dest='number', type=int, default=None)24 parser.add_argument("files", nargs='+')25 args = parser.parse_args()26 by_suite = {}27 # Sort before shuffle to make this deterministic regardless of input order28 for f in sorted(args.files):29 name = get_name(f) # Get benchmark suite name30 if name in by_suite:31 by_suite[name].append(f)32 else:33 by_suite[name] = [f]34 # Now reduce -- keetp at least one in each to make35 # the other scirpts easier.36 end_suite = {}37 for n in by_suite:38 if args.reduction_rate:39 new_num = int(len(by_suite[n]) * args.reduction_rate)40 elif args.number:41 # Divy up equally between architectures.42 new_num = int(args.number // len(by_suite))43 if new_num > len(by_suite[n]):44 # Can't go beyond the end of the benchmark suite however.45 # We choose not to make this up --- this is a fuzzy46 # tool to help reduce the computation power required :)47 new_num = len(by_suite[n])48 else:49 print ("Must have one of number or reduction rate set")50 assert False # Need to have one51 if new_num == 0:52 new_num = 153 54 # Random, but repeatable shuffle.55 random.shuffle(by_suite[n])56 end_suite[n] = by_suite[n][:new_num]57 # Print out the benchmark suites58 for n in end_suite:59 for e in end_suite[n]:...
emitter_test.py
Source:emitter_test.py
...36 def test_start_suite_is_ignored_if_not_persistent(self):37 self.emitter = Emitter(suiteId, targetHost, False)38 self.emitter.start_suite("start_suite", self.get_full_dict())39 # if a call was made, we would get an connection error here40 def test_end_suite(self):41 runId = "2"42 httpretty.register_uri(httpretty.PUT, apiPath + "/" + runId)43 44 self.emitter.runId = runId45 self.emitter.end_suite("end_suite", self.get_full_dict())46 result = httpretty.last_request().parsed_body47 self.assertEqual("2016-12-10T01:02:03.004Z", result['endTime'])48 self.assertEqual(1, len(result))49 def test_end_suite_is_ignored_if_not_persistent(self):50 self.emitter = Emitter(suiteId, targetHost, False)51 self.emitter.end_suite("end_suite", self.get_full_dict())52 # if a call was made, we would get an connection error here 53if __name__ == '__main__':...
CustomListener.py
Source:CustomListener.py
...17 print("start_suite listener called...")18 if not BrowserManager.get_browser():19 BrowserManager.initialize_browser()20 21 def end_suite(self,data, suite):22 print("end_suite listener called...")23 24 25 # def _end_suite(self, name, attrs):26 # print('Suite %s (%s) ending.' % (name, attrs['id']))27 def log_message(self,message):28 '''29 '''30 if message['level'] == 'FAIL':31 fname = "./failed_screenshots/" + self.test_name + ".png"32 logger.info(f'<a href="{fname}"> <i> SCREENSHOT </i></a>', html=True)33 34 def start_test(self,name,attributes):35 '''36 Using hooks to save the test name37 to be used other methods.38 '''39 self.test_name = name...
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!!