Best Python code snippet using ATX
test_build_automation_c.py
Source:test_build_automation_c.py
1"""2The MIT License (MIT)3Copyright (c) 2015-2021 Kim Blomqvist4Permission is hereby granted, free of charge, to any person obtaining a copy5of this software and associated documentation files (the "Software"), to deal6in the Software without restriction, including without limitation the rights7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8copies of the Software, and to permit persons to whom the Software is9furnished to do so, subject to the following conditions:10The above copyright notice and this permission notice shall be included in11all copies or substantial portions of the Software.12THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN18THE SOFTWARE.19"""20import sys21import subprocess22from os import path, chdir, mkdir23import pytest24if sys.version_info[0] == 2:25 FileNotFoundError = IOError26SCRIPT_PATH = path.dirname(path.realpath(__file__))27requires_py27_or_py35_or_greater = pytest.mark.skipif(28 sys.version_info < (2,7) or29 (sys.version_info >= (3,) and sys.version_info < (3,5)),30 reason='Requires either Python 2.7 or >= 3.5'31)32def check_output(cmd):33 try:34 return subprocess.check_output(cmd)35 except FileNotFoundError as e:36 msg = str(e)37 pytest.skip(msg)38def check_call(cmd):39 try:40 return subprocess.check_call(cmd)41 except FileNotFoundError as e:42 msg = str(e)43 pytest.skip(msg)44def setup_function():45 chdir(SCRIPT_PATH + '/fixtures/c_project')46def teardown_function(function):47 chdir(SCRIPT_PATH + '/fixtures/c_project')48 if 'scons' in function.__name__:49 check_call(('scons', '-c'))50 check_call(('scons', '-C', 'src', '-c'))51 else:52 check_call(('make', 'clean'))53 check_call(('make', '-C', 'src', 'clean'))54build_dependencies = (55 'foo.c.jinja',56 'foo.h.jinja',57 'foo.c.py',58 'foo.toml',59 'header.j2inc'60)61@pytest.mark.slowtest62def test_make():63 build_cmd = ('make',)64 # First build65 out = check_output(build_cmd)66 assert not b'is up to date' in out67 assert path.isfile('build/a.out')68 # Second build shouldn't do anything69 out = check_output(build_cmd)70 assert b'is up to date' in out71 # Check program output72 out = check_output(('./build/a.out'))73 assert b'bar has 3 chars ...\n' == out74 # Require rebuild after touching dependency75 for dep in build_dependencies:76 check_call(('touch', path.join('src', dep)))77 out = check_output(build_cmd)78 assert not b'is up to date' in out79@pytest.mark.slowtest80def test_cmake():81 mkdir('build')82 chdir('build')83 build_cmd = ('make',)84 # First build85 check_call(('cmake', '..'))86 out = check_output(build_cmd)87 assert b'Linking C executable' in out88 assert path.isfile('a.out')89 # Immediate new build shouldn't do anything90 out = check_output(build_cmd)91 assert not b'Linking C executable' in out92 # Check program output93 out = check_output(['./a.out'])94 assert b'bar has 3 chars ...\n' == out95 # Require rebuild after touching build dependency96 for dep in build_dependencies:97 check_call(('touch', path.join('../src/', dep)))98 out = check_output(build_cmd)99 assert b'Linking C executable' in out100@pytest.mark.slowtest101@requires_py27_or_py35_or_greater102def test_scons():103 build_cmd = ('scons', '-Q')104 # First build105 out = check_output(build_cmd)106 assert not b'is up to date' in out107 assert path.isfile('build/a.out')108 # Immediate new build shouldn't do anything109 out = check_output(build_cmd)110 assert b'is up to date' in out111 # Check program output112 out = check_output(('./build/a.out'))113 assert b'bar has 3 chars ...\n' == out114 # FIXME: Sometimes the rebuild happens sometimes not.115 for dep in build_dependencies:116 check_call(('touch', path.join('src', dep)))117 out = check_output(build_cmd)118 #assert not b'is up to date' in out119 print(out) # For debugging purposes, run 'pytest -s -k scons'120@pytest.mark.slowtest121def test_make_without_build_dir():122 chdir('src')123 build_cmd = ('make',)124 # First build125 out = check_output(build_cmd)126 assert not b'is up to date' in out127 assert path.isfile('a.out')128 # Immediate new build shouldn't do anything129 out = check_output(build_cmd)130 assert b'is up to date' in out131 # Check program output132 out = check_output(('./a.out'))133 assert b'bar has 3 chars ...\n' == out134 # Require rebuild after touching dependency135 for dep in build_dependencies:136 check_call(('touch', dep))137 out = check_output(build_cmd)138 assert not b'is up to date' in out139@pytest.mark.slowtest140@requires_py27_or_py35_or_greater141def test_scons_without_build_dir():142 chdir('src')143 build_cmd = ('scons', '-Q')144 # First build145 out = check_output(build_cmd)146 assert not b'is up to date' in out147 assert path.isfile('a.out')148 # Immediate new build shouldn't do anything149 out = check_output(build_cmd)150 assert b'is up to date' in out151 # Check program output152 out = check_output(('./a.out'))153 assert b'bar has 3 chars ...\n' == out154 # FIXME: Sometimes the rebuild happens sometimes not.155 for dep in build_dependencies:156 check_call(('touch', dep))157 out = check_output(build_cmd)158 #assert not b'is up to date' in out...
build_cmd_tests.py
Source:build_cmd_tests.py
1from pavilion import arguments2from pavilion import commands3from pavilion import plugins4from pavilion.status_file import STATES5from pavilion.unittest import PavTestCase6class BuildCmdTests(PavTestCase):7 """The build command is really just the run command in disguise, so8 we only need to test the unique arguments that it enables."""9 def set_up(self):10 plugins.initialize_plugins(self.pav_cfg)11 commands.get_command('build').silence()12 def test_multi_build(self):13 """Make sure we can just build multiple simultaneous builds on14 both the front-end and the nodes."""15 arg_parser = arguments.get_parser()16 args = arg_parser.parse_args([17 'build',18 '-H', 'this',19 'build_parallel'20 ])21 build_cmd = commands.get_command(args.command_name)22 build_ret = build_cmd.run(self.pav_cfg, args)23 build_cmd.outfile.seek(0)24 self.assertEqual(build_ret, 0, msg=build_cmd.outfile.read())25 for test in build_cmd.last_tests:26 test.wait(timeout=10)27 # Make sure we actually built separate builds28 builds = [test.builder for test in build_cmd.last_tests]29 build_names = set([b.name for b in builds])30 self.assertEqual(len(build_names), 4)31 for test in build_cmd.last_tests:32 if not test.skipped:33 self.assertEqual(test.status.current().state, STATES.BUILD_DONE,34 msg='Test {} status: {}'35 .format(test.id, test.status.current()))36 def test_local_builds_only(self):37 """Make sure we can just build multiple simultanious builds on38 both the front-end and the nodes."""39 arg_parser = arguments.get_parser()40 args = arg_parser.parse_args([41 'build',42 '-H', 'this',43 '--local-builds-only',44 'build_parallel'45 ])46 build_cmd = commands.get_command(args.command_name)47 build_ret = build_cmd.run(self.pav_cfg, args)48 build_cmd.outfile.seek(0)49 self.assertEqual(build_ret, 0, msg=build_cmd.outfile.read())50 for test in build_cmd.last_tests:51 test.wait(timeout=10)52 # Make sure we actually built separate builds53 builds = [test.builder for test in build_cmd.last_tests]54 build_names = set([b.name for b in builds])55 self.assertEqual(len(build_names), 2)56 for test in build_cmd.last_tests:57 if not test.skipped:58 self.assertEqual(test.status.current().state, STATES.BUILD_DONE,59 msg='Test {} status: {}'60 .format(test.id, test.status.current()))61 def test_rebuilds(self):62 """Make sure rebuilding works as expected."""63 arg_parser = arguments.get_parser()64 args = arg_parser.parse_args([65 'build',66 '-H', 'this',67 'build_rebuild',68 '--rebuild',69 ])70 build_cmd = commands.get_command(args.command_name)71 self.assertEqual(build_cmd.run(self.pav_cfg, args), 0)72 for test in build_cmd.last_tests:73 test.wait(timeout=10)74 # Make sure we actually built separate builds75 builds = [test.builder for test in build_cmd.last_tests]76 build_names = set([b.name for b in builds])77 self.assertEqual(len(build_names), 4)78 result_matrix = {79 'local1': [STATES.BUILD_DONE, STATES.BUILD_REUSED],80 'local1a': [STATES.BUILD_REUSED, STATES.BUILD_DONE],81 'nodes1': [STATES.BUILD_REUSED, STATES.BUILD_DONE],82 'nodes1a': [STATES.BUILD_REUSED, STATES.BUILD_DONE],83 'local2': [STATES.BUILD_DONE],84 'nodes3': [STATES.BUILD_DONE],85 }86 orig_names = {}87 for test in build_cmd.last_tests:88 tname = test.name.split('.')[1]89 self.assertIn(test.status.current().state, result_matrix[tname],90 msg='Test {} status: {}'91 .format(test.name, test.status.current()))92 orig_names[test.name] = test.builder.name93 self.assertEqual(build_cmd.run(self.pav_cfg, args), 0)94 for test in build_cmd.last_tests:95 test.wait(timeout=10)96 # Make sure we actually built separate builds97 builds = [test.builder for test in build_cmd.last_tests]98 build_names = set([b.name for b in builds])99 self.assertEqual(len(build_names), 4)100 for test in build_cmd.last_tests:101 test.load_attributes()102 expected_name = test.builder.rehash_name(orig_names[test.name])103 self.assertEqual(test.build_name, expected_name,104 msg=test.name)105 origin = test.build_origin_path.resolve().name106 self.assertEqual(origin, expected_name,107 msg=test.name)108 def test_build_verbosity(self):109 """Make sure that the build verbosity levels at least appear to work."""110 arg_parser = arguments.get_parser()111 arg_sets = [112 ['build', '-H', 'this', '-l', '-b', 'build_parallel'],113 ['build', '-H', 'this', '-l', '-b', '-b', 'build_parallel'],114 ]115 build_cmd = commands.get_command('build')116 for arg_set in arg_sets:117 args = arg_parser.parse_args(arg_set)118 build_ret = build_cmd.run(self.pav_cfg, args)119 build_cmd.outfile.seek(0)...
release_build.py
Source:release_build.py
1#!/usr/bin/env python2import sys3import subprocess4import logging5import shutil6import errno7import os8from argparse import ArgumentParser9from packagecreator import SconsConfiguration, PackageCreatorError, PackageCreatorManager10logger = logging.getLogger(__name__)11def compose_build_command(baseline, builddir, suffix):12 build_cmd = []13 build_cmd.append('scons')14 build_cmd.append('--allvars')15 build_cmd.append('--no-cache')16 build_cmd.append('--debug=time')17 build_cmd.append('--jobs=264')18 build_cmd.append('BUILDDIR=' + builddir)19 build_cmd.append('--userconfig=scons/.release.build.cfg' + ('.' + suffix if suffix != '' else ''))20 build_cmd.append('BUILD_LABEL=%s' % baseline)21 build_cmd.append('package')22 return build_cmd23def build_applications(configuration, suffix=''):24 cmd = compose_build_command(configuration.baseline, configuration.build_subdirectory, suffix)25 logger.info("Build cmd %s" % cmd)26 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)27 for line in iter(process.stdout.readline, ''):28 logger.info(line.strip())29 return process.wait() == 030def main(argv=None):31 try:32 parser = ArgumentParser(description='ATSEv2 baseline package builder manager')33 parser.add_argument('--baseline', type=str, required=True,34 help='Baseline <family>.<release> Ex. atsev2.2015.00.00')35 parser.add_argument('--stage', action="store_true",36 help="Stage package (default: false)")37 parser.add_argument('--build-directory', type=str, default='sc_release',38 help='Build directory (default: sc_release)')39 parser.add_argument('--strip', action="store_true",40 help="Strip debug symbols info separate package (default: false)")41 parser.add_argument('--drop-symbols', action="store_true",42 help="Do not create symbols package (default: false). Could be used with --strip")43 parser.add_argument('--add-suffixes', type=str, default='fallback',44 help="Different suffixes for config file (for different compilers and etc.)")45 args = parser.parse_args()46 logging.basicConfig(level=getattr(logging, 'INFO'),47 format="%(message)s",48 datefmt='%Y-%m-%d %H:%M:%S',49 stream=sys.stdout)50 configuration = SconsConfiguration(args.baseline,51 args.build_directory,52 args.stage,53 args.strip,54 args.drop_symbols)55 if not build_applications(configuration):56 return 157 configuration.collect()58 logger.debug(configuration)59 configuration.verify()60 for suff in args.add_suffixes.split(','):61 if len(suff) == 0:62 continue63 curr_config = SconsConfiguration(args.baseline,64 args.build_directory + '.' + suff,65 args.stage,66 args.strip,67 args.drop_symbols)68 if not build_applications(curr_config, suff):69 return 170 curr_config.collect()71 logger.debug(curr_config)72 curr_config.verify()73 os.link(curr_config.binary_path, configuration.binary_path + '.' + suff)74 if not PackageCreatorManager(configuration).process():75 return 176 return 077 except PackageCreatorError as exc:78 logger.critical(str(exc.args))79 except Exception, e:80 logger.critical(str(e))81 return 182if __name__ == "__main__":...
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!!