How to use get_packages_info method in avocado

Best Python code snippet using avocado_python

install_utils_tests.py

Source:install_utils_tests.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2#3# This file is part of PyBuilder4#5# Copyright 2011-2020 PyBuilder Team6#7# Licensed under the Apache License, Version 2.0 (the "License");8# you may not use this file except in compliance with the License.9# You may obtain a copy of the License at10#11# http://www.apache.org/licenses/LICENSE-2.012#13# Unless required by applicable law or agreed to in writing, software14# distributed under the License is distributed on an "AS IS" BASIS,15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16# See the License for the specific language governing permissions and17# limitations under the License.18import unittest19from os.path import normcase as nc, join as jp20from pybuilder.core import (Project,21 Logger,22 Dependency,23 RequirementsFile)24from pybuilder.install_utils import install_dependencies25from pybuilder.pip_utils import PIP_MODULE_STANZA26from pybuilder.plugins.python.install_dependencies_plugin import initialize_install_dependencies_plugin27from test_utils import Mock, ANY, patch28__author__ = "Arcadiy Ivanov"29class InstallDependencyTest(unittest.TestCase):30 def setUp(self):31 self.project = Project("unittest", ".")32 self.project.set_property("dir_install_logs", "any_directory")33 self.project.set_property("dir_target", "/any_target_directory")34 self.logger = Mock(Logger)35 self.pyb_env = Mock()36 self.pyb_env.executable = ["exec"]37 self.pyb_env.site_paths = []38 self.pyb_env.env_dir = "a"39 self.pyb_env.execute_command.return_value = 040 initialize_install_dependencies_plugin(self.project)41 @patch("pybuilder.install_utils.tail_log")42 @patch("pybuilder.install_utils.open")43 @patch("pybuilder.install_utils.create_constraint_file")44 @patch("pybuilder.install_utils.get_packages_info", return_value={})45 def test_should_install_requirements_file_dependency(self, *_):46 dependency = RequirementsFile("requirements.txt")47 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")48 self.pyb_env.execute_command.assert_called_with(49 self.pyb_env.executable + PIP_MODULE_STANZA +50 ["install", "-r", "requirements.txt"],51 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)52 @patch("pybuilder.install_utils.tail_log")53 @patch("pybuilder.install_utils.open")54 @patch("pybuilder.install_utils.create_constraint_file")55 @patch("pybuilder.install_utils.get_packages_info", return_value={})56 def test_should_install_dependency_without_version(self, *_):57 dependency = Dependency("spam")58 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch",59 constraints_file_name="constraint_file")60 self.pyb_env.execute_command.assert_called_with(61 self.pyb_env.executable + PIP_MODULE_STANZA +62 ["install", "-c", nc(jp(self.pyb_env.env_dir, "constraint_file")), "spam"],63 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)64 @patch("pybuilder.install_utils.tail_log")65 @patch("pybuilder.install_utils.open")66 @patch("pybuilder.install_utils.create_constraint_file")67 @patch("pybuilder.install_utils.get_packages_info", return_value={})68 def test_should_install_dependency_without_version_on_windows_derivate(self, *_):69 dependency = Dependency("spam")70 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")71 self.pyb_env.execute_command.assert_called_with(72 self.pyb_env.executable + PIP_MODULE_STANZA + ["install", "spam"],73 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)74 @patch("pybuilder.install_utils.tail_log")75 @patch("pybuilder.install_utils.open")76 @patch("pybuilder.install_utils.create_constraint_file")77 @patch("pybuilder.install_utils.get_packages_info", return_value={})78 def test_should_install_dependency_insecurely_when_property_is_set(self, *_):79 dependency = Dependency("spam")80 self.project.set_property("install_dependencies_insecure_installation", ["spam"])81 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")82 self.pyb_env.execute_command.assert_called_with(83 self.pyb_env.executable + PIP_MODULE_STANZA +84 ["install", "--allow-unverified", "spam", "--allow-external", "spam", "spam"],85 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)86 @patch("pybuilder.install_utils.tail_log")87 @patch("pybuilder.install_utils.open")88 @patch("pybuilder.install_utils.create_constraint_file")89 @patch("pybuilder.install_utils.get_packages_info", return_value={})90 def test_should_install_dependency_securely_when_property_is_not_set_to_dependency(self, *_):91 dependency = Dependency("spam")92 self.project.set_property("install_dependencies_insecure_installation", ["some-other-dependency"])93 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch",94 constraints_file_name="constraint_file")95 self.pyb_env.execute_command.assert_called_with(96 self.pyb_env.executable + PIP_MODULE_STANZA +97 ["install", "-c", ANY, "--allow-unverified", "some-other-dependency",98 "--allow-external", "some-other-dependency", "spam"],99 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)100 # some-other-dependency might be a dependency of "spam"101 # so we always have to put the insecure dependencies in the command line :-(102 @patch("pybuilder.install_utils.tail_log")103 @patch("pybuilder.install_utils.open")104 @patch("pybuilder.install_utils.create_constraint_file")105 @patch("pybuilder.install_utils.get_packages_info", return_value={})106 def test_should_install_dependency_using_custom_index_url(self, *_):107 self.project.set_property("install_dependencies_index_url", "some_index_url")108 dependency = Dependency("spam")109 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")110 self.pyb_env.execute_command.assert_called_with(111 self.pyb_env.executable + PIP_MODULE_STANZA +112 ["install", "--index-url", "some_index_url", "spam"],113 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)114 @patch("pybuilder.install_utils.tail_log")115 @patch("pybuilder.install_utils.open")116 @patch("pybuilder.install_utils.create_constraint_file")117 @patch("pybuilder.install_utils.get_packages_info", return_value={})118 def test_should_use_extra_index_url_when_index_url_is_not_set(self, *_):119 self.project.set_property("install_dependencies_extra_index_url", "some_extra_index_url")120 dependency = Dependency("spam")121 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")122 self.pyb_env.execute_command.assert_called_with(123 self.pyb_env.executable + PIP_MODULE_STANZA +124 ["install", "--extra-index-url", "some_extra_index_url", "spam"],125 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)126 @patch("pybuilder.install_utils.tail_log")127 @patch("pybuilder.install_utils.open")128 @patch("pybuilder.install_utils.create_constraint_file")129 @patch("pybuilder.install_utils.get_packages_info", return_value={})130 def test_should_use_index_and_extra_index_url_when_index_and_extra_index_url_are_set(self, *_):131 self.project.set_property("install_dependencies_index_url", "some_index_url")132 self.project.set_property("install_dependencies_extra_index_url", "some_extra_index_url")133 dependency = Dependency("spam")134 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")135 self.pyb_env.execute_command.assert_called_with(136 self.pyb_env.executable + PIP_MODULE_STANZA +137 ["install", "--index-url", "some_index_url", "--extra-index-url", "some_extra_index_url", "spam"],138 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)139 @patch("pybuilder.install_utils.tail_log")140 @patch("pybuilder.install_utils.open")141 @patch("pybuilder.install_utils.create_constraint_file")142 @patch("pybuilder.install_utils.get_packages_info", return_value={})143 def test_should_install_dependency_with_version(self, *_):144 dependency = Dependency("spam", "0.1.2")145 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")146 self.pyb_env.execute_command.assert_called_with(147 self.pyb_env.executable + PIP_MODULE_STANZA +148 ["install", "spam>=0.1.2"],149 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)150 @patch("pybuilder.install_utils.tail_log")151 @patch("pybuilder.install_utils.open")152 @patch("pybuilder.install_utils.create_constraint_file")153 @patch("pybuilder.install_utils.get_packages_info", return_value={})154 def test_should_install_dependency_with_version_and_operator(self, *_):155 dependency = Dependency("spam", "==0.1.2")156 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")157 self.pyb_env.execute_command.assert_called_with(158 self.pyb_env.executable + PIP_MODULE_STANZA + ["install", "spam==0.1.2"],159 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)160 def test_should_install_dependency_with_wrong_version_and_operator(self):161 self.assertRaises(ValueError, Dependency, "spam", "~=1")162 @patch("pybuilder.install_utils.tail_log")163 @patch("pybuilder.install_utils.open")164 @patch("pybuilder.install_utils.create_constraint_file")165 @patch("pybuilder.install_utils.get_packages_info", return_value={})166 def test_should_install_dependency_with_url(self, *_):167 dependency = Dependency("spam", url="some_url")168 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")169 self.pyb_env.execute_command.assert_called_with(170 self.pyb_env.executable + PIP_MODULE_STANZA +171 ["install", "--force-reinstall", "some_url"],172 cwd=ANY, env=ANY, error_file_name=ANY, outfile_name=ANY, shell=False, no_path_search=True)173 @patch("pybuilder.install_utils.tail_log")174 @patch("pybuilder.install_utils.open")175 @patch("pybuilder.install_utils.create_constraint_file")176 @patch("pybuilder.install_utils.get_packages_info", return_value={})177 def test_should_install_dependency_with_url_even_if_version_is_given(self, *_):178 dependency = Dependency("spam", version="0.1.2", url="some_url")179 install_dependencies(self.logger, self.project, dependency, self.pyb_env, "install_batch")180 self.pyb_env.execute_command.assert_called_with(181 self.pyb_env.executable + PIP_MODULE_STANZA +182 ["install", "--force-reinstall", "some_url"],...

