Best Python code snippet using autotest_python
script_test.py
Source: script_test.py
...4import subprocess5import os6CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))7FILE='testpofile.da.po'8def prepend_path(filepath):9 """Return the absolute path of a file in the functionaltest folder"""10 return os.path.join(CURRENT_DIR, filepath)11def run_command(command_args):12 """Run a command13 Args:14 command_args (list): List of command and arguments e.g. ['ls', '-l']15 Returns:16 tuple: (return_code (int), stdout (str), stderr (str)) 17 """18 process = subprocess.Popen(command_args,19 stdout=subprocess.PIPE,20 stderr=subprocess.PIPE,21 cwd=CURRENT_DIR)22 stdout, stderr = process.communicate()23 process.wait()24 return process.returncode, stdout, stderr25def standardtest(command_args, expected, return_code=0):26 """Perform the standard tests on a command.27 The standard tests consist of making sure that the return_code is as28 expected, that stderr is empty and that stdout has the expected value.29 """30 return_code_actual, stdout, stderr = run_command(command_args)31 if 'pyg3t_save_output' in os.environ:32 with open('{0}_expected_output'.format(command_args[0]), 'w') as fd:33 fd.write(stdout)34 return35 assert return_code_actual == return_code36 assert stderr == b''37 assert stdout == expected38def test_gtcat():39 """Functional test for gtcat40 This test uses the old.po, new.po and gtcat_expected_output files.41 """42 # Complete command:43 # gtcat --encode ISO-8859-1 old.po|podiff -r - new.po44 process1 = subprocess.Popen(45 ['gtcat', '--encode', 'ISO-8859-1', 'old.po'],46 stdout=subprocess.PIPE, cwd=CURRENT_DIR47 )48 process2 = subprocess.Popen(49 ['podiff', '-r', '-', 'new.po'], stdin=process1.stdout,50 stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=CURRENT_DIR51 )52 # Forward output53 process1.stdout.close()54 # Wait for process to close and set return code and check it55 process1.wait()56 assert process1.returncode == 057 # Get final stdout and stderr58 stdout, stderr = process2.communicate()59 # Check return code60 process2.wait()61 assert process2.returncode == 062 # Check stderr and stdout63 assert stderr == b''64 with open(prepend_path('gtcat_expected_output'), 'rb') as file_:65 expected = file_.read()66 assert stdout == expected67def test_gtcheckargs():68 """Functional test for gtcheckargs"""69 with open(prepend_path('gtcheckargs_expected_output'), 'rb') as file_:70 expected = file_.read()71 standardtest(['gtcheckargs', FILE], expected, return_code=1)72def test_gtcompare():73 """Functional test for gtcompare"""74 with open(prepend_path('gtcompare_expected_output'), 'rb') as file_:75 expected = file_.read()76 standardtest(['gtcompare', FILE, FILE], expected)77def test_gtgrep():78 """functional test for gtgrep"""79 with open(prepend_path('gtgrep_expected_output'), 'rb') as file_:80 expected = file_.read()81 standardtest(['gtgrep', '-i', 'hello', '-s', 'hej', FILE], expected)82def test_gtmerge():83 """Functional test for gtmerge"""84 with open(prepend_path('gtmerge_expected_output'), 'rb') as file_:85 expected = file_.read()86 standardtest(['gtmerge', FILE, FILE], expected)87def test_gtprevmsgdiff():88 """Functional test for gtprevmsgdiff"""89 with open(prepend_path('gtprevmsgdiff_expected_output'), 'rb') as file_:90 expected = file_.read()91 standardtest(['gtprevmsgdiff', FILE], expected)92def test_gtwdiff():93 """Functional test for gtwdiff"""94 with open(prepend_path('gtwdiff_expected_output'), 'rb') as file_:95 expected = file_.read()96 return_code, stdout, stderr = run_command(97 ['gtwdiff', 'testpodiff_gtwdiff.podiff']98 )99 assert return_code == 0100 assert stderr == b''101 # We have problems with the diff comming out in different order on102 # different Python versions, so test for correct in and out but103 # not for the same order104 new_pattern = b'\x1b[1;33;42m'105 old_pattern = b'\x1b[1;31;41m'106 stop_pattern = b'\x1b[0m'107 def parse_wdiff(text):108 out = {'new': b'', 'old': b'', 'unchanged': b''}109 state = 'unchanged'110 while text:111 if text.startswith(new_pattern):112 state = 'new'113 text = text.replace(new_pattern, b'', 1)114 elif text.startswith(old_pattern):115 state = 'old'116 text = text.replace(old_pattern, b'', 1)117 elif text.startswith(stop_pattern):118 state = 'unchanged'119 text = text.replace(stop_pattern, b'', 1)120 else:121 out[state] += text[0:1]122 text = text[1:]123 return out124 from_stdout = parse_wdiff(stdout)125 from_expected = parse_wdiff(expected)126 assert from_stdout['new'] == from_expected['new']127 assert from_stdout['old'] == from_expected['old']128 assert from_stdout['unchanged'] == from_expected['unchanged']129def test_gtxml():130 """Functional test for gtxml"""131 with open(prepend_path('gtxml_expected_output'), 'rb') as file_:132 expected = file_.read()133 standardtest(['gtxml', FILE], expected, return_code=1)134def test_poabc():135 """Functional test for poabc"""136 with open(prepend_path('poabc_expected_output'), 'rb') as file_:137 expected = file_.read()138 standardtest(['poabc', FILE], expected)139def test_podiff():140 """Functional test for podiff"""141 with open(prepend_path('podiff_expected_output'), 'rb') as file_:142 expected = file_.read()143 standardtest(['podiff', '--relax', 'old.po', 'new.po'], expected)144def test_popatch():145 """Functional test for popatch"""146 return_code, stdout, stderr = run_command(147 ['popatch', 'testpofile.da.po', 'testpodiff.podiff'])148 assert return_code == 0149 assert stderr == b''150 with open(prepend_path('patched.po'), 'wb') as file_:151 file_.write(stdout)152 return_code, stdout, stderr = run_command(153 ['popatch', '--new', 'testpodiff.podiff'])154 assert return_code == 0155 assert stderr == b''156 with open(prepend_path('patched.new.po'), 'wb') as file_:157 file_.write(stdout)158 return_code, stdout, stderr = run_command(159 ['popatch', '--old', 'testpodiff.podiff'])160 assert return_code == 0161 assert stderr == b''162 with open(prepend_path('patched.old.po'), 'wb') as file_:163 file_.write(stdout)164 return_code, stdout, stderr = run_command(165 ['podiff', '-rf', 'patched.old.po', 'patched.new.po'])166 assert return_code == 0167 assert stderr == b''168 with open(prepend_path('testpodiff.podiff'), 'rb') as file_:169 lines_diff = file_.readlines()170 lines_stdout = stdout.strip().split(b'\n')171 for line1, line2 in zip(lines_diff, lines_stdout):172 if line1.startswith(b'---'):173 continue174 assert line1 == line2 + b'\n'175def test_poselect():176 """Functional test for poselect"""177 with open(prepend_path('poselect_expected_output'), 'rb') as file_:178 expected = file_.read()...
package.py
Source: package.py
...40 return args41 def setup_environment(self, spack_env, run_env):42 gcc = which(spack_cc)43 gcc_prefix = re.sub('/bin/.*$', '', self.compiler.cc)44 spack_env.prepend_path('PATH',45 join_path(self.build_directory, 'bin'))46 spack_env.prepend_path('PATH',47 join_path(self.build_directory, 'test'))48 spack_env.prepend_path('LD_LIBRARY_PATH',49 join_path(self.build_directory, 'lib'))50 spack_env.prepend_path('LD_LIBRARY_PATH',51 join_path(self.build_directory, 'test'))52 spack_env.prepend_path('LD_LIBRARY_PATH',53 join_path(self.spec['root'].prefix.lib))54 spack_env.prepend_path('LD_LIBRARY_PATH',55 join_path(gcc_prefix, 'lib64'))56 # Ensure we can find plugin libraries.57 spack_env.prepend_path('PYTHONPATH',58 join_path(self.build_directory, 'lib'))59 spack_env.prepend_path('PYTHONPATH',60 join_path(self.build_directory, 'test'))61 spack_env.prepend_path('PYTHONPATH',62 join_path(self.build_directory, 'python'))63 spack_env.prepend_path('PYTHONPATH',64 join_path(self.build_directory, 'cfipython'))65 run_env.prepend_path('PYTHONPATH', self.prefix.lib)66 run_env.prepend_path('PYTHONPATH', '%s/python' % self.prefix)67 run_env.prepend_path('PYTHONPATH', '%s/cfipython' % self.prefix)68 # Ensure Root can find headers for autoparsing.69 for d in self.spec.traverse(root=False, cover='nodes', order='post',70 deptype=('link'), direction='children'):71 spack_env.prepend_path('ROOT_INCLUDE_PATH',72 str(self.spec[d.name].prefix.include))73 run_env.prepend_path('ROOT_INCLUDE_PATH',74 str(self.spec[d.name].prefix.include))75 run_env.prepend_path('ROOT_INCLUDE_PATH', self.prefix.include)76 run_env.prepend_path('ROOT_INCLUDE_PATH', self.prefix.src)...
constants.py
Source: constants.py
1# If you change the location of dataset, then2# Make the appropriate changes to the following constants.3prepend_path = ''4# /prepend_path = '../'5TRAIN_FILE = prepend_path + 'data/en-ud-train.conllu'6DEV_FILE = prepend_path + 'data/en-ud-dev.conllu'7TEST_FILE_UNLABELED = prepend_path + 'data/en-ud-test-hidden.conllu'8TEST_FILE = prepend_path + 'data/en-ud-test.conllu'9NR_TRAIN_FILE = prepend_path + 'data/no_bokmaal-ud-train.conllu'10NR_DEV_FILE = prepend_path + 'data/no_bokmaal-ud-dev.conllu'11NR_TEST_FILE_UNLABELED = prepend_path + 'data/no_bokmaal-ud-test-hidden.conllu'12NR_TEST_FILE = prepend_path + 'data/no_bokmaal-ud-test.conllu'13OFFSET = '**OFFSET**'14START_TAG = '--START--'15END_TAG = '--END--'...
Check out the latest blogs from LambdaTest on this topic:
So you are at the beginning of 2020 and probably have committed a new year resolution as a tester to take a leap from Manual Testing To Automation . However, to automate your test scripts you need to get your hands dirty on a programming language and that is where you are stuck! Or you are already proficient in automation testing through a single programming language and are thinking about venturing into new programming languages for automation testing, along with their respective frameworks. You are bound to be confused about picking your next milestone. After all, there are numerous programming languages to choose from.
In an ideal world, you can test your web application in the same test environment and return the same results every time. The reality can be difficult sometimes when you have flaky tests, which may be due to the complexity of the web elements you are trying to perform an action on your test case.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
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!!