Best Python code snippet using prospector_python
virtenv.py
Source:virtenv.py
...122 sys_mgr = UnsupportedDistManager(ctx)123 # Yes, some of these lines are very long, but let's stay consistent.124 # pylint: disable=line-too-long125 # Basic venv stuff:126 pip_mgr.check_package(BUILD, 'pip', version='>=19.0')127 pip_mgr.check_package(BUILD, 'setuptools', version='>=41.0')128 pip_mgr.check_package(BUILD, 'wheel', version='>=0.33')129 sys_mgr.check_package(BUILD, 'build-essential')130 sys_mgr.check_package(BUILD, 'python3-dev')131 # Misc pip packages:132 pip_mgr.check_package(RUNTIME, 'eventfd', version='0.2')133 pip_mgr.check_package(RUNTIME, 'lucky-humanize', version='0.5.4')134 pip_mgr.check_package(RUNTIME, 'numpy', version='1.18.1')135 pip_mgr.check_package(RUNTIME, 'portalocker', version='1.5.2')136 pip_mgr.check_package(RUNTIME, 'posix-ipc', version='1.0.4')137 pip_mgr.check_package(RUNTIME, 'psutil', version='5.6.7')138 pip_mgr.check_package(RUNTIME, 'pyparsing', version='2.4.6')139 pip_mgr.check_package(RUNTIME, 'sortedcontainers', version='2.1.0')140 pip_mgr.check_package(RUNTIME, 'toposort', version='1.5')141 pip_mgr.check_package(RUNTIME, 'urwid', version='2.1.0')142 pip_mgr.check_package(RUNTIME, 'fastjsonschema', version='2.14.2')143 pip_mgr.check_package(RUNTIME, 'mutagen', version='1.44.0')144 pip_mgr.check_package(BUILD, 'cssutils', version='1.0.2')145 pip_mgr.check_package(BUILD, 'Cython', version='0.29.15')146 pip_mgr.check_package(BUILD, 'Jinja2', version='2.11.1')147 pip_mgr.check_package(BUILD, 'PyYAML', version='5.3')148 pip_mgr.check_package(BUILD, 'packaging', version='20.1')149 pip_mgr.check_package(BUILD, 'xunitparser', version='1.3.3')150 pip_mgr.check_package(DEV, 'asynctest', version='0.13.0')151 pip_mgr.check_package(DEV, 'async-generator', version='1.10')152 pip_mgr.check_package(DEV, 'coverage', version='5.0.3')153 pip_mgr.check_package(DEV, 'mox3', version='1.0.0')154 pip_mgr.check_package(DEV, 'py-cpuinfo', version='5.0.0')155 pip_mgr.check_package(DEV, 'pyfakefs', version='3.7.1')156 pip_mgr.check_package(DEV, 'pylint', version='2.4.4')157 pip_mgr.check_package(DEV, 'unittest-xml-reporting', version='3.0.1')158 pip_mgr.check_package(DEV, 'pyprof2calltree', version='1.4.4')159 # misc sys packages:160 sys_mgr.check_package(RUNTIME, 'ffmpeg')161 sys_mgr.check_package(RUNTIME, 'libxkbcommon-x11-0')162 sys_mgr.check_package(BUILD, 'cmake')163 sys_mgr.check_package(BUILD, 'python3-dev')164 sys_mgr.check_package(BUILD, 'portaudio19-dev')165 sys_mgr.check_package(BUILD, 'libfluidsynth-dev')166 sys_mgr.check_package(BUILD, 'inkscape')167 sys_mgr.check_package(BUILD, 'zlib1g-dev')168 sys_mgr.check_package(BUILD, 'libunwind-dev')169 sys_mgr.check_package(DEV, 'gdb')170 sys_mgr.check_package(DEV, 'xvfb')171 sys_mgr.check_package(DEV, 'intltool')172 sys_mgr.check_package(DEV, 'libboost-dev', version='>=1.65')173 # git is needed to fetch PIP packages from 'git+https://...' sources.174 sys_mgr.check_package(BUILD, 'git')175 # mypy176 pip_mgr.check_package(DEV, 'mypy', version='0.761')177 pip_mgr.check_package(RUNTIME, 'mypy-extensions')178 # sndfile179 sys_mgr.check_package(BUILD, 'libsndfile1-dev')180 # csound181 sys_mgr.check_package(BUILD, 'libsamplerate0-dev')182 sys_mgr.check_package(BUILD, 'libboost-dev')183 sys_mgr.check_package(BUILD, 'flex')184 sys_mgr.check_package(BUILD, 'bison')185 CSoundBuilder(ctx).check(RUNTIME, version='6.08.0')186 # LV2187 sys_mgr.check_package(BUILD, 'libserd-dev')188 sys_mgr.check_package(BUILD, 'libsord-dev')189 sys_mgr.check_package(BUILD, 'libsratom-dev')190 if os_dist == 'ubuntu' and os_release >= Version('17.10'):191 sys_mgr.check_package(BUILD, 'lv2-dev')192 else:193 LV2Builder(ctx).check(RUNTIME, version='1.14.0')194 LilvBuilder(ctx).check(RUNTIME, version='0.24.3-git')195 SuilBuilder(ctx).check(RUNTIME, version='0.10.0')196 sys_mgr.check_package(DEV, 'mda-lv2')197 # ladspa198 sys_mgr.check_package(BUILD, 'ladspa-sdk')199 sys_mgr.check_package(DEV, 'swh-plugins')200 # Faust201 FaustBuilder(ctx).check(BUILD, version='2.15.11')202 FaustLibrariesBuilder(ctx).check(BUILD, version='64a57f56') # snapshot from 2019-03-30203 # libswresample204 sys_mgr.check_package(BUILD, 'libswresample-dev')205 # libavutil206 sys_mgr.check_package(BUILD, 'libavutil-dev')207 # sf2208 sys_mgr.check_package(RUNTIME, 'libfluidsynth1')209 sys_mgr.check_package(RUNTIME, 'timgm6mb-soundfont')210 sys_mgr.check_package(RUNTIME, 'fluid-soundfont-gs')211 sys_mgr.check_package(RUNTIME, 'fluid-soundfont-gm')212 # Qt213 pip_mgr.check_package(RUNTIME, 'PyQt5')214 # TODO: get my changes upstream and use regular quamash package from pip.215 pip_mgr.check_package(RUNTIME, 'Quamash', source='git+https://github.com/odahoda/quamash.git#egg=quamash')216 sys_mgr.check_package(BUILD, 'libqt4-dev')217 # GTK218 sys_mgr.check_package(BUILD, 'libgtk2.0-dev')219 sys_mgr.check_package(BUILD, 'libgirepository1.0-dev')220 pip_mgr.check_package(RUNTIME, 'PyGObject', version='3.34.0')221 pip_mgr.check_package(DEV, 'PyGObject-stubs', version='0.0.2')222 pip_mgr.check_package(RUNTIME, 'gbulb', version='0.6.1')223 # Protobuf224 pip_mgr.check_package(RUNTIME, 'protobuf', version='3.11.3')225 sys_mgr.check_package(BUILD, 'autoconf')226 sys_mgr.check_package(BUILD, 'automake')227 sys_mgr.check_package(BUILD, 'libtool')228 sys_mgr.check_package(BUILD, 'curl')229 sys_mgr.check_package(BUILD, 'make')230 sys_mgr.check_package(BUILD, 'g++')231 sys_mgr.check_package(BUILD, 'unzip')232 ProtocBuilder(ctx).check(BUILD, version='3.11.3')233 # TODO: get my changes upstream and use regular mypy-protobuf package from pip.234 pip_mgr.check_package(BUILD, 'mypy-protobuf', source='git+https://github.com/odahoda/mypy-protobuf.git#egg=mypy-protobuf&subdirectory=python')235 # profiling236 sys_mgr.check_package(RUNTIME, 'google-perftools')237 sys_mgr.check_package(RUNTIME, 'libgoogle-perftools4')238 sys_mgr.check_package(BUILD, 'libgoogle-perftools-dev')239 # indicator-cpufreq240 sys_mgr.check_package(DEV, 'libdbus-1-dev')241 pip_mgr.check_package(DEV, 'dbus-python', version='1.2.16')242 sys_mgr.check_package(DEV, 'bzr')243 pip_mgr.check_package(DEV, 'python-distutils-extra', source='bzr+lp:python-distutils-extra#egg=python-distutils-extra')244 pip_mgr.check_package(DEV, 'indicator-cpufreq', source='bzr+lp:indicator-cpufreq#egg=indicator-cpufreq')245 sys_mgr.check_package(DEV, 'indicator-cpufreq')246 # clang-tidy247 if ctx.env.ENABLE_TEST:248 # clang-tidy is optional, let's install it on systems where we known that V8 is249 # available. On other systems it's up to the user to install it.250 if os_dist == 'ubuntu' and os_release >= Version('18.04'):251 sys_mgr.check_package(DEV, 'clang-tidy-8')252 # vmtest253 sys_mgr.check_package(VMTEST, 'qemu-system-x86')254 sys_mgr.check_package(VMTEST, 'qemu-block-extra')255 sys_mgr.check_package(VMTEST, 'libvirt-bin')256 pip_mgr.check_package(VMTEST, 'asyncssh')257 sys_mgr.check_package(VMTEST, 'sshpass')258 sys_mgr.check_package(VMTEST, 'openssh-client')259 pip_mgr.check_package(VMTEST, 'aiohttp')260 AptCacherNGBuilder(ctx).check(VMTEST, version='3.2')261 # pylint: enable=line-too-long262@conf263def check_virtual_env(ctx):264 ctx.start_msg('Checking for virtual environment')265 venvdir = os.environ.get('VIRTUAL_ENV', None)266 if not venvdir and os.path.isfile('.venv'):267 venvdir = open('.venv', 'r').readline().strip()268 if not venvdir:269 venvdir = ctx.options.venvdir270 if not venvdir:271 venvdir = DEFAULT_VENVDIR272 venvdir = os.path.abspath(venvdir)273 ctx.to_log("Using virtual env path %s" % venvdir)274 py_path = os.path.join(venvdir, 'bin', 'python')275 if not os.path.isfile(py_path):276 ctx.to_log("No virtual environment found, creating...")277 try:278 env_builder = venv.EnvBuilder(279 system_site_packages=False,280 with_pip=True)281 env_builder.create(venvdir)282 except BaseException as exc: # pylint: disable=broad-except283 shutil.rmtree(venvdir)284 ctx.fatal("Failed to create virtual env: %s: %s" % (type(exc).__name__, exc))285 # Always update PIP to something more recent than what ensurepip has installed. We need at286 # least 9.0 for 'pip list --format=json' to work.287 ctx.cmd_and_log(288 [os.path.join(venvdir, 'bin', 'pip'),289 '--disable-pip-version-check', 'install', '-U', 'pip>=9.0'],290 output=BOTH)291 ctx.to_log(" ok.")292 old_venvdir = None293 if os.path.isfile('.venv'):294 old_venvdir = open('.venv', 'r').readline().strip()295 if venvdir != old_venvdir:296 ctx.to_log("Creating .venv sentinel file...")297 with open('.venv', 'w') as fp:298 fp.write(venvdir)299 fp.write('\n')300 ctx.to_log(" ok.")301 ctx.env.VIRTUAL_ENV = venvdir302 ctx.env.PYTHON = [os.path.join(venvdir, 'bin', 'python')]303 ctx.environ['PATH'] = os.pathsep.join(304 [os.path.join(venvdir, 'bin')] + ctx.environ.get('PATH', '').split(os.pathsep))305 os.environ['VIRTUAL_ENV'] = venvdir306 os.environ['LD_LIBRARY_PATH'] = os.path.join(venvdir, 'lib')307 os.environ['PATH'] = os.pathsep.join(308 [os.path.join(venvdir, 'bin')] + os.environ.get('PATH', '').split(os.pathsep))309 # Make sure the site-packages from the venv are visible, even on the initial run of waf, when310 # the venv didn't exist yet when it was started.311 site_packages_path = os.path.join(312 ctx.env.VIRTUAL_ENV, 'lib',313 'python%d.%d' % (sys.version_info[0], sys.version_info[1]), 'site-packages')314 sys.path.insert(0, site_packages_path)315 ctx.end_msg(venvdir)316class PackageManager(object):317 def __init__(self, ctx):318 self._ctx = ctx319 self._packages = {}320 @property321 def packages(self):322 return sorted(self._packages.items())323 def is_installed(self, pkg):324 return pkg in self._packages325 def version(self, pkg):326 return self._packages[pkg]327 def split_spec(self, spec):328 if spec.startswith('<=') or spec.startswith('>=') or spec.startswith('=='):329 return spec[:2], spec[2:]330 if spec.startswith('<') or spec.startswith('>'):331 return spec[:1], spec[1:]332 return '==', spec333 def check_version(self, pkg, expected_spec):334 op, version = self.split_spec(expected_spec)335 return self.compare_versions(self.version(pkg), op, version)336 def compare_versions(self, v1, op, v2):337 raise NotImplementedError338 def update_packages(self):339 raise NotImplementedError340 def install_package(self, name, version=None, source=None):341 raise NotImplementedError342 def check_package(self, dep_type, name, version, source, message, allow_install):343 if dep_type >= DEV and not self._ctx.env.ENABLE_TEST:344 return345 if dep_type >= VMTEST and not self._ctx.env.ENABLE_VMTEST:346 return347 self._ctx.start_msg(message)348 need_install = False349 if not self.is_installed(name):350 self._ctx.to_log("Package is not installed")351 need_install = True352 self._ctx.end_msg("not found", 'YELLOW')353 else:354 self._ctx.to_log("Found installed version %s" % self.version(name))355 if version and not self.check_version(name, version):356 self._ctx.end_msg(self.version(name), 'YELLOW')357 self._ctx.to_log("Requirement '%s' not met, requires update" % version)358 need_install = True359 if need_install:360 if not allow_install:361 self._ctx.to_log("Not installing system package myself.")362 self._ctx.fatal("missing")363 if version:364 self._ctx.start_msg("Install '%s' (%s)" % (name, version))365 else:366 self._ctx.start_msg("Install '%s'" % name)367 self.install_package(name, version, source)368 self.update_packages()369 assert not version or self.check_version(name, version)370 self._ctx.end_msg(self.version(name))371class PipManager(PackageManager):372 def __init__(self, ctx):373 super().__init__(ctx)374 self.__pip_path = os.path.join(self._ctx.env.VIRTUAL_ENV, 'bin', 'pip')375 self.__pip_cmd = [self.__pip_path, '--disable-pip-version-check']376 def compare_versions(self, v1, op_name, v2):377 op = {378 '<=': operator.le,379 '>=': operator.ge,380 '<': operator.lt,381 '>': operator.gt,382 '==': operator.eq,383 }[op_name]384 return op(Version(v1), Version(v2))385 def update_packages(self):386 p = subprocess.run(387 self.__pip_cmd + ['list', '--format=json'],388 stdout=subprocess.PIPE, check=True)389 self._packages = {p['name']: p['version'] for p in json.loads(p.stdout.decode('utf-8'))}390 def get_pip_spec(self, name, version=None, source=None):391 if source:392 spec = source393 else:394 spec = name395 if version:396 op, version = self.split_spec(version)397 spec += op398 spec += version399 return spec400 def install_package(self, name, version=None, source=None):401 self._ctx.cmd_and_log(402 self.__pip_cmd + ['install', '-U', self.get_pip_spec(name, version, source)],403 output=BOTH)404 def check_package(self, dep_type, name, version=None, source=None):405 super().check_package(406 dep_type, name, version, source,407 "Checking pip package '%s'" % name,408 self._ctx.options.download)409 if dep_type == RUNTIME:410 self._ctx.env.append_value('RUNTIME_PIP_PACKAGES', [name])411class DebManager(PackageManager):412 def compare_versions(self, v1, op_name, v2):413 op = {414 '<=': 'le',415 '>=': 'ge',416 '<': 'lt',417 '>': 'gt',418 '==': 'eq',419 }[op_name]420 p = subprocess.run(['/usr/bin/dpkg', '--compare-versions', v1, op, v2])421 return p.returncode == 0422 def update_packages(self):423 p = subprocess.run(424 ['/usr/bin/dpkg-query', '--show', '--showformat', '${Package}\t${Version}\n'],425 stdout=subprocess.PIPE, check=True)426 self._packages.clear()427 for l in p.stdout.splitlines():428 l = l.decode('utf-8')429 pkg, version = l.split('\t')430 self._packages[pkg] = version431 def install_package(self, name, version=None, source=None):432 env = dict(os.environ)433 cmd = ['/usr/bin/sudo']434 if self._ctx.env.SSH_ASKPASS:435 env['SUDO_ASKPASS'] = self._ctx.env.SSH_ASKPASS[0]436 cmd += ['--askpass']437 else:438 cmd += ['--non-interactive']439 cmd += ['--', '/usr/bin/apt-get', '-q', '-y', 'install', name]440 self._ctx.cmd_and_log(cmd, output=BOTH, env=env)441 def check_package(self, dep_type, name, version=None):442 super().check_package(443 dep_type, name, version, None,444 "Checking system package '%s'" % name,445 self._ctx.options.install_system_packages)446class UnsupportedDistManager(PackageManager):447 def compare_versions(self, v1, op, v2):448 raise RuntimeError449 def update_packages(self):450 raise RuntimeError451 def install_package(self, name, version=None, source=None):452 raise RuntimeError453 def check_package(self, dep_type, name, version=None, source=None):454 pass455class ThirdPartyBuilder(object):456 def __init__(self, ctx, name, archive_ext):457 self._ctx = ctx458 self.name = name459 self.archive_ext = archive_ext460 def download_url(self, version):461 raise NotImplementedError462 def archive_name(self, version):463 return '%s-%s%s' % (self.name, version, self.archive_ext)464 def download(self, download_url, target_path):465 total_bytes = 0466 with urllib.request.urlopen(download_url) as fp_in:467 with open(target_path + '.partial', 'wb') as fp_out:...
test_pacmon.py
Source:test_pacmon.py
...8def test_initialization():9 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))10def test_pypi_monitoring_1():11 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))12 changes = p.check_package('pypi', 'ioc_fanger')13 assert len(changes) == 014def test_pypi_monitoring_2():15 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))16 changes = p.check_package('pypi', 'requests')17 assert len(changes) == 018def test_pypi_monitoring_3():19 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))20 changes = p.check_package('pypi', 'onemillion')21 assert len(changes) == 022def test_pypi_file_replacement():23 """Make sure file removal and addition is recorded correctly."""24 with open(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")), 'w+') as f:25 json.dump({26 "onemillion": {27 "abc": "123"28 }29 }, f)30 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))31 changes = p.check_package('pypi', 'onemillion')32 assert len(changes) == 333 assert len(changes['added_files']) == 834 assert len(changes['removed_files']) == 135 assert len(changes['changed_files']) == 036def test_pypi_file_change():37 """Make sure a file hash change is recorded correctly."""38 with open(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")), 'w+') as f:39 json.dump({40 "onemillion": {41 "onemillion/cli.py": "123"42 }43 }, f)44 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))45 changes = p.check_package('pypi', 'onemillion')46 assert len(changes) == 347 assert len(changes['added_files']) == 748 assert len(changes['removed_files']) == 049 assert len(changes['changed_files']) == 150@pytest.mark.npm51def test_npm_monitoring_1():52 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))53 changes = p.check_package('npm', 'spaces-ng')54 assert len(changes) == 055@pytest.mark.npm56def test_npm_file_replacement():57 """Make sure file removal and addition is recorded correctly."""58 with open(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")), 'w+') as f:59 json.dump({60 "spaces-ng": {61 "abc": "123"62 }63 }, f)64 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))65 changes = p.check_package('npm', 'spaces-ng')66 print("changes {}".format(changes))67 assert len(changes) == 368 assert len(changes['added_files']) == 2269 assert len(changes['removed_files']) == 170 assert len(changes['changed_files']) == 071@pytest.mark.npm72def test_npm_file_change():73 """Make sure a file hash change is recorded correctly."""74 with open(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")), 'w+') as f:75 json.dump({76 "spaces-ng": {77 "node_modules/spaces-ng/src/SpacesModule.d.ts": "123",78 "node_modules/spaces-ng/LICENSE": "abc"79 }80 }, f)81 p = pacmon.Pacmon(os.path.abspath(os.path.join(os.path.dirname(__file__), "./test_output.json")))82 changes = p.check_package('npm', 'spaces-ng')83 print("changes {}".format(changes))84 assert len(changes) == 385 assert len(changes['added_files']) == 2086 assert len(changes['removed_files']) == 087 assert len(changes['changed_files']) == 288@pytest.mark.npm89def test_dual_package_check():90 """Make sure packages are downloaded and stored properly."""91 p = pacmon.Pacmon()92 p.check_package('npm', 'spaces-ng')93 p.check_package('pypi', 'onemillion')94 with open(p.output_path, 'r') as f:95 hashes = json.load(f)96 assert 'spaces-ng' in hashes...
batch.py
Source:batch.py
1# -*- coding: utf-8 -*-2# Copyright (c) 2020, suganya and contributors3# For license information, please see license.txt4from __future__ import unicode_literals5import frappe6from frappe.model.document import Document7from frappe.utils import add_days8class Batch(Document):9 pass10@frappe.whitelist()11def get_end_date(name,check_package,expected_start_date):12 check_package = frappe.get_value('Check Package', {'name': check_package},["package_tat"])13 if expected_start_date:14 end_date = add_days(expected_start_date,check_package)15 frappe.errprint(end_date)16 return end_date17@frappe.whitelist()18def get_check_list(check_package):19 check_list = {}20 checks = frappe.get_all('Checks List', {'parent': check_package}, ['check_name', 'units'])21 return checks22@frappe.whitelist()23def get_cases(batch, no_of_case,expected_start_date):24 nc = {}25 for unit in range(int(no_of_case)):26 if frappe.db.count("Case", {'batch': batch}) < int(no_of_case):27 nc = frappe.new_doc("Case")28 nc.batch = batch29 nc.no_of_cases = str((unit+1))+"/"+no_of_case30 nc.date_of_initiating = expected_start_date31 nc.save(ignore_permissions=True)32 return nc33@frappe.whitelist()34def get_checks(check_package):35 check_list = {}36 checks = frappe.get_all('Checks List', {'parent': check_package}, ['check_name', 'units'])37 return checks38@frappe.whitelist()39def check_status(name, check_package):40 check_package = frappe.get_doc('Check Package', {'name': check_package})41 ch = []42 for c in check_package.checks_list:43 # frappe.errprint(c.check_name)44 checks = frappe.get_all(c.check_name, {"batch": name}, [45 'entry_status', 'report_status', 'verification_status', 'name'])46 # ch=frappe.get_doc("Case",name)47 # frappe.errprint(checks)48 for cs in checks:49 cj = cs["name"]50 sep = cj.split("-")51 ch.append({52 "checks": sep[0],53 "check_id": cs["name"],54 "check_status": cs["entry_status"],55 "verification_status": cs["verification_status"],56 "report_status": cs["report_status"]57 })...
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!!