How to use setup_source method in autotest

Best Python code snippet using autotest_python

bootstrap.py

Source:bootstrap.py Github

copy

Full Screen

1##############################################################################2#3# Copyright (c) 2006 Zope Foundation and Contributors.4# All Rights Reserved.5#6# This software is subject to the provisions of the Zope Public License,7# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS11# FOR A PARTICULAR PURPOSE.12#13##############################################################################14"""Bootstrap a buildout-based project15Simply run this script in a directory containing a buildout.cfg.16The script accepts buildout command-line options, so you can17use the -c option to specify an alternate configuration file.18"""19import os, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess20from optparse import OptionParser21if sys.platform == 'win32':22 def quote(c):23 if ' ' in c:24 return '"%s"' % c # work around spawn lamosity on windows25 else:26 return c27else:28 quote = str29# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.30stdout, stderr = subprocess.Popen(31 [sys.executable, '-Sc',32 'try:\n'33 ' import ConfigParser\n'34 'except ImportError:\n'35 ' print 1\n'36 'else:\n'37 ' print 0\n'],38 stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()39has_broken_dash_S = bool(int(stdout.strip()))40# In order to be more robust in the face of system Pythons, we want to41# run without site-packages loaded. This is somewhat tricky, in42# particular because Python 2.6's distutils imports site, so starting43# with the -S flag is not sufficient. However, we'll start with that:44if not has_broken_dash_S and 'site' in sys.modules:45 # We will restart with python -S.46 args = sys.argv[:]47 args[0:0] = [sys.executable, '-S']48 args = map(quote, args)49 os.execv(sys.executable, args)50# Now we are running with -S. We'll get the clean sys.path, import site51# because distutils will do it later, and then reset the path and clean52# out any namespace packages from site-packages that might have been53# loaded by .pth files.54clean_path = sys.path[:]55import site56sys.path[:] = clean_path57for k, v in sys.modules.items():58 if k in ('setuptools', 'pkg_resources') or (59 hasattr(v, '__path__') and60 len(v.__path__)==1 and61 not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):62 # This is a namespace package. Remove it.63 sys.modules.pop(k)64is_jython = sys.platform.startswith('java')65setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'66distribute_source = 'http://python-distribute.org/distribute_setup.py'67# parsing arguments68def normalize_to_url(option, opt_str, value, parser):69 if value:70 if '://' not in value: # It doesn't smell like a URL.71 value = 'file://%s' % (72 urllib.pathname2url(73 os.path.abspath(os.path.expanduser(value))),)74 if opt_str == '--download-base' and not value.endswith('/'):75 # Download base needs a trailing slash to make the world happy.76 value += '/'77 else:78 value = None79 name = opt_str[2:].replace('-', '_')80 setattr(parser.values, name, value)81usage = '''\82[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]83Bootstraps a buildout-based project.84Simply run this script in a directory containing a buildout.cfg, using the85Python that you want bin/buildout to use.86Note that by using --setup-source and --download-base to point to87local resources, you can keep this script from going over the network.88'''89parser = OptionParser(usage=usage)90parser.add_option("-v", "--version", dest="version",91 help="use a specific zc.buildout version")92parser.add_option("-d", "--distribute",93 action="store_true", dest="use_distribute", default=True,94 help="Use Distribute rather than Setuptools.")95parser.add_option("--setup-source", action="callback", dest="setup_source",96 callback=normalize_to_url, nargs=1, type="string",97 help=("Specify a URL or file location for the setup file. "98 "If you use Setuptools, this will default to " +99 setuptools_source + "; if you use Distribute, this "100 "will default to " + distribute_source +"."))101parser.add_option("--download-base", action="callback", dest="download_base",102 callback=normalize_to_url, nargs=1, type="string",103 help=("Specify a URL or directory for downloading "104 "zc.buildout and either Setuptools or Distribute. "105 "Defaults to PyPI."))106parser.add_option("--eggs",107 help=("Specify a directory for storing eggs. Defaults to "108 "a temporary directory that is deleted when the "109 "bootstrap script completes."))110parser.add_option("-t", "--accept-buildout-test-releases",111 dest='accept_buildout_test_releases',112 action="store_true", default=False,113 help=("Normally, if you do not specify a --version, the "114 "bootstrap script and buildout gets the newest "115 "*final* versions of zc.buildout and its recipes and "116 "extensions for you. If you use this flag, "117 "bootstrap and buildout will get the newest releases "118 "even if they are alphas or betas."))119parser.add_option("-c", None, action="store", dest="config_file",120 help=("Specify the path to the buildout configuration "121 "file to be used."))122options, args = parser.parse_args()123# if -c was provided, we push it back into args for buildout's main function124if options.config_file is not None:125 args += ['-c', options.config_file]126if options.eggs:127 eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))128else:129 eggs_dir = tempfile.mkdtemp()130if options.setup_source is None:131 if options.use_distribute:132 options.setup_source = distribute_source133 else:134 options.setup_source = setuptools_source135if options.accept_buildout_test_releases:136 args.append('buildout:accept-buildout-test-releases=true')137args.append('bootstrap')138try:139 import pkg_resources140 import setuptools # A flag. Sometimes pkg_resources is installed alone.141 if not hasattr(pkg_resources, '_distribute'):142 raise ImportError143except ImportError:144 ez_code = urllib2.urlopen(145 options.setup_source).read().replace('\r\n', '\n')146 ez = {}147 exec ez_code in ez148 setup_args = dict(to_dir=eggs_dir, download_delay=0)149 if options.download_base:150 setup_args['download_base'] = options.download_base151 if options.use_distribute:152 setup_args['no_fake'] = True153 ez['use_setuptools'](**setup_args)154 if 'pkg_resources' in sys.modules:155 reload(sys.modules['pkg_resources'])156 import pkg_resources157 # This does not (always?) update the default working set. We will158 # do it.159 for path in sys.path:160 if path not in pkg_resources.working_set.entries:161 pkg_resources.working_set.add_entry(path)162cmd = [quote(sys.executable),163 '-c',164 quote('from setuptools.command.easy_install import main; main()'),165 '-mqNxd',166 quote(eggs_dir)]167if not has_broken_dash_S:168 cmd.insert(1, '-S')169find_links = options.download_base170if not find_links:171 find_links = os.environ.get('bootstrap-testing-find-links')172if find_links:173 cmd.extend(['-f', quote(find_links)])174if options.use_distribute:175 setup_requirement = 'distribute'176else:177 setup_requirement = 'setuptools'178ws = pkg_resources.working_set179setup_requirement_path = ws.find(180 pkg_resources.Requirement.parse(setup_requirement)).location181env = dict(182 os.environ,183 PYTHONPATH=setup_requirement_path)184requirement = 'zc.buildout'185version = options.version186if version is None and not options.accept_buildout_test_releases:187 # Figure out the most recent final version of zc.buildout.188 import setuptools.package_index189 _final_parts = '*final-', '*final'190 def _final_version(parsed_version):191 for part in parsed_version:192 if (part[:1] == '*') and (part not in _final_parts):193 return False194 return True195 index = setuptools.package_index.PackageIndex(196 search_path=[setup_requirement_path])197 if find_links:198 index.add_find_links((find_links,))199 req = pkg_resources.Requirement.parse(requirement)200 if index.obtain(req) is not None:201 best = []202 bestv = None203 for dist in index[req.project_name]:204 distv = dist.parsed_version205 if _final_version(distv):206 if bestv is None or distv > bestv:207 best = [dist]208 bestv = distv209 elif distv == bestv:210 best.append(dist)211 if best:212 best.sort()213 version = best[-1].version214if version:215 requirement = '=='.join((requirement, version))216cmd.append(requirement)217if is_jython:218 import subprocess219 exitcode = subprocess.Popen(cmd, env=env).wait()220else: # Windows prefers this, apparently; otherwise we would prefer subprocess221 exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))222if exitcode != 0:223 sys.stdout.flush()224 sys.stderr.flush()225 print ("An error occurred when trying to install zc.buildout. "226 "Look above this message for any errors that "227 "were output by easy_install.")228 sys.exit(exitcode)229ws.add_entry(eggs_dir)230ws.require(requirement)231import zc.buildout.buildout232zc.buildout.buildout.main(args)233if not options.eggs: # clean up temporary egg directory...

