How to use test_started method in autotest

Best Python code snippet using autotest_python

unit-tests.py

Source:unit-tests.py Github

copy

Full Screen

1from scraper import Scraper2from colorsofitaly import ColorsOfItaly3from time import time4from string import printable5# terminal coloured text6def red(text):7 return f"\x1b[1m\x1b[31m{text}\x1b[0m"8def green(text):9 return f"\x1b[1m\x1b[32m{text}\x1b[0m"10def yellow(text):11 return f"\x1b[1m\x1b[33m{text}\x1b[0m"12def white(text):13 return f"\x1b[1m\x1b[37m{text}\x1b[0m"14# Return real (printable) length of string15def rLen(text):16 return len("".join(s for s in text if s in printable))17def main():18 global_started = time()19 failed = False20 width = 5021 result = "done"22 print(yellow("Starting tests."))23 incipit = "Instantiating scraper... "24 print(incipit, end="", flush=True)25 try:26 test_started = time()27 s = Scraper()28 elapsed = round((time() - test_started) * 1000, 2)29 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"30 spacing = (width - rLen(incipit) -31 rLen(result))32 print(result, spacing * " ", info, sep="")33 except Exception as e:34 spacing = width - rLen(incipit)35 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")36 return37 incipit = "Instantiating colors of italy... "38 print(incipit, end="", flush=True)39 try:40 test_started = time()41 c = ColorsOfItaly()42 elapsed = round((time() - test_started) * 1000, 2)43 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"44 spacing = (width - rLen(incipit) -45 rLen(result))46 print(result, spacing * " ", info, sep="")47 except Exception as e:48 spacing = width - rLen(incipit)49 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")50 return51 # test methods52 total = 053 passed = 054 print()55 print(yellow("Starting methods test."))56 incipit = "Scraping history... "57 print(incipit, end="", flush=True)58 try:59 total += 160 test_started = time()61 s.scrapeHistory()62 elapsed = round((time() - test_started) * 1000, 2)63 passed += 164 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"65 spacing = (width - rLen(incipit) -66 rLen(result))67 print(result, spacing * " ", info, sep="")68 except Exception as e:69 spacing = width - rLen(incipit)70 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")71 incipit = "Scraping data... "72 print(incipit, end="", flush=True)73 try:74 total += 175 test_started = time()76 s.scrapeData()77 elapsed = round((time() - test_started) * 1000, 2)78 passed += 179 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"80 spacing = (width - rLen(incipit) -81 rLen(result))82 print(result, spacing * " ", info, sep="")83 except Exception as e:84 spacing = width - rLen(incipit)85 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")86 incipit = "Scraping colors... "87 print(incipit, end="", flush=True)88 try:89 total += 190 test_started = time()91 s.scrapeColors()92 elapsed = round((time() - test_started) * 1000, 2)93 passed += 194 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"95 spacing = (width - rLen(incipit) -96 rLen(result))97 print(result, spacing * " ", info, sep="")98 except Exception as e:99 spacing = width - rLen(incipit)100 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")101 incipit = "Saving data... "102 print(incipit, end="", flush=True)103 try:104 total += 1105 test_started = time()106 s.saveData()107 elapsed = round((time() - test_started) * 1000, 2)108 passed += 1109 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"110 spacing = (width - rLen(incipit) -111 rLen(result))112 print(result, spacing * " ", info, sep="")113 except Exception as e:114 spacing = width - rLen(incipit)115 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")116 percentage = int(passed/total * 100)117 print(yellow(f"Passed: {passed}/{total}"), end=" ", flush=True)118 if percentage < 100:119 print("[", red(f"{percentage}%"), "]", sep="")120 failed = True121 else:122 print("[", green(f"{percentage}%"), "]", sep="")123 # test getters124 total = 0125 passed = 0126 print()127 print(yellow("Starting properties test."))128 incipit = "Getting italy... "129 print(incipit, end="", flush=True)130 try:131 total += 1132 test_started = time()133 _ = s.italy134 elapsed = round((time() - test_started) * 1000, 2)135 passed += 1136 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"137 spacing = (width - rLen(incipit) -138 rLen(result))139 print(result, spacing * " ", info, sep="")140 except Exception as e:141 spacing = width - rLen(incipit)142 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")143 incipit = "Getting territories list... "144 print(incipit, end="", flush=True)145 try:146 total += 1147 test_started = time()148 _ = s.territories_list149 elapsed = round((time() - test_started) * 1000, 2)150 passed += 1151 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"152 spacing = (width - rLen(incipit) -153 rLen(result))154 print(result, spacing * " ", info, sep="")155 except Exception as e:156 spacing = width - rLen(incipit)157 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")158 incipit = "Getting absolute territories... "159 print(incipit, end="", flush=True)160 try:161 total += 1162 test_started = time()163 _ = s.absolute_territories164 elapsed = round((time() - test_started) * 1000, 2)165 passed += 1166 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"167 spacing = (width - rLen(incipit) -168 rLen(result))169 print(result, spacing * " ", info, sep="")170 except Exception as e:171 spacing = width - rLen(incipit)172 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")173 incipit = "Getting variation territories... "174 print(incipit, end="", flush=True)175 try:176 total += 1177 test_started = time()178 _ = s.variation_territories179 elapsed = round((time() - test_started) * 1000, 2)180 passed += 1181 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"182 spacing = (width - rLen(incipit) -183 rLen(result))184 print(result, spacing * " ", info, sep="")185 except Exception as e:186 spacing = width - rLen(incipit)187 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")188 incipit = "Getting categories... "189 print(incipit, end="", flush=True)190 try:191 total += 1192 test_started = time()193 _ = s.categories194 elapsed = round((time() - test_started) * 1000, 2)195 passed += 1196 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"197 spacing = (width - rLen(incipit) -198 rLen(result))199 print(result, spacing * " ", info, sep="")200 except Exception as e:201 spacing = width - rLen(incipit)202 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")203 incipit = "Getting genders... "204 print(incipit, end="", flush=True)205 try:206 total += 1207 test_started = time()208 _ = s.genders209 elapsed = round((time() - test_started) * 1000, 2)210 passed += 1211 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"212 spacing = (width - rLen(incipit) -213 rLen(result))214 print(result, spacing * " ", info, sep="")215 except Exception as e:216 spacing = width - rLen(incipit)217 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")218 incipit = "Getting age ranges... "219 print(incipit, end="", flush=True)220 try:221 total += 1222 test_started = time()223 _ = s.age_ranges224 elapsed = round((time() - test_started) * 1000, 2)225 passed += 1226 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"227 spacing = (width - rLen(incipit) -228 rLen(result))229 print(result, spacing * " ", info, sep="")230 except Exception as e:231 spacing = width - rLen(incipit)232 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")233 incipit = "Getting history... "234 print(incipit, end="", flush=True)235 try:236 total += 1237 test_started = time()238 _ = s.history239 elapsed = round((time() - test_started) * 1000, 2)240 passed += 1241 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"242 spacing = (width - rLen(incipit) -243 rLen(result))244 print(result, spacing * " ", info, sep="")245 except Exception as e:246 spacing = width - rLen(incipit)247 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")248 incipit = "Getting territories color... "249 print(incipit, end="", flush=True)250 try:251 total += 1252 test_started = time()253 _ = s.territories_color254 elapsed = round((time() - test_started) * 1000, 2)255 passed += 1256 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"257 spacing = (width - rLen(incipit) -258 rLen(result))259 print(result, spacing * " ", info, sep="")260 except Exception as e:261 spacing = width - rLen(incipit)262 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")263 incipit = "Getting territories color slim... "264 print(incipit, end="", flush=True)265 try:266 total += 1267 test_started = time()268 _ = s.territories_color_slim269 elapsed = round((time() - test_started) * 1000, 2)270 passed += 1271 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"272 spacing = (width - rLen(incipit) -273 rLen(result))274 print(result, spacing * " ", info, sep="")275 except Exception as e:276 spacing = width - rLen(incipit)277 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")278 incipit = "Getting territories color rgb... "279 print(incipit, end="", flush=True)280 try:281 total += 1282 test_started = time()283 _ = s.territories_color_rgb284 elapsed = round((time() - test_started) * 1000, 2)285 passed += 1286 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"287 spacing = (width - rLen(incipit) -288 rLen(result))289 print(result, spacing * " ", info, sep="")290 except Exception as e:291 spacing = width - rLen(incipit)292 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")293 incipit = "Getting territories color dummy... "294 print(incipit, end="", flush=True)295 try:296 total += 1297 test_started = time()298 _ = s.territories_color_dummy299 elapsed = round((time() - test_started) * 1000, 2)300 passed += 1301 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"302 spacing = (width - rLen(incipit) -303 rLen(result))304 print(result, spacing * " ", info, sep="")305 except Exception as e:306 spacing = width - rLen(incipit)307 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")308 incipit = "Getting territories color map... "309 print(incipit, end="", flush=True)310 try:311 total += 1312 test_started = time()313 _ = s.territories_color_map314 elapsed = round((time() - test_started) * 1000, 2)315 passed += 1316 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"317 spacing = (width - rLen(incipit) -318 rLen(result))319 print(result, spacing * " ", info, sep="")320 except Exception as e:321 spacing = width - rLen(incipit)322 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")323 incipit = "Getting territories percentage map... "324 print(incipit, end="", flush=True)325 try:326 total += 1327 test_started = time()328 _ = s.territories_percentage_map329 elapsed = round((time() - test_started) * 1000, 2)330 passed += 1331 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"332 spacing = (width - rLen(incipit) -333 rLen(result))334 print(result, spacing * " ", info, sep="")335 except Exception as e:336 spacing = width - rLen(incipit)337 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")338 incipit = "Getting vaccine producers... "339 print(incipit, end="", flush=True)340 try:341 total += 1342 test_started = time()343 _ = s.vaccine_producers344 elapsed = round((time() - test_started) * 1000, 2)345 passed += 1346 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"347 spacing = (width - rLen(incipit) -348 rLen(result))349 print(result, spacing * " ", info, sep="")350 except Exception as e:351 spacing = width - rLen(incipit)352 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")353 incipit = "Getting subministrations... "354 print(incipit, end="", flush=True)355 try:356 total += 1357 test_started = time()358 _ = s.subministrations359 elapsed = round((time() - test_started) * 1000, 2)360 passed += 1361 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"362 spacing = (width - rLen(incipit) -363 rLen(result))364 print(result, spacing * " ", info, sep="")365 except Exception as e:366 spacing = width - rLen(incipit)367 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")368 incipit = "Getting ota infos... "369 print(incipit, end="", flush=True)370 try:371 total += 1372 test_started = time()373 _ = c.ota_infos374 elapsed = round((time() - test_started) * 1000, 2)375 passed += 1376 info = f"{green('PASS')} [{green(elapsed)}{green('ms')}]"377 spacing = (width - rLen(incipit) -378 rLen(result))379 print(result, spacing * " ", info, sep="")380 except Exception as e:381 spacing = width - rLen(incipit)382 print(spacing * " ", red("FAIL"), " error: ", red(e), sep="")383 percentage = int(passed/total * 100)384 print(yellow(f"Passed: {passed}/{total}"), end=" ", flush=True)385 if percentage < 100:386 print("[", red(f"{percentage}%"), "]", sep="")387 failed = True388 else:389 print("[", green(f"{percentage}%"), "]", sep="")390 print()391 if failed:392 print(red("TEST FAILED"))393 else:394 global_elapsed = round((time() - global_started) * 1000, 2)395 print(f"{green('TEST PASSED')} [{green(global_elapsed)}{green('ms')}]")396 print()397if __name__ == '__main__':...

