Best Python code snippet using autotest_python
test_efi_selftest.py
Source:test_efi_selftest.py  
...17	u_boot_console.run_command(cmd='', wait_for_echo=False, wait_for_prompt=False);18	m = u_boot_console.p.expect(['resetting', 'U-Boot'])19	if m != 0:20		raise Exception('Reset failed during the EFI selftest')21	u_boot_console.restart_uboot();22@pytest.mark.buildconfigspec('cmd_bootefi_selftest')23@pytest.mark.buildconfigspec('of_control')24@pytest.mark.notbuildconfigspec('generate_acpi_table')25def test_efi_selftest_device_tree(u_boot_console):26	u_boot_console.run_command(cmd='setenv efi_selftest list')27	output = u_boot_console.run_command('bootefi selftest')28	assert '\'device tree\'' in output29	u_boot_console.run_command(cmd='setenv efi_selftest device tree')30	u_boot_console.run_command(cmd='setenv -f serial# Testing DT')31	u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)32	m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot'])33	if m != 0:34		raise Exception('Reset failed in \'device tree\' test')35	u_boot_console.restart_uboot();36@pytest.mark.buildconfigspec('cmd_bootefi_selftest')37def test_efi_selftest_watchdog_reboot(u_boot_console):38	u_boot_console.run_command(cmd='setenv efi_selftest list')39	output = u_boot_console.run_command('bootefi selftest')40	assert '\'watchdog reboot\'' in output41	u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')42	u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)43	m = u_boot_console.p.expect(['resetting', 'U-Boot'])44	if m != 0:45		raise Exception('Reset failed in \'watchdog reboot\' test')46	u_boot_console.restart_uboot();47@pytest.mark.buildconfigspec('cmd_bootefi_selftest')48def test_efi_selftest_text_input(u_boot_console):49	"""Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL50	:param u_boot_console: U-Boot console51	This function calls the text input EFI selftest.52	"""53	u_boot_console.run_command(cmd='setenv efi_selftest text input')54	output = u_boot_console.run_command(cmd='bootefi selftest',55					    wait_for_prompt=False)56	m = u_boot_console.p.expect(['To terminate type \'x\''])57	if m != 0:58		raise Exception('No prompt for \'text input\' test')59	u_boot_console.drain_console()60	u_boot_console.p.timeout = 50061	# EOT62	u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,63				   send_nl=False, wait_for_prompt=False)64	m = u_boot_console.p.expect(65		['Unicode char 4 \(unknown\), scan code 0 \(Null\)'])66	if m != 0:67		raise Exception('EOT failed in \'text input\' test')68	u_boot_console.drain_console()69	# BS70	u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,71				   send_nl=False, wait_for_prompt=False)72	m = u_boot_console.p.expect(73		['Unicode char 8 \(BS\), scan code 0 \(Null\)'])74	if m != 0:75		raise Exception('BS failed in \'text input\' test')76	u_boot_console.drain_console()77	# TAB78	u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,79				   send_nl=False, wait_for_prompt=False)80	m = u_boot_console.p.expect(81		['Unicode char 9 \(TAB\), scan code 0 \(Null\)'])82	if m != 0:83		raise Exception('BS failed in \'text input\' test')84	u_boot_console.drain_console()85	# a86	u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,87				   wait_for_prompt=False)88	m = u_boot_console.p.expect(89		['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])90	if m != 0:91		raise Exception('\'a\' failed in \'text input\' test')92	u_boot_console.drain_console()93	# UP escape sequence94	u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,95				   send_nl=False, wait_for_prompt=False)96	m = u_boot_console.p.expect(97		['Unicode char 0 \(Null\), scan code 1 \(Up\)'])98	if m != 0:99		raise Exception('UP failed in \'text input\' test')100	u_boot_console.drain_console()101	# Euro sign102	u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False,103				   send_nl=False, wait_for_prompt=False)104	m = u_boot_console.p.expect(['Unicode char 8364 \(\''])105	if m != 0:106		raise Exception('Euro sign failed in \'text input\' test')107	u_boot_console.drain_console()108	u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,109				   wait_for_prompt=False)110	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])111	if m != 0:112		raise Exception('Failures occurred during the EFI selftest')113	u_boot_console.restart_uboot();114@pytest.mark.buildconfigspec('cmd_bootefi_selftest')115def test_efi_selftest_text_input_ex(u_boot_console):116	"""Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL117	:param u_boot_console: U-Boot console118	This function calls the extended text input EFI selftest.119	"""120	u_boot_console.run_command(cmd='setenv efi_selftest extended text input')121	output = u_boot_console.run_command(cmd='bootefi selftest',122					    wait_for_prompt=False)123	m = u_boot_console.p.expect(['To terminate type \'CTRL\+x\''])124	if m != 0:125		raise Exception('No prompt for \'text input\' test')126	u_boot_console.drain_console()127	u_boot_console.p.timeout = 500128	# EOT129	u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,130				   send_nl=False, wait_for_prompt=False)131	m = u_boot_console.p.expect(132		['Unicode char 100 \\(\'d\'\\), scan code 0 \\(CTRL\\+Null\\)'])133	if m != 0:134		raise Exception('EOT failed in \'text input\' test')135	u_boot_console.drain_console()136	# BS137	u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,138				   send_nl=False, wait_for_prompt=False)139	m = u_boot_console.p.expect(140		['Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])141	if m != 0:142		raise Exception('BS failed in \'text input\' test')143	u_boot_console.drain_console()144	# TAB145	u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,146				   send_nl=False, wait_for_prompt=False)147	m = u_boot_console.p.expect(148		['Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])149	if m != 0:150		raise Exception('TAB failed in \'text input\' test')151	u_boot_console.drain_console()152	# a153	u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,154				   wait_for_prompt=False)155	m = u_boot_console.p.expect(156		['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])157	if m != 0:158		raise Exception('\'a\' failed in \'text input\' test')159	u_boot_console.drain_console()160	# UP escape sequence161	u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,162				   send_nl=False, wait_for_prompt=False)163	m = u_boot_console.p.expect(164		['Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])165	if m != 0:166		raise Exception('UP failed in \'text input\' test')167	u_boot_console.drain_console()168	# Euro sign169	u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False,170				   send_nl=False, wait_for_prompt=False)171	m = u_boot_console.p.expect(['Unicode char 8364 \(\''])172	if m != 0:173		raise Exception('Euro sign failed in \'text input\' test')174	u_boot_console.drain_console()175	# SHIFT+ALT+FN 5176	u_boot_console.run_command(cmd='\x1b\x5b\x31\x35\x3b\x34\x7e',177				   wait_for_echo=False, send_nl=False,178				   wait_for_prompt=False)179	m = u_boot_console.p.expect(180		['Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])181	if m != 0:182		raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')183	u_boot_console.drain_console()184	u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,185				   wait_for_prompt=False)186	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])187	if m != 0:188		raise Exception('Failures occurred during the EFI selftest')...refind-mkdefault
Source:refind-mkdefault  
1#!/usr/bin/env python32"""3Set rEFInd as the default boot loader, using Linux's efibootmgr tool.4Copyright (c) 2016 Roderick W. Smith5Authors:6  Roderick W. Smith <rodsmith@rodsbooks.com>7This program is free software: you can redistribute it and/or modify8it under the terms of the GNU General Public License version 3, or9(at your option) any later version, as published by the Free Software10Foundation.11This program is distributed in the hope that it will be useful,12but WITHOUT ANY WARRANTY; without even the implied warranty of13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the14GNU General Public License for more details.15You should have received a copy of the GNU General Public License16along with this program.  If not, see <http://www.gnu.org/licenses/>.17"""18import os19import shlex20import shutil21import sys22from subprocess import Popen, PIPE23from argparse import ArgumentParser24def discover_data():25    """Extract boot entry and boot order information.26    :returns:27        boot_entries, boot_order28    """29    command = "efibootmgr -v"30    bootinfo_bytes = (Popen(shlex.split(command), stdout=PIPE)31                      .communicate()[0])32    bootinfo = (bootinfo_bytes.decode(encoding="utf-8", errors="ignore")33                .splitlines())34    boot_entries = {}35    boot_order = []36    if len(bootinfo) > 1:37        for s in bootinfo:38            if "BootOrder" in s:39                try:40                    boot_order = s.split(":")[1].replace(" ", "").split(",")41                except IndexError:42                    pass43            else:44                # On Boot#### lines, #### is characters 4-8....45                hex_value = s[4:8]46                # ....and the description starts at character 1047                name = s[10:]48                try:49                    # In normal efibootmgr output, only Boot#### entries50                    # have characters 4-8 that can be interpreted as51                    # hex values, so this will harmlessly error out on all52                    # but Boot#### entries....53                    int(hex_value, 16)54                    boot_entries[hex_value] = name55                except ValueError:56                    pass57    return boot_entries, boot_order58def add_unordered_entry(boot_entries, boot_order, label):59    """Find a rEFInd boot_entry and add it to the boot_order list.60    Run if the boot_order list includes no rEFInd entry, in the61    hopes of finding an existing rEFInd boot_entry that can be62    used.63    :param boot_entries:64        Dictionary of boot entries, with string (hex-encoded number) as65        key and description as value66    :param boot_order:67        List of boot numbers as strings, in boot order68    :param label:69        String used to identify rEFInd entry in efibootmgr output70    :returns:71        True if an entry was added, False otherwise72    """73    added = False74    for boot_num, description in boot_entries.items():75        if label.lower() in description.lower():76            print("Adding Boot{} from boot options list.".format(boot_num))77            boot_order.insert(0, boot_num)78            added = True79    return added80def set_refind_first(boot_entries, boot_order, label):81    """Adjust boot_order so that rEFInd is first.82    :param boot_entries:83        Dictionary of boot entries, with string (hex-encoded number) as84        key and description as value85    :param boot_order:86        List of boot numbers as strings, in boot order87    :param label:88        String used to identify rEFInd entry in efibootmgr output89    :returns:90        * -1 if order already OK91        * 0 if order adjusted92        * 3 if label was not found in available entries93    """94    first_refind_number = i = -195    retval = 096    found_first_refind = ""97    show_multiple_warning = True98    for entry in boot_order:99        i += 1100        if label.lower() in boot_entries[entry].lower():101            if found_first_refind:102                if show_multiple_warning:103                    print("Found multiple {} entries! The earliest in the boot order will be made".format(label))104                    print("the default, but this may not be what you want. Manually checking with")105                    print("efibootmgr is advisable!\n")106                    show_multiple_warning = False107            else:108                found_first_refind = entry109                first_refind_number = i110    if first_refind_number == -1:111        if not add_unordered_entry(boot_entries, boot_order, label):112            print("{} was not found in the boot options list!".format(label))113            print("You should create a {} entry with efibootmgr or by re-installing".format(label))114            print("(with refind-install, for example)")115            retval = 3116    elif first_refind_number == 0:117        print("{} is already the first entry".format(label))118        retval = -1119    elif first_refind_number > 0:120        del boot_order[first_refind_number]121        boot_order.insert(0, found_first_refind)122        print("{} is not the first boot entry; adjusting....".format(label))123    return retval124def save_changes(boot_order):125    """Save an altered boot_order.126    :param boot_order:127        List of boot numbers as strings, in boot order128    :returns:129        0 if there were no problems, 1 otherwise130    """131    retval = 0132    order_string = ",".join(boot_order)133    command = "efibootmgr -o {}".format(order_string)134    print("Setting a boot order of {}".format(order_string))135    try:136        Popen(shlex.split(command), stdout=PIPE).communicate()[0]137    except:138        print("An error occurred setting the new boot order!")139        retval = 1140    return retval141def main():142    """Set rEFInd as the default boot option."""143    description = "Sets rEFInd as the default EFI boot option"144    parser = ArgumentParser(description=description)145    parser.add_argument("-L", "--label",146                        default="rEFInd",147                        help=("The label used to identify rEFInd (default=rEFInd)"))148    args = parser.parse_args()149    if sys.platform != "linux":150        print("This program is useful only under Linux; exiting!")151        return(4)152    if shutil.which("efibootmgr") is None:153        print("The efibootmgr utility is not installed; exiting!")154        return(4)155    if not os.geteuid() == 0:156        print("This program must be run as root (or via sudo); exiting!")157        return(4)158    retval = 0159    boot_entries, boot_order = discover_data()160    if boot_entries == {}:161        print("No EFI boot entries are available. This may indicate a firmware problem.")162        retval = 2163    if boot_order == []:164        print("The EFI BootOrder variable is not available. This may indicate a firmware")165        print("problem.")166    if (retval == 0):167        changed = set_refind_first(boot_entries, boot_order, args.label)168        if (changed == 0):169            retval = save_changes(boot_order)170        else:171            print("No changes saved.")172            if changed > 0:173                retval = changed174    else:175        print("No changes saved.")176    return(retval)177if __name__ == '__main__':...Navbar.js
Source:Navbar.js  
1import React from "react";2import "../App.css";3import * as ReactBootStrap from "react-bootstrap";4import { BrowserRouter as Router, Link } from "react-router-dom";5const NavBar = () => {6  return (7    <div className="App">8      <ReactBootStrap.Navbar9        collapseOnSelect10        expand="xl"11        bg="danger"12        variant="dark"13        className="nava"14      >15        <ReactBootStrap.Navbar.Brand href="#home">16          THICC BOIS HOURS17        </ReactBootStrap.Navbar.Brand>18        <ReactBootStrap.Navbar.Toggle aria-controls="responsive-navbar-nav" />19        <ReactBootStrap.Navbar.Collapse id="responsive-navbar-nav">20          <ReactBootStrap.Nav className="mr-auto">21            <Link to="/Features">22              <ReactBootStrap.Nav.Link href="#features">23                Features24              </ReactBootStrap.Nav.Link>25            </Link>26            <Link to="/Pricing">27              <ReactBootStrap.Nav.Link href="#pricing">28                Pricing29              </ReactBootStrap.Nav.Link>30            </Link>31            <ReactBootStrap.NavDropdown32              title="YEET"33              id="collasible-nav-dropdown"34            >35              <ReactBootStrap.NavDropdown.Item href="#action/3.1">36                Action37              </ReactBootStrap.NavDropdown.Item>38              <ReactBootStrap.NavDropdown.Item href="#action/3.2">39                Another action40              </ReactBootStrap.NavDropdown.Item>41              <ReactBootStrap.NavDropdown.Item href="#action/3.3">42                Something43              </ReactBootStrap.NavDropdown.Item>44              <ReactBootStrap.NavDropdown.Divider />45              <ReactBootStrap.NavDropdown.Item href="#action/3.4">46                Separated link47              </ReactBootStrap.NavDropdown.Item>48            </ReactBootStrap.NavDropdown>49          </ReactBootStrap.Nav>50          <ReactBootStrap.Nav>51            <Link to="/Moredeets">52              <ReactBootStrap.Nav.Link href="#deets">53                More deets54              </ReactBootStrap.Nav.Link>55            </Link>56            <Link to="/Dankmemes">57              <ReactBootStrap.Nav.Link eventKey={2} href="#memes">58                Dank memes59              </ReactBootStrap.Nav.Link>60            </Link>61          </ReactBootStrap.Nav>62        </ReactBootStrap.Navbar.Collapse>63      </ReactBootStrap.Navbar>64    </div>65  );66};...handle-middlewares.test.js
Source:handle-middlewares.test.js  
...32  }33  const modules = [34    { reducer: reducers, middleware: middlewares }35  ]36  const app = boot(initialState, modules)37  app.then(({action, store}) => {38    assert.equal(39      store.getState().foo,40      'baz',41      'Middleware for the AFTER_BOOT action.'42    )43    assert.equal(44      store.getState().faa,45      'boo',46      'Middleware for the AFTER_AFTER_BOOT action.'47    )48    assert.end()49  })50})51test('Middlewares should can create singletons at BOOT', assert => {52  const AFTER_BOOT = 'AFTER_BOOT'53  const afterBootAction = createAction(AFTER_BOOT)54  let count = 055  const moduleA = {56    middleware: {57      [BOOT]: store => {58        count = count + 159        return next => action => next(action)60      }61    }62  }63  const moduleB = {64    middleware: {65      [AFTER_BOOT]: store => {66        count = count + 167        return next => action => next(action)68      }69    }70  }71  const modules = [moduleA, moduleB]72  boot({}, modules).then(({ store }) => {73    store.dispatch(afterBootAction())74    store.dispatch(afterBootAction())75    store.dispatch(afterBootAction())76    assert.equal(count, 2, 'Shoud pass two times')77    assert.end()78  })...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!!
