Best Python code snippet using tempest_python
kernel.py
Source: kernel.py
...16 elif current_mode in ["nvidia", "hybrid", None] and requested_mode == "intel":17 _nvidia_down(config)18def _nvidia_up(config):19 logger = get_logger()20 available_modules = _get_available_modules()21 logger.info("Available modules: %s", str(available_modules))22 _unload_nouveau(available_modules)23 switching_mode = config["optimus"]["switching"]24 if switching_mode == "bbswitch":25 _try_load_bbswitch(available_modules)26 _try_set_bbswitch_state("ON")27 elif switching_mode == "acpi_call":28 _try_load_acpi_call(available_modules)29 _try_set_acpi_call_state("ON")30 elif switching_mode == "custom":31 _try_custom_set_power_state("ON")32 if not pci.is_nvidia_visible():33 logger.info("Nvidia card not visible in PCI bus, rescanning")34 _try_rescan_pci()35 if config["optimus"]["pci_reset"] == "yes":36 _try_pci_reset(config, available_modules)37 if config["optimus"]["pci_power_control"] == "yes":38 _try_set_pci_power_state("on")39 _load_nvidia_modules(config, available_modules)40 41def _create_pm_udev_rule(keep_nvidia=True):42 _udev_rule_file = '/lib/udev/rules.d/50-pm-nvidia.rules'43 44 udev_rule_stub = '''# Remove NVIDIA USB xHCI Host Controller devices, if present45ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{remove}="1"46# Remove NVIDIA USB Type-C UCSI devices, if present47ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{remove}="1"48# Remove NVIDIA Audio devices, if present49ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{remove}="1"50%s51# Enable runtime PM for NVIDIA VGA/3D controller devices on driver bind52ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="auto"53ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="auto"54# Disable runtime PM for NVIDIA VGA/3D controller devices on driver unbind55ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="on"56ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="on"'''57 disable_nvidia_stub = '''58# Remove NVIDIA VGA/3D controller59ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", ATTR{remove}="1"60ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x038000", ATTR{remove}="1"61'''62 complete_stub = disable_nvidia_stub63 udev_rule = udev_rule_stub % (complete_stub)64 rule_fd = open(_udev_rule_file, 'w')65 rule_fd.write('%s\n' % (udev_rule))66 rule_fd.close()67 68def _nvidia_down(config):69 logger = get_logger()70 available_modules = _get_available_modules()71 logger.info("Available modules: %s", str(available_modules))72 73 _create_pm_udev_rule(False)74 75 _unload_nvidia_modules(available_modules)76 switching_mode = config["optimus"]["switching"]77 if switching_mode == "nouveau":78 _try_load_nouveau(config, available_modules)79 elif switching_mode == "bbswitch":80 _try_load_bbswitch(available_modules)81 _set_bbswitch_state("OFF")82 elif switching_mode == "acpi_call":83 _try_load_acpi_call(available_modules)84 _try_set_acpi_call_state("OFF")85 elif switching_mode == "custom":86 _try_custom_set_power_state("OFF")87 if config["optimus"]["pci_remove"] == "yes":88 if switching_mode == "nouveau" or switching_mode == "bbswitch":89 logger.warning("%s is selected, pci_remove option ignored.", switching_mode)90 else:91 logger.info("Removing Nvidia from PCI bus")92 _try_remove_pci()93 if config["optimus"]["pci_power_control"] == "yes":94 switching_mode = config["optimus"]["switching"]95 if switching_mode == "bbswitch" or switching_mode == "acpi_call":96 logger.warning("%s is enabled, pci_power_control option ignored.", switching_mode)97 elif config["optimus"]["pci_remove"] == "yes":98 logger.warning("pci_remove is enabled, pci_power_control option ignored.")99 else:100 _try_set_pci_power_state("auto")101def _get_available_modules():102 MODULES = ["nouveau", "bbswitch", "acpi_call", "nvidia", "nvidia_drm", "nvidia_modeset", "nvidia_uvm", "ipmi_devintf", "ipmi_msghandler"]103 return [module for module in MODULES if checks.is_module_available(module)]104def _load_nvidia_modules(config, available_modules):105 pat_value = _get_PAT_parameter_value(config)106 modeset_value = 1 if config["nvidia"]["modeset"] == "yes" else 0107 _load_module(available_modules, "nvidia", options="NVreg_UsePageAttributeTable=%d" % pat_value)108 _load_module(available_modules, "nvidia_drm", options="modeset=%d" % modeset_value)109def _load_nouveau(config, available_modules):110 modeset_value = 1 if config["intel"]["modeset"] == "yes" else 0111 _load_module(available_modules, "nouveau", options="modeset=%d" % modeset_value)112def _try_load_nouveau(config, available_modules):113 logger = get_logger()114 try:115 _load_nouveau(config, available_modules)...
python_unittests.py
Source: python_unittests.py
1#!/usr/bin/env python32"""3Unittests for Botan Python scripts.4Requires Python 3.5(C) 2017 Simon Warta (Kullo GmbH)6Botan is released under the Simplified BSD License (see license.txt)7"""8import sys9import unittest10sys.path.append("../..") # Botan repo root11from configure import AmalgamationHelper # pylint: disable=wrong-import-position12from configure import ModulesChooser # pylint: disable=wrong-import-position13class AmalgamationHelperTests(unittest.TestCase):14 def test_matcher_std_includes(self):15 self.assertEqual(AmalgamationHelper.is_unconditional_std_include("#include <string>"), "string")16 self.assertEqual(AmalgamationHelper.is_unconditional_std_include("#include <string> // comment"), "string")17 self.assertEqual(AmalgamationHelper.is_unconditional_std_include("#include <myfile.h>"), None)18 self.assertEqual(AmalgamationHelper.is_unconditional_std_include("#include <unistd.h>"), None)19 self.assertEqual(AmalgamationHelper.is_unconditional_std_include(" #include <string>"), None)20 def test_matcher_botan_include(self):21 self.assertEqual(AmalgamationHelper.is_botan_include("#include <botan/oids.h>"),22 "oids.h")23 self.assertEqual(AmalgamationHelper.is_botan_include("#include <botan/internal/socket.h>"),24 "internal/socket.h")25 self.assertEqual(AmalgamationHelper.is_botan_include("#include <botan/oids.h> // comment"),26 "oids.h")27 self.assertEqual(AmalgamationHelper.is_botan_include("#include <botan/internal/socket.h> // comment"),28 "internal/socket.h")29 self.assertEqual(AmalgamationHelper.is_botan_include(" #include <botan/oids.h>"),30 "oids.h")31 self.assertEqual(AmalgamationHelper.is_botan_include(" #include <botan/internal/socket.h>"),32 "internal/socket.h")33 self.assertEqual(AmalgamationHelper.is_botan_include("#include <string>"), None)34 self.assertEqual(AmalgamationHelper.is_botan_include("#include <myfile.h>"), None)35 self.assertEqual(AmalgamationHelper.is_botan_include("#include <unistd.h>"), None)36 def test_matcher_any_includes(self):37 self.assertEqual(AmalgamationHelper.is_any_include("#include <string>"), "string")38 self.assertEqual(AmalgamationHelper.is_any_include("#include <myfile.h>"), "myfile.h")39 self.assertEqual(AmalgamationHelper.is_any_include("#include <unistd.h>"), "unistd.h")40 self.assertEqual(AmalgamationHelper.is_any_include("#include <botan/oids.h>"),41 "botan/oids.h")42 self.assertEqual(AmalgamationHelper.is_any_include(" #include <string>"), "string")43 self.assertEqual(AmalgamationHelper.is_any_include(" #include <myfile.h>"), "myfile.h")44 self.assertEqual(AmalgamationHelper.is_any_include(" #include <unistd.h>"), "unistd.h")45 self.assertEqual(AmalgamationHelper.is_any_include(" #include <botan/oids.h>"),46 "botan/oids.h")47 self.assertEqual(AmalgamationHelper.is_any_include("#include <string> // comment"), "string")48 self.assertEqual(AmalgamationHelper.is_any_include("#include <myfile.h> // comment"), "myfile.h")49 self.assertEqual(AmalgamationHelper.is_any_include("#include <unistd.h> // comment"), "unistd.h")50 self.assertEqual(AmalgamationHelper.is_any_include("#include <botan/oids.h> // comment"),51 "botan/oids.h")52class ModulesChooserResolveDependencies(unittest.TestCase):53 def test_base(self):54 available_modules = set(["A", "B"])55 table = {56 "A": [],57 }58 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")59 self.assertTrue(ok)60 self.assertEqual(modules, set(["A"]))61 def test_no_dependencies_defined(self):62 available_modules = set(["A", "B"])63 table = {64 "A": [],65 }66 with self.assertRaises(KeyError):67 ModulesChooser.resolve_dependencies(available_modules, table, "B")68 available_modules = set(["A", "B"])69 table = {70 "A": ["B"],71 }72 with self.assertRaises(KeyError):73 ModulesChooser.resolve_dependencies(available_modules, table, "A")74 def test_add_dependency(self):75 available_modules = set(["A", "B"])76 table = {77 "A": ["B"],78 "B": []79 }80 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")81 self.assertTrue(ok)82 self.assertEqual(modules, set(["A", "B"]))83 def test_add_dependencies_two_levels(self):84 available_modules = set(["A", "B", "C"])85 table = {86 "A": ["B"],87 "B": ["C"],88 "C": []89 }90 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")91 self.assertTrue(ok)92 self.assertEqual(modules, set(["A", "B", "C"]))93 def test_circular(self):94 available_modules = set(["A", "B", "C"])95 table = {96 "A": ["B"],97 "B": ["C"],98 "C": ["A"]99 }100 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")101 self.assertTrue(ok)102 self.assertEqual(modules, set(["A", "B", "C"]))103 def test_not_available(self):104 available_modules = set(["A", "C"])105 table = {106 "A": ["B"],107 "B": ["C"],108 "C": ["A"]109 }110 ok, _ = ModulesChooser.resolve_dependencies(available_modules, table, "B")111 self.assertFalse(ok)112 def test_dependency_not_available(self):113 available_modules = set(["A", "C"])114 table = {115 "A": ["B"],116 "B": ["C"],117 "C": ["A"]118 }119 ok, _ = ModulesChooser.resolve_dependencies(available_modules, table, "A")120 self.assertFalse(ok)121 def test_dependency2_not_available(self):122 available_modules = set(["A", "B"])123 table = {124 "A": ["B"],125 "B": ["C"],126 "C": ["A"]127 }128 ok, _ = ModulesChooser.resolve_dependencies(available_modules, table, "A")129 self.assertFalse(ok)130 def test_dependency_choices(self):131 available_modules = set(["A", "B", "C"])132 table = {133 "A": ["B|C"],134 "B": [],135 "C": []136 }137 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")138 self.assertTrue(ok)139 self.assertTrue(modules == set(["A", "B"]) or modules == set(["A", "C"]))140 def test_dependency_prefer_existing(self):141 available_modules = set(["A", "B", "C"])142 table = {143 "A": ["C", "B|C"],144 "B": [],145 "C": []146 }147 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")148 self.assertTrue(ok)149 self.assertEqual(modules, set(["A", "C"]))150 def test_dependency_prefer_existing2(self):151 available_modules = set(["A", "B", "C"])152 table = {153 "A": ["B", "B|C"],154 "B": [],155 "C": []156 }157 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")158 self.assertTrue(ok)159 self.assertEqual(modules, set(["A", "B"]))160 def test_dependency_choices_impossible(self):161 available_modules = set(["A", "C"])162 table = {163 "A": ["B|C"],164 "B": [],165 "C": []166 }167 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")168 self.assertTrue(ok)169 self.assertEqual(modules, set(["A", "C"]))170 def test_dependency_choices_impossible2(self):171 available_modules = set(["A", "B"])172 table = {173 "A": ["B|C"],174 "B": [],175 "C": []176 }177 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "A")178 self.assertTrue(ok)179 self.assertEqual(modules, set(["A", "B"]))180 def test_deep(self):181 available_modules = set(["A", "B", "C", "E", "G"])182 table = {183 "A": ["B|C"],184 "B": ["D"],185 "C": ["E"],186 "D": [],187 "E": ["F|G"],188 "F": ["A", "B"],189 "G": ["A", "G"]190 }191 ok, modules = ModulesChooser.resolve_dependencies(available_modules, table, "G")192 self.assertTrue(ok)193 self.assertEqual(modules, set(["G", "A", "C", "E"]))194if __name__ == '__main__':195 unittest.TestCase.longMessage = True...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!