Full Screen

Full Screen

test_visitor.py

Source:test_visitor.py Github

copy

Full Screen

1import unittest2from os.path import dirname, join3from robot.result import ExecutionResult4from robot.result.visitor import SuiteVisitor5from robot.utils.asserts import assert_equal6RESULT = ExecutionResult(join(dirname(__file__), 'golden.xml'))7class TestVisitingSuite(unittest.TestCase):8 def test_abstract_visitor(self):9 RESULT.suite.visit(SuiteVisitor())10 RESULT.suite.visit(SuiteVisitor())11 def test_start_suite_can_stop_visiting(self):12 RESULT.suite.visit(StartSuiteStopping())13 def test_start_test_can_stop_visiting(self):14 RESULT.suite.visit(StartTestStopping())15 def test_start_keyword_can_stop_visiting(self):16 RESULT.suite.visit(StartKeywordStopping())17 def test_start_and_end_methods_can_add_items(self):18 suite = RESULT.suite.deepcopy()19 suite.visit(ItemAdder())20 assert_equal(len(suite.tests), len(RESULT.suite.tests) + 2)21 assert_equal(suite.tests[-2].name, 'Added by start_test')22 assert_equal(suite.tests[-1].name, 'Added by end_test')23 assert_equal(len(suite.tests[0].keywords),24 len(RESULT.suite.tests[0].keywords) + 2)25 assert_equal(suite.tests[0].keywords[-2].name, 'Added by start_keyword')26 assert_equal(suite.tests[0].keywords[-1].name, 'Added by end_keyword')27class StartSuiteStopping(SuiteVisitor):28 def start_suite(self, suite):29 return False30 def end_suite(self, suite):31 raise AssertionError32 def start_test(self, test):33 raise AssertionError34 def start_keyword(self, keyword):35 raise AssertionError36class StartTestStopping(SuiteVisitor):37 def __init__(self):38 self.test_started = False39 def start_test(self, test):40 self.test_started = True41 return False42 def end_test(self, test):43 raise AssertionError44 def start_keyword(self, keyword):45 if self.test_started:46 raise AssertionError47class StartKeywordStopping(SuiteVisitor):48 def start_keyword(self, test):49 return False50 def end_keyword(self, test):51 raise AssertionError52 def log_message(self, msg):53 raise AssertionError54class ItemAdder(SuiteVisitor):55 test_to_add = 256 test_started = False57 kw_added = False58 def start_test(self, test):59 if self.test_to_add > 0:60 test.parent.tests.create(name='Added by start_test')61 self.test_to_add -= 162 self.test_started = True63 def end_test(self, test):64 if self.test_to_add > 0:65 test.parent.tests.create(name='Added by end_test')66 self.test_to_add -= 167 self.test_started = False68 def start_keyword(self, keyword):69 if self.test_started and not self.kw_added:70 keyword.parent.keywords.create(kwname='Added by start_keyword')71 self.kw_added = True72 def end_keyword(self, keyword):73 if keyword.name == 'Added by start_keyword':74 keyword.parent.keywords.create(kwname='Added by end_keyword')75if __name__ == '__main__':...

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