Full Screen

Full Screen

classes.py

Source:classes.py Github

copy

Full Screen

...83 version = version.split('#')[0].split(' ')[1]84 return Dependency(package, version, standard=False)85 else:86 return Dependency(package, version, standard=True)87 def get_packages_info(self, requirements_file=None):88 for item in pip('freeze').splitlines():89 yield self.extract_dependency(item)90 def __init__(self):91 if not PIP:92 raise PIPNotFound93 def get_results(self):94 requirements = {}95 installed_packages = {}96 for item in self.get_packages_info():97 requirements[item.name] = item98 for item in self.get_packages_info():99 installed_packages[item.name] = item100 for name, item in requirements.items():101 try:102 if item.standard:103 if item.version:104 if item.version == installed_packages[name].version:105 status = item.version106 else:107 status = installed_packages[name].version108 else:109 status = None110 else:111 # Non standard version number, check SVN or GIT path112 if item.version == installed_packages['%s-dev' % name.replace('-', '_')].version:...

Full Screen

Full Screen

modified_liccheck.py

Source:modified_liccheck.py Github

copy

Full Screen

2from liccheck.command_line import (Level, check_package, get_packages_info,3 group_by, parse_args, read_strategy)4def process(requirement_file, strategy, level=Level.STANDARD, no_deps=False):5 print('gathering licenses...')6 pkg_info = get_packages_info(requirement_file, no_deps)7 deps_mention = '' if no_deps else ' and dependencies'8 print('{} package{}{}.'.format(len(pkg_info),9 '' if len(pkg_info) <= 1 else 's',10 deps_mention))11 groups = group_by(pkg_info,12 functools.partial(check_package, strategy, level=level))13 packages = []14 for r, ps in groups.items():15 for p in ps:16 packages.append({17 'name': p['name'],18 'version': p['version'],19 'license': (p['licenses'] or ['UNKNOWN'])[0],20 'status': r...

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 avocado 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