Best Python code snippet using localstack_python
fab_release_test.py
Source:fab_release_test.py  
...25        sys.exit(1)26    else:27        return result28    29def do_run(command):30    result = run(command)31    if result.return_code != 0:32        print "Error running command: %s" %command33        shutdown()34        sys.exit(1)35    else:36        return result37        38def do_local(command, capture=True):39    result = local(command, capture)40    if result.return_code != 0:41        print "Error running command: %s" %command42        shutdown()43        sys.exit(1)44    else:45        return result46def pause():47    raw_input("--> Press Enter to continue...")48    49def shutdown():50    do_sudo("poweroff")51    time.sleep(45)52def test():53    x = do_sudo('airtime-check-system')54    print x.failed55    print x.succeeded56    print x.return_code57    58def download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file):59    if not os.path.exists(vdi_dir):60        os.makedirs(vdi_dir)61    62    if os.path.exists(os.path.join(vdi_dir, vm_vdi_file)):63        print "File %s already exists. No need to re-download" % os.path.join(vdi_dir, vm_vdi_file)64    else:65        print "File %s not found. Downloading" % vm_vdi_file66        tmpPath = do_local("mktemp", capture=True)67        do_local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_vdi_file, tmpPath))68        os.rename(tmpPath, os.path.join(vdi_dir, vm_vdi_file))69           70    if os.path.exists(os.path.join(xml_dir, vm_xml_file)):71        print "File %s already exists. No need to re-download" % os.path.join(xml_dir, vm_xml_file)72    else:73        do_local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_xml_file, os.path.join(xml_dir, vm_xml_file)))       74   75def create_fresh_os(vm_name, lucid=False, debian=False, icecast2_config=False):76    77    """78    remove known_hosts because if two virtual machines get the same ip address,79    then they will most likey have a different host key, and ssh will fail, warning80    about a possible man in the middle attack.81    """82    do_local("rm -f ~/.ssh/known_hosts")83    84    vm_vdi_file = '%s.vdi'%vm_name85    vm_xml_file = '%s.xml'%vm_name86    vdi_dir = os.path.expanduser('~/tmp/vms/%s'%vm_name)87    vdi_snapshot_dir = os.path.expanduser('~/tmp/vms/%s/Snapshots'%vm_name)88    xml_dir = os.path.expanduser('~/.VirtualBox')89    vm_xml_path = os.path.join(xml_dir, vm_xml_file)90            91    download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file)92        93    if not os.path.exists("%s/vm_registered"%vdi_dir):94        do_local("VBoxManage registervm %s"%os.path.join(xml_dir, vm_xml_file), capture=True)95        do_local('VBoxManage storagectl "%s" --name "SATA Controller" --add sata'%vm_name)96        do_local('VBoxManage storageattach "%s" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium %s'%(vm_name, os.path.join(vdi_dir, vm_vdi_file)))97        do_local("VBoxManage modifyvm %s --snapshotfolder %s"%(vm_name, vdi_snapshot_dir))98        do_local("VBoxManage snapshot %s take fresh_install"%vm_name)99        do_local("touch %s/vm_registered"%vdi_dir)100        101    do_local('VBoxManage snapshot %s restore fresh_install'%vm_name)102    103    do_local('VBoxManage modifyvm "%s" --bridgeadapter1 eth0'%vm_name)104    do_local('VBoxManage startvm %s'%vm_name)105    print "Please wait while attempting to acquire IP address"106        107    time.sleep(30)108    try_again = True109    while try_again:110        ret = do_local('VBoxManage --nologo guestproperty get "%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%vm_name, capture=True)111        triple = ret.partition(':')112        ip_addr = triple[2].strip(' \r\n')113        print "Address found %s"%ip_addr114        115        try_again = (len(ip_addr) == 0)116        time.sleep(1)117        118    env.hosts.append(ip_addr)119    env.host_string = ip_addr120    121    if lucid:122        print "Lucid detected - updating python virtualenv"123        do_sudo('apt-get update')124        do_sudo('apt-get install -y python-setuptools')125        do_sudo('wget http://apt.sourcefabric.org/pool/main/p/python-virtualenv/python-virtualenv_1.4.9-3_all.deb')126        do_sudo('dpkg -i python-virtualenv_1.4.9-3_all.deb')127        128        #supress rabbitmq bug that makes an upgrade warning pop-up even though it hasn't been 129        #installed before.130        do_sudo('echo "rabbitmq-server rabbitmq-server/upgrade_previous note" | debconf-set-selections')131        132    if debian:133        append('/etc/apt/sources.list', "deb http://backports.debian.org/debian-backports squeeze-backports main", use_sudo=True)134    if icecast2_config:135                print "Updating icecast2 setup settings"136                do_sudo('echo "icecast2 icecast2/icecast-setup  boolean false" | debconf-set-selections')137def ubuntu_lucid_32(fresh_os=True):138    if (fresh_os):139        create_fresh_os('Ubuntu_10.04_32', lucid=True)140def ubuntu_lucid_64(fresh_os=True):141    if (fresh_os):142        create_fresh_os('Ubuntu_10.04_64', lucid=True)143        144def ubuntu_maverick_32(fresh_os=True):145    if (fresh_os):146        create_fresh_os('Ubuntu_10.10_32')147def ubuntu_maverick_64(fresh_os=True):148    if (fresh_os):149        create_fresh_os('Ubuntu_10.10_64')150def ubuntu_natty_32(fresh_os=True):151    if (fresh_os):152        create_fresh_os('Ubuntu_11.04_32')153    154def ubuntu_natty_64(fresh_os=True):155    if (fresh_os):156        create_fresh_os('Ubuntu_11.04_64')157        158def ubuntu_oneiric_32(fresh_os=True):159    if (fresh_os):160        create_fresh_os('Ubuntu_11.10_32')161    162def ubuntu_oneiric_64(fresh_os=True):163    if (fresh_os):164        create_fresh_os('Ubuntu_11.10_64')165def ubuntu_precise_32(fresh_os=True):166    if (fresh_os):167        create_fresh_os('Ubuntu_12.04_32', icecast2_config=True)168    169def ubuntu_precise_64(fresh_os=True):170    if (fresh_os):171        create_fresh_os('Ubuntu_12.04_64', icecast2_config=True)172def ubuntu_quantal_32(fresh_os=True):173    if (fresh_os):174        create_fresh_os('Ubuntu_12.10_32', icecast2_config=True)175    176def ubuntu_quantal_64(fresh_os=True):177    if (fresh_os):178        create_fresh_os('Ubuntu_12.10_64', icecast2_config=True)179        180def ubuntu_raring_32(fresh_os=True):181    if (fresh_os):182        create_fresh_os('Ubuntu_13.04_32', icecast2_config=True)183    184def ubuntu_raring_64(fresh_os=True):185    if (fresh_os):186        create_fresh_os('Ubuntu_13.04_64', icecast2_config=True)187        188def ubuntu_saucy_32(fresh_os=True):189    if (fresh_os):190        create_fresh_os('Ubuntu_13.10_32', icecast2_config=True)191    192def ubuntu_saucy_64(fresh_os=True):193    if (fresh_os):194        create_fresh_os('Ubuntu_13.10_64', icecast2_config=True)195        196def debian_squeeze_32(fresh_os=True):197    if (fresh_os):198        create_fresh_os('Debian_Squeeze_32', debian=True)199        200def debian_squeeze_64(fresh_os=True):201    if (fresh_os):202        create_fresh_os('Debian_Squeeze_64', debian=True)203def debian_wheezy_32(fresh_os=True):204    if (fresh_os):205        create_fresh_os('Debian_Wheezy_32', icecast2_config=True)206    207def debian_wheezy_64(fresh_os=True):208    if (fresh_os):209        create_fresh_os('Debian_Wheezy_64', icecast2_config=True)210        211def airtime_180_tar():212    airtime_18x_tar("airtime", "1.8.0")213    214def airtime_181_tar():215    airtime_18x_tar("airtime", "1.8.1")216    217def airtime_182_tar():218    airtime_18x_tar("airtime-1.8.2", "1.8.2")219        220def airtime_18x_tar(root_dir, version):221    do_sudo('apt-get update')222    do_sudo('apt-get install -y --force-yes tar gzip unzip apache2 php5-pgsql libapache2-mod-php5 ' + \223        'php-pear php5-gd postgresql odbc-postgresql python python-configobj poc-streamer ' + \224        'lame daemontools daemontools-run python-mutagen libsoundtouch-ocaml sudo ' + \225        'libtaglib-ocaml libao-ocaml libmad-ocaml libesd0 icecast2 oggvideotools ' + \226        'libportaudio2 libsamplerate0 libcamomile-ocaml-dev ecasound php5-curl mpg123 ' + \227        'python-setuptools python-pip rabbitmq-server libvorbis-ocaml-dev libmp3lame-dev flac')228        229    do_sudo('pip install kombu')230    do_sudo('pip install poster')231    do_sudo('mkdir -p /tmp/pear/cache')232    do_sudo('pear channel-discover pear.phing.info || true')233    do_sudo('pear install phing/phing-2.4.2 || true')234    235    do_sudo('ln -sf /etc/apache2/mods-available/php5.* /etc/apache2/mods-enabled')236    do_sudo('ln -sf /etc/apache2/mods-available/rewrite.* /etc/apache2/mods-enabled')237    sed('/etc/php5/apache2/php.ini', ";upload_vdi_dir =", "upload_vdi_dir = /tmp", use_sudo=True)238    sed('/etc/php5/apache2/php.ini', ";date.timezone =", 'date.timezone = "America/Toronto"', use_sudo=True)239    put('airtime.vhost', '/etc/apache2/sites-available/airtime', use_sudo=True)240    do_sudo('a2dissite default')241    do_sudo('ln -sf /etc/apache2/sites-available/airtime /etc/apache2/sites-enabled/airtime')242    do_sudo('a2enmod rewrite')243    do_sudo('service apache2 restart')244    sed('/etc/default/icecast2', 'ENABLE=false', 'ENABLE=true', use_sudo=True)245    do_sudo('service icecast2 start')246    247    #these are do_sudo instead of do_run because in Debian we would be working with different home directores (/home/martin and /root in debian)248    do_sudo('wget http://downloads.sourceforge.net/project/airtime/%s/airtime-%s.tar.gz' % (version, version))249    do_sudo('tar xfz airtime-%s.tar.gz' % version)250    251    #do_sudo('cd ~/%s/install && php airtime-install.php' % root_dir)252    do_sudo('php ~/%s/install/airtime-install.php' % root_dir)253    #need to reboot because of daemon-tools.254    reboot(45)255    do_sudo('airtime-check-system')256    257def airtime_190_tar():258    #1.9.0 doesn't do apt-get update during install, and therefore the package index259    #files are not resynchronized. Need to do this here.260    do_sudo('apt-get update')261    262    do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.0/airtime-1.9.0.tar.gz')263    do_run('tar xfz airtime-1.9.0.tar.gz')264    do_sudo('cd /home/martin/airtime-1.9.0/install_full/ubuntu && ./airtime-full-install')265    266def airtime_191_tar():267    #1.9.0 doesn't do apt-get update during install, and therefore the package index268    #files are not resynchronized. Need to do this here.269    do_sudo('apt-get update')270    271    do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.1/airtime-1.9.1.tar.gz')272    do_run('tar xfz airtime-1.9.1.tar.gz')273    do_sudo('cd /home/martin/airtime-1.9.1/install_full/ubuntu && ./airtime-full-install')274    275def airtime_192_tar():276    #1.9.2 doesn't do apt-get update during install, and therefore the package index277    #files are not resynchronized. Need to do this here.278    do_sudo('apt-get update')279    280    do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.2/airtime-1.9.2.tar.gz')281    do_run('tar xfz airtime-1.9.2.tar.gz')282    do_sudo('cd /home/martin/airtime-1.9.2/install_full/ubuntu && ./airtime-full-install')283    284def airtime_193_tar():285    #1.9.3 doesn't do apt-get update during install, and therefore the package index286    #files are not resynchronized. Need to do this here.287    do_sudo('apt-get update')288    289    do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.3/airtime-1.9.3.tar.gz')290    do_run('tar xfz airtime-1.9.3.tar.gz')291    do_sudo('cd /home/martin/airtime-1.9.3/install_full/ubuntu && ./airtime-full-install')292    293def airtime_194_tar():294    #1.9.4 doesn't do apt-get update during install, and therefore the package index295    #files are not resynchronized. Need to do this here.296    do_sudo('apt-get update')297    298    do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.4/airtime-1.9.4.tar.gz')299    do_run('tar xfz airtime-1.9.4.tar.gz')300    do_sudo('cd /home/martin/airtime-1.9.4/install_full/ubuntu && ./airtime-full-install')301    302def airtime_195_tar():303    do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.5/airtime-1.9.5.tar.gz')304    do_run('tar xfz airtime-1.9.5.tar.gz')305    do_sudo('cd /home/martin/airtime-1.9.5/install_full/ubuntu && ./airtime-full-install')306def airtime_200_tar():307    do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.0/airtime-2.0.0.tar.gz')308    do_run('tar xfz airtime-2.0.0.tar.gz')309    do_sudo('cd /home/martin/airtime-2.0.0/install_full/ubuntu && ./airtime-full-install')310def airtime_201_tar():311    do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.1/airtime-2.0.1.tar.gz')312    do_run('tar xfz airtime-2.0.1.tar.gz')313    do_sudo('cd /home/martin/airtime-2.0.1/install_full/ubuntu && ./airtime-full-install')314def airtime_202_tar():315    do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.2/airtime-2.0.2.tar.gz')316    do_run('tar xfz airtime-2.0.2.tar.gz')317    do_sudo('cd /home/martin/airtime-2.0.2/install_full/ubuntu && ./airtime-full-install')318    319def airtime_203_tar():320    do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.3/airtime-2.0.3.tar.gz')321    do_run('tar xfz airtime-2.0.3.tar.gz')322    do_sudo('cd /home/martin/airtime-2.0.3/install_full/ubuntu && ./airtime-full-install')323    324def airtime_210_tar():325    do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.0/airtime-2.1.0.tar.gz')326    do_run('tar xfz airtime-2.1.0.tar.gz')327    do_sudo('cd /home/martin/airtime-2.1.0/install_full/ubuntu && ./airtime-full-install')328def airtime_211_tar():329    do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.1/airtime-2.1.1.tar.gz')330    do_run('tar xfz airtime-2.1.1.tar.gz')331    do_sudo('cd /home/martin/airtime-2.1.1/install_full/ubuntu && ./airtime-full-install')332def airtime_212_tar():333    do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.2/airtime-2.1.2.tar.gz')334    do_run('tar xfz airtime-2.1.2.tar.gz')335    do_sudo('cd /home/martin/airtime-2.1.2/install_full/ubuntu && ./airtime-full-install')336def airtime_213_tar():337    do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.3/airtime-2.1.3.tar.gz')338    do_run('tar xfz airtime-2.1.3.tar.gz')339    do_sudo('cd /home/martin/airtime-2.1.3/install_full/ubuntu && ./airtime-full-install')340def airtime_220_tar():341    do_run('wget http://downloads.sourceforge.net/project/airtime/2.2.0/airtime-2.2.0.tar.gz')342    do_run('tar xfz airtime-2.2.0.tar.gz')343    do_sudo('cd /home/martin/airtime-2.2.0/install_full/ubuntu && ./airtime-full-install')344def airtime_221_tar():345    do_run('wget http://downloads.sourceforge.net/project/airtime/2.2.1/airtime-2.2.1.tar.gz')  346    do_run('tar xfz airtime-2.2.1.tar.gz')347    do_sudo('cd /home/martin/airtime-2.2.1/install_full/ubuntu && ./airtime-full-install')348def airtime_230_tar():349    do_run('wget http://downloads.sourceforge.net/project/airtime/2.3.0/airtime-2.3.0.tar.gz')350    do_run('tar xfz airtime-2.3.0.tar.gz')351    do_sudo('cd /home/martin/airtime-2.3.0/install_full/ubuntu && ./airtime-full-install')352def airtime_231_tar():353    do_run('wget http://downloads.sourceforge.net/project/airtime/2.3.1/airtime-2.3.1-ga.tar.gz')354    do_run('tar xfz airtime-2.3.1-ga.tar.gz')355    do_sudo('cd /home/martin/airtime-2.3.1/install_full/ubuntu && ./airtime-full-install')356def airtime_240_tar():357    do_run('wget http://sourceforge.net/projects/airtime/files/2.4.0/airtime-2.4.0-ga.tar.gz')358    do_run('tar xfz airtime-2.4.0-ga.tar.gz')359    do_sudo('cd /home/martin/airtime-2.4.0/install_full/ubuntu && ./airtime-full-install')360def airtime_241_tar():361    do_run('wget http://sourceforge.net/projects/airtime/files/2.4.1/airtime-2.4.1-ga.tar.gz')362    do_run('tar xfz airtime-2.4.1-ga.tar.gz')363    do_sudo('cd /home/martin/Airtime-airtime-2.4.1-ga/install_full/ubuntu && ./airtime-full-install')364def airtime_latest_deb():365    append('/etc/apt/sources.list', "deb http://apt.sourcefabric.org/ lucid main", use_sudo=True)366    append('/etc/apt/sources.list', "deb http://archive.ubuntu.com/ubuntu/ lucid multiverse", use_sudo=True)367    do_sudo('apt-get update')368    do_sudo('apt-get install -y --force-yes sourcefabric-keyring')369    do_sudo('apt-get install -y postgresql')370    do_sudo('apt-get install -y icecast2')371    do_sudo('apt-get purge -y pulseaudio')372    do_sudo('apt-get install -y --force-yes airtime')373    374def airtime_git_branch(branch="2.5.x"):375    do_sudo('apt-get update')376    do_sudo('apt-get install -y git-core')377    do_run('git clone https://github.com/sourcefabric/Airtime.git ~/airtime_git')378    do_sudo('cd /home/martin/airtime_git && git checkout %s && install_full/ubuntu/airtime-full-install || true' % branch)379#def airtime_200():...test_runs.py
Source:test_runs.py  
...12        yield13    @pytest.mark.usefixtures("jump_line")14    def test_check_jsons(self):15        assert imports.check_jsons_ok() is True16    def do_run(self, name):17        return sr.load_from_json(name, print_schema=True)18    @pytest.mark.usefixtures("jump_line")19    def test_run_versions(self):20        assert self.do_run("versions")21    @pytest.mark.usefixtures("jump_line")22    def test_run_maps(self):23        assert self.do_run("maps")24    @pytest.mark.usefixtures("jump_line")25    def test_run_seasons(self):26        assert self.do_run("seasons")27    @pytest.mark.usefixtures("jump_line")28    def test_run_queues(self):29        assert self.do_run("queues")30    @pytest.mark.usefixtures("jump_line")31    def test_run_game_modes(self):32        assert self.do_run("gameModes")33    @pytest.mark.usefixtures("jump_line")34    def test_run_game_types(self):35        assert self.do_run("gameTypes")36    @pytest.mark.usefixtures("jump_line")37    def test_run_regions(self):38        assert self.do_run("regions")39    @pytest.mark.usefixtures("jump_line")40    def test_run_languages(self):41        assert self.do_run("languages")42    @pytest.mark.usefixtures("jump_line")43    def test_run_champions(self):44        assert self.do_run("champions")45    @pytest.mark.usefixtures("jump_line")46    def test_run_summoner_spells(self):47        assert self.do_run("summonerSpells")48    @pytest.mark.usefixtures("jump_line")49    def test_run_profile_icons(self):50        assert self.do_run("profileIcons")51    @pytest.mark.usefixtures("jump_line")52    def test_run_items(self):53        assert self.do_run("items")54    @pytest.mark.usefixtures("jump_line")55    def test_run_featured_matches(self):56        assert self.do_run("featuredMatches")57    @pytest.mark.usefixtures("jump_line")58    def test_run_summoner(self):59        assert self.do_run("summoner")60    @pytest.mark.usefixtures("jump_line")61    def test_run_spectator(self):62        assert self.do_run("spectator")63    @pytest.mark.usefixtures("jump_line")64    def test_run_matches(self):65        assert self.do_run("matches")66    @pytest.mark.usefixtures("jump_line")67    def test_run_match(self):68        assert self.do_run("match")69    @pytest.mark.usefixtures("jump_line")70    def test_run_match_timeline(self):71        assert self.do_run("matchTimeline")72    @pytest.mark.usefixtures("jump_line")73    def test_run_challenges(self):74        assert self.do_run("challenges")75    @pytest.mark.usefixtures("jump_line")76    def test_run_champions_masteries(self):...conftest.py
Source:conftest.py  
...8from _pytest.pytester import Testdir, RunResult9from rasa.utils.io import write_yaml_file10@pytest.fixture11def run(testdir: Testdir) -> Callable[..., RunResult]:12    def do_run(*args):13        args = ["rasa"] + list(args)14        return testdir.run(*args)15    return do_run16@pytest.fixture17def run_with_stdin(testdir: Testdir) -> Callable[..., RunResult]:18    def do_run(*args, stdin):19        args = ["rasa"] + list(args)20        return testdir.run(*args, stdin=stdin)21    return do_run22@pytest.fixture(scope="session")23def init_default_project(tmpdir_factory: TempdirFactory) -> str:24    path = tmpdir_factory.mktemp("agent").strpath25    os.environ["LOG_LEVEL"] = "ERROR"26    check_call(["rasa", "init", "--no-prompt"], cwd=path)27    return path28@pytest.fixture29def run_in_default_project_without_models(testdir: Testdir) -> Callable[..., RunResult]:30    os.environ["LOG_LEVEL"] = "ERROR"31    _set_up_initial_project(testdir)32    def do_run(*args):33        args = ["rasa"] + list(args)34        return testdir.run(*args)35    return do_run36@pytest.fixture37def run_in_default_project(38    testdir: Testdir, init_default_project: str39) -> Callable[..., RunResult]:40    os.environ["LOG_LEVEL"] = "ERROR"41    # makes sure we do not always retrain an initial model for every "new" project42    for file_name in os.listdir(init_default_project):43        full_file_name = os.path.join(init_default_project, file_name)44        if os.path.isfile(full_file_name):45            shutil.copy(full_file_name, str(testdir.tmpdir))46        else:47            shutil.copytree(full_file_name, str(testdir.tmpdir / file_name))48    def do_run(*args):49        args = ["rasa"] + list(args)50        result = testdir.run(*args)51        os.environ["LOG_LEVEL"] = "INFO"52        return result53    return do_run54def _set_up_initial_project(testdir: Testdir):55    # copy initial project files56    testdir.copy_example("rasa/cli/initial_project/actions.py")57    testdir.copy_example("rasa/cli/initial_project/credentials.yml")58    testdir.copy_example("rasa/cli/initial_project/domain.yml")59    testdir.copy_example("rasa/cli/initial_project/endpoints.yml")60    testdir.mkdir("data")61    testdir.copy_example("rasa/cli/initial_project/data")62    testdir.run("mv", "nlu.md", "data/nlu.md")...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!!
