Best Python code snippet using localstack_python
test_install_script.py
Source:test_install_script.py  
...14    logger_level=logging.DEBUG)15@pytest.mark.only_posix16def test_download_curl(file_server, tmp_path, agent_ssl_cert):17    with set_mock_context(agent_ssl_cert, tmp_path):18        run_install(['ln -s $(which curl) curl',19                     'PATH=$PWD',20                     'download http://127.0.0.1:{0} download.output'21                     .format(file_server.port)],22                    tmp_path,23                    cert=agent_ssl_cert)24    assert os.path.isfile('download.output')25@pytest.mark.only_posix26def test_download_wget(file_server, tmp_path, agent_ssl_cert):27    with set_mock_context(agent_ssl_cert, tmp_path):28        run_install(['ln -s $(which wget) wget',29                     'PATH=$PWD',30                     'download http://127.0.0.1:{0} download.output'31                     .format(file_server.port)],32                    tmp_path,33                    cert=agent_ssl_cert)34    assert os.path.isfile('download.output')35@pytest.mark.only_posix36def test_download_no_curl_or_wget(file_server, tmp_path, agent_ssl_cert):37    with set_mock_context(agent_ssl_cert, tmp_path):38        pytest.raises(39            exceptions.CommandExecutionException,40            run_install,41            ['PATH=$PWD',42             'download http://127.0.0.1:{0} download.output'43             .format(file_server.port)],44            tmp_path,45            cert=agent_ssl_cert,46        )47@pytest.mark.only_posix48def test_package_url_implicit(tmp_path, agent_ssl_cert):49    with set_mock_context(agent_ssl_cert, tmp_path):50        output = run_install(['package_url'], tmp_path, cert=agent_ssl_cert)51    assert '-agent.tar.gz' in output52@pytest.mark.only_posix53def test_package_url_explicit(tmp_path, agent_ssl_cert):54    with set_mock_context(agent_ssl_cert, tmp_path):55        output = run_install(56            ['package_url'],57            tmp_path,58            cert=agent_ssl_cert,59            extra_agent_params={60                'distro': 'one',61                'distro_codename': 'two'62            },63        )64    assert 'one-two-agent.tar.gz' in output65@pytest.mark.only_posix66def test_create_custom_env_file(tmp_path, agent_ssl_cert):67    with set_mock_context(agent_ssl_cert, tmp_path):68        run_install(69            ['create_custom_env_file'],70            tmp_path,71            cert=agent_ssl_cert,72            extra_agent_params={'env': {'one': 'one'}},73        )74    with open(os.path.join(str(tmp_path), 'custom_agent_env.sh')) as f:75        assert 'export one="one"' in f.read()76@pytest.mark.only_posix77def test_no_create_custom_env_file(tmp_path, agent_ssl_cert):78    with set_mock_context(agent_ssl_cert, tmp_path):79        run_install(['create_custom_env_file'], tmp_path, cert=agent_ssl_cert)80    assert not os.path.isfile(os.path.join(81        str(tmp_path), 'custom_agent_env.sh'))82@pytest.mark.only_posix83def test_create_ssl_cert(tmp_path, agent_ssl_cert):84    with set_mock_context(agent_ssl_cert, tmp_path):85        run_install(['add_ssl_cert'], tmp_path, cert=agent_ssl_cert)86    # basedir + node_id87    agent_dir = os.path.join(str(tmp_path), 'd')88    agent_ssl_cert.verify_remote_cert(agent_dir)89def test_add_ssl_func_not_rendered(tmp_path, agent_ssl_cert):90    with set_mock_context(agent_ssl_cert, tmp_path):91        install_script = _get_install_script(agent_ssl_cert,92                                             add_ssl_cert=False)93    expected = 'add_ssl_cert' if os.name == 'posix' else 'AddSSLCert'94    assert expected not in install_script95def test_install_is_rendered_by_default(tmp_path, agent_ssl_cert):96    with set_mock_context(agent_ssl_cert, tmp_path):97        install_script = _get_install_script(agent_ssl_cert)98    expected = 'install_agent' if os.name == 'posix' else 'InstallAgent'99    assert expected in install_script100def test_install_not_rendered_in_provided_mode(tmp_path, agent_ssl_cert):101    with set_mock_context(agent_ssl_cert, tmp_path,102                          install_method='provided'):103        install_script = _get_install_script(agent_ssl_cert)104    expected = 'install_agent' if os.name == 'posix' else 'InstallAgent'105    assert expected not in install_script106@pytest.mark.only_nt107def test_win_create_custom_env_file(tmp_path, agent_ssl_cert):108    with set_mock_context(agent_ssl_cert, tmp_path):109        run_install(['CreateCustomEnvFile'],110                    tmp_path,111                    windows=True,112                    cert=agent_ssl_cert,113                    extra_agent_params={'env': {'one': 'one'}})114    with open(os.path.join(str(tmp_path), 'custom_agent_env.bat')) as f:115        assert 'set one="one"' in f.read()116@pytest.mark.only_nt117def test_win_no_create_custom_env_file(tmp_path, agent_ssl_cert):118    with set_mock_context(agent_ssl_cert, tmp_path):119        run_install(['CreateCustomEnvFile'], tmp_path, windows=True,120                    cert=agent_ssl_cert)121    assert not os.path.isfile(os.path.join(122        str(tmp_path), 'custom_agent_env.bat'))123@pytest.mark.only_nt124def test_win_create_ssl_cert(tmp_path, agent_ssl_cert):125    with set_mock_context(agent_ssl_cert, tmp_path):126        run_install(['AddSSLCert'], tmp_path, windows=True,127                    cert=agent_ssl_cert)128    # basedir + node_id129    agent_dir = os.path.join(str(tmp_path), 'd')130    agent_ssl_cert.verify_remote_cert(agent_dir)131@contextmanager132def set_mock_context(agent_ssl_cert, tmp_path, **override_properties):133    node_properties = {134        'agent_config': {135            'user': getpass.getuser(),136            'install_method': 'init_script',137            'rest_host': '127.0.0.1',138            'windows': os.name == 'nt',139            'basedir': str(tmp_path),140        }141    }142    node_properties['agent_config'].update(**override_properties)143    current_ctx.set(mock_context(agent_ssl_cert, node_id='d',144                                 properties=node_properties))145    yield146    current_ctx.clear()147def _get_install_script(cert, add_ssl_cert=True, extra_agent_params=None):148    input_cloudify_agent = {149        'broker_ip': '127.0.0.1',150        'ssl_cert_path': cert.local_cert_path(),151    }152    if extra_agent_params:153        input_cloudify_agent.update(extra_agent_params)154    with patch.dict(os.environ, {constants.MANAGER_NAME: 'cloudify'}):155        script_builder = script._get_script_builder(156            cloudify_agent=input_cloudify_agent157        )158        return script_builder.install_script(add_ssl_cert=add_ssl_cert)159def run_install(commands, tmp_path, windows=False, extra_agent_params=None,160                cert=None):161    install_script = _get_install_script(162        cert, extra_agent_params=extra_agent_params)163    # Remove last line where main function is executed164    install_script = '\n'.join(install_script.split('\n')[:-1])165    if windows:166        install_script_path = os.path.abspath(os.path.join(167            str(tmp_path), 'install_script.ps1'))168    else:169        install_script_path = os.path.abspath(os.path.join(170            str(tmp_path), 'install_script.sh'))171    with open(install_script_path, 'w') as f:172        f.write(install_script)173        # Inject test commands...setup.py
Source:setup.py  
...8    result = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)9    output = result.decode("utf-8")10    output = output.strip()11    return output12def run_install(packages, method):13    if method == "sudo apt-get":14        method = "sudo apt-get -y"15    install_string = "{} install {}".format(method, packages)16    run_command(install_string)17def replace_kivy_config(username):18    kivy_config_path = "/home/{}/.kivy/config.ini".format(username)19    mimic_config_path = "/home/{}/Mimic/Pi/config.ini".format(username)20    print("\nUpdating the Kivy config.ini file.")21    shutil.copyfile(mimic_config_path, kivy_config_path)22def main():23    parser = argparse.ArgumentParser(description='ISS Mimic initial Pi setup tool.')24    parser.add_argument(25            '--skip_kivy', action='store_true',26            help='Skip installing the Kivy package and replacing the Kivy config file.',27            default=False)28    parser.add_argument(29            '--username', type=str,30            help='Specify Pi username (default is pi).',31            default="pi")32    args = parser.parse_args()33    print("\nBefore running this script, you should make sure your packages are updated.")34    print("If you still need to do that, Ctrl+C this script to exit and run the following:")35    print("sudo apt -y update; sudo apt -y upgrade\n")36    run_install("vim", "sudo apt-get")37    run_install("python3-numpy", "sudo apt-get")38    run_install("nodejs sqlite3", "sudo apt-get")39    run_command("curl https://www.npmjs.com/install.sh | sudo sh")40    run_install("lightstreamer-client", "npm")41    run_install("sqlite3", "npm")42    run_install("ephem pytz matplotlib autobahn twisted pyudev", "python3 -m pip")43    run_install("python3-mpltoolkits.basemap --fix-missing", "sudo apt-get")44    if not args.skip_kivy:45        print("\nInstalling Kivy requirements and package.")46        kivy_packages = "libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev pkg-config libgl1-mesa-dev libgles2-mesa-dev python3-setuptools libgstreamer1.0-dev git-core gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-omx gstreamer1.0-alsa python3-dev libmtdev-dev xclip xsel libjpeg-dev"47        run_install(kivy_packages, "sudo apt-get")48        run_install("--upgrade --user pip setuptools", "python3 -m pip")49        run_install("--upgrade --user Cython==0.29.10 pillow", "python3 -m pip")50        run_install("--user kivy", "python3 -m pip")51        run_command("python3 -c 'import kivy'") # run kivy init to create the config.ini file52        replace_kivy_config(args.username)53    else:54        print("\nSkipping Kivy setup.")55if __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!!
