How to use install_module method in lisa

Best Python code snippet using lisa_python

tests.py

Source:tests.py Github

copy

Full Screen

1"""2Test that ``PipInstall`` is a ``Command``.3The ``distutils`` package defines what is required by a ``Command``4inside of the source code (see *distutils/cmd.py:_Command*). The5tests in this module verify that ``setupext.pip.PipInstall`` meets6the requirements described below.7``command_name``8 string returned from the ``get_command_name()`` method9``initialize_options()``10 provide default values for all options; may be customized by11 setup script, by options from config file(s), or by command-line12 options13``finalize_options()``14 decide on the final values for all options; this is called15 after all possible intervention from the outside world16 (command-line, option file, etc.) has been processed17``run()``18 run the command: do whatever it is we're here to do,19 controlled by the command's various option values20"""21from distutils import dist, errors22import atexit23import os24import tempfile25try:26 from unittest import mock27except ImportError:28 import mock29import setuptools30from setupext import pip31########################################################################32# setupext.pip.PipInstall33########################################################################34def should_define_command_name():35 assert pip.PipInstall.command_name is not None36def should_define_description():37 assert pip.PipInstall.description is not None38def should_define_default_for_each_option():39 distribution = mock.Mock(spec=dist.Distribution)40 distribution.verbose = mock.sentinel.verbose41 command = pip.PipInstall(distribution)42 for long_opt, short_opt, desc in pip.PipInstall.user_options:43 attr_name = long_opt.replace('-', '_').rstrip('=')44 attr_value = getattr(command, attr_name, mock.sentinel.unspecified)45 assert attr_value is not mock.sentinel.unspecified, (46 'attribute for option {0} was not found'.format(long_opt))47@mock.patch('setupext.pip.install')48def should_implement_setuptools_command_protocol(install_module):49 pip_command = install_module.InstallCommand()50 pip_command.run = mock.Mock()51 pip_command.cmd_opts = mock.MagicMock()52 install_module.InstallCommand.return_value = pip_command53 setuptools.setup(54 name='testing-setup',55 cmdclass={'requirements': pip.PipInstall},56 script_name='setup.py',57 script_args=[58 'requirements',59 '--requirement-file', 'requirements.txt',60 '--find-links', 'http://cheese-shop.local/links',61 '--index-url', 'http://cheese-shop.local/simple',62 '--pre',63 '--no-use-wheel',64 ],65 )66 pip_command.cmd_opts.parser.parse_args.assert_called_with([67 '-r', 'requirements.txt',68 '-f', 'http://cheese-shop.local/links',69 '-i', 'http://cheese-shop.local/simple',70 '--no-use-wheel',71 '--pre',72 ])73@mock.patch('setupext.pip.install')74def should_default_to_installing_package_requirements(install_module):75 pip_command = install_module.InstallCommand()76 pip_command.run = mock.Mock()77 pip_command.cmd_opts = mock.MagicMock()78 install_module.InstallCommand.return_value = pip_command79 setuptools.setup(80 name='testing-setup',81 cmdclass={'requirements': pip.PipInstall},82 script_name='setup.py',83 script_args=['requirements'],84 install_requires=[85 'docopt==0.6.1',86 'requests==2.3.0',87 ],88 )89 pip_command.cmd_opts.parser.parse_args.assert_called_with(90 ['docopt==0.6.1', 'requests==2.3.0'])91@mock.patch.object(pip, 'install')92def should_raise_setup_error_when_pip_import_fails(_):93 pip.install = None94 command = pip.PipInstall(dist.Distribution())95 try:96 command.run()97 except Exception as exc:98 assert isinstance(exc, errors.DistutilsSetupError)99 else:100 raise AssertionError('should have raised DistutilsSetupError')101@mock.patch('setupext.pip.install')102def should_do_nothing_without_install_requires(install_module):103 setuptools.setup(104 name='testing-setup',105 cmdclass={'requirements': pip.PipInstall},106 script_name='setup.py',107 script_args=['requirements'],108 )109 assert not install_module.InstallCommand.called110@mock.patch('setupext.pip.install')111def should_install_test_requirements_when_instructed_to(install_module):112 pip_command = install_module.InstallCommand()113 pip_command.run = mock.Mock()114 pip_command.cmd_opts = mock.MagicMock()115 install_module.InstallCommand.return_value = pip_command116 setuptools.setup(117 name='testing-setup',118 cmdclass={'requirements': pip.PipInstall},119 script_name='setup.py',120 script_args=[121 'requirements',122 '--install-test-requirements',123 ],124 tests_require=['tox==1.7.2'],125 )126 pip_command.cmd_opts.parser.parse_args.assert_called_with(127 ['tox==1.7.2'])128@mock.patch('setupext.pip.install')129def should_install_requirements_for_specified_extra(install_module):130 pip_command = install_module.InstallCommand()131 pip_command.run = mock.Mock()132 pip_command.cmd_opts = mock.MagicMock()133 install_module.InstallCommand.return_value = pip_command134 setuptools.setup(135 name='testing-setup',136 cmdclass={'requirements': pip.PipInstall},137 script_name='setup.py',138 script_args=[139 'requirements',140 '--install-extra-requirements=doc',141 ],142 extras_require={'doc': ['sphinx']}143 )144 pip_command.cmd_opts.parser.parse_args.assert_called_with(['sphinx'])145@mock.patch('setupext.pip.install')146def should_not_install_when_extra_does_not_exist(install_module):147 setuptools.setup(148 name='testing-setup',149 cmdclass={'requirements': pip.PipInstall},150 script_name='setup.py',151 script_args=[152 'requirements',153 '--install-extra-requirements=doc',154 ],155 extras_require={'not doc': []},156 )157 assert not install_module.InstallCommand.called158@mock.patch('setupext.pip.install')159def should_not_install_when_no_extras_require(install_module):160 setuptools.setup(161 name='testing-setup',162 cmdclass={'requirements': pip.PipInstall},163 script_name='setup.py',164 script_args=[165 'requirements',166 '--install-extra-requirements=doc',167 ],168 )169 assert not install_module.InstallCommand.called170########################################################################171# setupext.pip.read_requirements_from_file172########################################################################173def should_read_complex_requirements_file():174 fd, name = tempfile.mkstemp()175 atexit.register(os.unlink, name)176 os.write(fd, '\n'.join([177 '# this comment is ignored',178 ' --always-unzip # ignored',179 '-Z',180 'Unsafe_Name>1',181 '-i ignored/index/url',182 '--index-url=ignored/url',183 '-f ignored-links-path',184 '--find-links=ignored',185 'requests==1.2.3',186 'illegal name ignored',187 ]).encode('utf-8'))188 requirements = pip.read_requirements_from_file(name)189 assert (190 requirements[0] in ['Unsafe-Name>1', 'Unsafe_Name>1']191 ), 'Unsafe name not adjusted'192 assert requirements[1] == 'requests==1.2.3', 'Simple dependency broken'...

