Best Python code snippet using sure_python
ctokens.py
Source: ctokens.py
2from util import just_tokenize, make_tests, make_fails, TSTRING, STRING, SSTRING, ID, WHITE, NUMBER, INT, HEX, CCOMMENT, CMCOMMENT, PYCOMMENT, NEWLINE, ANY3def make_single(tok, *tests):4 fn = just_tokenize(tok, WHITE)5 return make_tests(globals(), tok.__name__, fn, tests)6def fail_single(tok, *tests):7 fn = just_tokenize(tok)8 return make_fails(globals(), tok.__name__, fn, tests)9# string10make_single(STRING,11 ('', 0),12 ('"one"', 1),13 ('"lo' + 'o'*1000 + 'ng"', 1),14 ('"many"'*20, 20))15fail_single(STRING,16 '"',17 '"hello',18 '"one""and',19 '"lo' + 'o'*1000)20# sstring21make_single(SSTRING,22 ('', 0),23 ("'one'", 1),24 ('\'lo' + 'o'*1000 + 'ng\'', 1),25 ('\'many\''*20, 20))26fail_single(SSTRING,27 "'",28 "'one",29 "'lo"+'o'*1000,30 "'many'"*20+"'")31# tstring32make_single(TSTRING,33 ('', 0),34 ('""""""', 1),35 ('"""one line"""', 1),36 ('"""two\nlines"""', 1),37 ('"""lots'+'\n'*100+'of lines"""', 1),38 ('"""many"""'*20, 20),39 ("''''''", 1),40 ("'''one line'''", 1),41 ("'''two\nlines'''", 1),42 ("'''lots"+'\n'*100+"of lines'''", 1),43 ("'''many'''"*20, 20))44fail_single(TSTRING,45 '"',46 '"""""',47 '"""',48 '"""start',49 '"""not full"',50 '"""partial""')51# ID52make_single(ID,53 ('', 0),54 ('o', 1),55 ('one', 1),56 ('lo'+'o'*1000+'ng', 1),57 ('numb3rs', 1),58 ('ev3ry_thing', 1))59fail_single(ID,60 '3',61 '3tostart',62 '$other',63 'in-the-middle')64# NUMBER65make_single(NUMBER,66 ('', 0),67 ('24', 1),68 ('1 2', 3),69 ('1.2', 1),70 ('.3', 1),71 ('1.23'+'4'*100, 1),72 ('123'+'4'*100 + '1.20', 1),73 ('1.23e10', 1),74 ('1.23E10', 1),75 ('1.23e+10', 1),76 ('1.23E+10', 1),77 ('.1e-10', 1),78 ('.1E-10', 1))79fail_single(NUMBER,80 '.1e',81 '.2e.10')82# INT83make_single(INT,84 ('123', 1),85 ('', 0),86 ('100'+'0'*1000+'6543', 1))87# HEX88make_single(HEX,89 ('0xdead', 1),90 ('0x1234', 1),91 ('0xDEad0142', 1),92 ('0XDe23', 1))93fail_single(HEX,94 '1x23',95 '0xread')96# CCOMMENT97make_single(CCOMMENT,98 ('', 0),99 ('// hello!', 1),100 ('// one\n', 1),101 ('// one\n// two', 2))102# CMCOMMENT103make_single(CMCOMMENT,104 ('', 0),105 ('/**/', 1),106 ('/** //*/', 1),107 ('/*/*/', 1),108 ('/* // *//**/', 2),109 ('/** multi\n// line**/', 1))110fail_single(CMCOMMENT,111 '/*/',112 '/',113 '/*',114 '/** stuff\n')115# PYCOMMENT116make_single(PYCOMMENT,117 ('', 0),118 ('# stuff', 1),119 ('# nline\n', 1),120 ('# more\n# stuff', 2))121# ANY122make_single(ANY,123 ('', 0),124 ('ask@#$\n', 7))...
generate_doc.py
Source: generate_doc.py
1from docx import Document2from docx.enum.style import WD_STYLE_TYPE3from docx.enum.text import WD_PARAGRAPH_ALIGNMENT4from docx.shared import Pt5from src.utils.strings import fail_multi, tab, text1, text2, fail_single, \6 success, specialists7def has_comment(data):8 return "comment" in data9def main_generate_word(data):10 fail = fail_multi if has_comment(data) and "\n" in data["comment"] else fail_single11 comment = ''12 for c in data.get('comment', '').split('\n'):13 comment += f'{tab}{c}\n'14 number = f"{data['postanovlenie']}-{data['number']}"15 paragraph1 = f'ÐаÑвиÑелÑ: {data["name"]}\n' \16 f'ÐÐÐ: {data["inn"]}\n' \17 f'â заÑвки {number}\n' \18 f'ÐаÑа: {data["request_date"]}\n'19 paragraph2 = f'{tab}{text1}{fail if has_comment(data) else success}\t\n' \20 f'{comment if has_comment(data) else ""}\n'21 paragraph3 = f'{specialists[data["ispolnitel"]]}'22 paragraph4 = f'{text2}\n\n\n'23 document = Document()24 obj_styles = document.styles25 obj_charstyle = obj_styles.add_style('Main title', WD_STYLE_TYPE.CHARACTER)26 obj_font = obj_charstyle.font27 obj_font.size = Pt(14)28 obj_font.name = 'Times New Roman'29 obj_charstyle = obj_styles.add_style('Middle paragraph', WD_STYLE_TYPE.CHARACTER)30 obj_font = obj_charstyle.font31 obj_font.size = Pt(14)32 obj_font.name = 'Times New Roman'33 obj_charstyle = obj_styles.add_style('Last paragraph', WD_STYLE_TYPE.CHARACTER)34 obj_font = obj_charstyle.font35 obj_font.size = Pt(11)36 obj_font.name = 'Times New Roman'37 t = document.add_paragraph('')38 t.add_run('ÐÐÐÐЮЧÐÐÐÐРЮРÐÐÐЧÐСÐÐÐÐ ÐТÐÐÐÐ\n\n', style='Main title')39 t.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER40 p1 = document.add_paragraph('')41 p1.add_run(paragraph1, style='Middle paragraph')42 p1.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT43 p2 = document.add_paragraph('')44 p2.add_run(paragraph2, style='Middle paragraph')45 p2.alignment = WD_PARAGRAPH_ALIGNMENT.JUSTIFY46 p3 = document.add_paragraph('')47 p3.add_run(paragraph3, style='Middle paragraph')48 p3.alignment = WD_PARAGRAPH_ALIGNMENT.JUSTIFY49 p4 = document.add_paragraph('')50 p4.add_run(paragraph4, style='Last paragraph').italic = True51 p4.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER...
collective_fail.py
Source: collective_fail.py
1def fail_collective():2 import underworld as uw3 raise RuntimeError("Collective error.")4collective_msg = b'An uncaught exception appears to have been raised by all processes. Set the \'UW_ALL_MESSAGES\' environment variable to see all messages. Rank 0 message is:\nTraceback (most recent call last):\n File "collective_fail.py", line 18, in <module>\n fail_collective()\n File "collective_fail.py", line 4, in fail_collective\n raise RuntimeError("Collective error.")\nRuntimeError: Collective error.\n'5def fail_single():6 import underworld as uw7 if uw.mpi.rank==1:8 raise RuntimeError("Rank 1 error.")9single_msg = b'An uncaught exception was encountered on processor 1.\nTraceback (most recent call last):\n File "collective_fail.py", line 20, in <module>\n fail_single()\n File "collective_fail.py", line 10, in fail_single\n raise RuntimeError("Rank 1 error.")\nRuntimeError: Rank 1 error.\n'10if __name__ == '__main__':11 import sys12 if len(sys.argv) > 1:13 if sys.argv[1] == "collective":14 fail_collective()15 elif sys.argv[1] == "single":16 fail_single()17 else:18 import subprocess19 command = "mpirun -np 2 python3 collective_fail.py"20 result = subprocess.run(command + " collective", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)21 if not result.stderr.startswith(collective_msg):22 raise RuntimeError("Incorrect collective error message encountered. \n"23 "Expected:\n{}\n\n"24 "Encountered:\n{}\n\n".format(collective_msg,result.stderr[0:len(collective_msg)+1]))25 result = subprocess.run(command + " single", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)26 if not result.stderr.startswith(single_msg):27 raise RuntimeError("Incorrect collective error message encountered. \n"28 "Expected:\n{}\n\n"...
Check out the latest blogs from LambdaTest on this topic:
Ever came across the situation where you really need to open a web page fast and it’s taking forever because of slow internet speed? May be someone in your network is downloading a torrent choking the bandwidth?
In today’s scenario, software testing has become an important entity across every domain for the benefits it offers. We have already explored a lot about software testing in general in our post need of software testing.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Mobile Testing Tutorial.
Before development of a project begins, the project manager’s job is to determine which methodology should be used for the project life cycle. The 2 most popular methodologies are
In human physiology, vision plays a major role as 83% of the information humans perceive is via sight. So, your website should never lack in visual appeal. In web design, this is even more important. Every new iteration of design leaves some minor deviations. Sometimes, these minor visual deviations can be very hard to fix or unknowingly break the whole user experience. Hence, it is necessary to make sure that your website provides a perfect and working interface design to the user.
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!!