Full Screen

Full Screen

test_dg.py

Source:test_dg.py Github

copy

Full Screen

...3import time4gen = RigolDG900('TCPIP::192.168.0.109::INSTR')5gen.print_info()6# gen.reset()7#gen.setup_source(channel=1,shape=RigolDG900.waveform.SQUARE,duty=25.3, period='5ms', offset=RigolDG900.offset.MAXIMUM)8gen.setup_output(channel=1, impedance=RigolDG900.limit.INFINITY)9gen.setup_source(source=1, shape=RigolDG900.waveform.SINUSOID, frequency='10MHz',10 amplitude='500mV', offset='100mV', phase='{0}rad'.format(pi/2))11gen.output_state(channel=1, state=1)12for s in RigolDG900.generic_function_list:13 gen.setup_source(source=1, shape=s, frequency='10MHz', offset='-100mV',14 amplitude='500mVpp', duty=25, sample_rate='1MSa/s', phase='90deg')15 gen.beep()16 time.sleep(1)17# gen.setup_source(source=1, shape=RigolDG900.waveform.SEQUENCE, frequency='1MHz', offset='-100mV',18# amplitude='500mVpp', sample_rate='1MSa/s', phase='0deg')19gen.setup_source(1, RigolDG900.waveform.ABSSINE,20 amplitude='2Vpp', frequency='100kHz', offset='50mV')21# gen.setup_channel(channel=2,on=0)...

Full Screen

Full Screen

util.py

Source:util.py Github

copy

Full Screen

1from __future__ import absolute_import2from __future__ import print_function3from __future__ import unicode_literals4import os5import sys6def add_src_to_python_path():7 """8 Adds the source directory to the Python path.9 """10 src = os.path.join(os.getcwd(), 'src')11 src = os.path.abspath(src)12 if src not in sys.path:13 sys.path.insert(0, src)14def setup_py(*args):15 """16 Execute a setup.py command with the given args17 """18 setup_path = os.path.join(os.getcwd(), 'setup.py')19 with open(setup_path) as F:20 setup_source = F.read()21 old_args = sys.argv22 try:23 sys.argv = ['setup.py'] + list(args)24 exec(setup_source, {25 '__file__': setup_path,26 })27 finally:...

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