Full Screen

Full Screen

install_or_skip_dependencies.py

Source:install_or_skip_dependencies.py Github

copy

Full Screen

1import sys2from continuous_integration import utils3def install_or_skip_dependencies():4 def install_module(command: str, process_name: str) -> int:5 returncode = utils.run_process(command, process_name)6 if returncode != utils.RETURN_CODE_OK:7 sys.exit(-1)8 return returncode9 # TODO: Use dataclass and loop it for DRY10 black_version = "20.8b1"11 coverage_version = "5.3.1"12 mypy_version = "0.790"13 pylint_version = "2.6.0"14 xenon_version = "0.7.1"15 returncode = install_module("pip install pipenv", "pipenv")16 returncode = install_module(f"pipenv install black=={black_version}", "black")17 returncode = install_module("pipenv install codecov", "codecov")18 returncode = install_module(19 f"pipenv install coverage=={coverage_version}", "coverage"20 )21 returncode = install_module(f"pipenv install mypy=={mypy_version}", "mypy")22 returncode = install_module(f"pipenv install pylint=={pylint_version}", "pylint")23 returncode = install_module(f"pipenv install xenon=={xenon_version}", "xenon")...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...12 settings = yaml.load(open('settings.yaml'))13 bot = IRCBot(settings['nick'], settings['user'], settings['realname'])14 for network, server in settings['servers'].items():15 bot.connect(network, **server)16 bot.install_module(ChannelModule, channels=settings['channels'])17 bot.install_module(PermissionModule)18 bot.install_module(AutoOPModule)19 bot.install_module(TitleModule)20 bot.install_module(CalcModule)21 bot.install_module(CodeForcesModule)22 bot.install_module(AdminModule)23 bot.install_module(DynamicModuleLoaderModule)...

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