Best Python code snippet using autotest_python
kvm_control_unittest.py
Source:kvm_control_unittest.py
...16 def setUp(self):17 self.god = mock.mock_god()18 def tearDown(self):19 self.god.unstub_all()20 def _mock_cpu_info(self, data):21 """22 Mock function for `autotest.client.utils.get_cpu_info` function23 """24 lines = StringIO(data).readlines()25 self.god.stub_with(base_utils, 'get_cpu_info',26 lambda: lines)27 def _mock_utils_system(self, command):28 """29 Mock function for `autotest.client.shared.utils.system`30 """31 self.god.stub_with(utils, 'system', lambda c: command)32 def test_get_kvm_arch(self):33 """34 Asserts for `autotest.client.kvm_control.get_kvm_arch`35 :returns: None36 """37 self._mock_cpu_info("GenuineIntel\nvmx")38 self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_intel')39 self._mock_cpu_info("AuthenticAMD\nsvm")40 self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_amd')41 self._mock_cpu_info("HygonGenuine\nsvm")42 self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_amd')43 self._mock_cpu_info("POWER7")44 self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_power7')45 self._mock_cpu_info("AuthenticAMD")46 self.assertRaises(error.TestError, kvm_control.get_kvm_arch)47 self._mock_cpu_info("HygonGenuine")48 self.assertRaises(error.TestError, kvm_control.get_kvm_arch)49 self._mock_cpu_info("InvalidCPU")50 self.assertRaises(error.TestError, kvm_control.get_kvm_arch)51 def test_load_kvm(self):52 """53 Asserts for `autotest.client.kvm_control.load_kvm`54 :returns: None55 """56 self._mock_utils_system(0)57 self._mock_cpu_info("GenuineIntel\nvmx")58 self.assertTrue(kvm_control.load_kvm() == 0)59 self._mock_utils_system(1)60 self._mock_cpu_info("GenuineIntel\nvmx")61 self.assertTrue(kvm_control.load_kvm() == 1)62 self._mock_utils_system(0)63 self._mock_cpu_info("POWER7")64 self.assertTrue(kvm_control.load_kvm() == 0)65 def test_unload_kvm(self):66 """67 Asserts for `autotest.client.kvm_control.unload_kvm`68 :returns: None69 """70 self._mock_utils_system(0)71 self._mock_cpu_info("GenuineIntel\nvmx")72 self.assertTrue(kvm_control.unload_kvm() == 0)73 self._mock_utils_system(1)74 self._mock_cpu_info("GenuineIntel\nvmx")75 self.assertTrue(kvm_control.load_kvm() == 1)76 self._mock_utils_system(0)77 self._mock_cpu_info("POWER7")78 self.assertTrue(kvm_control.load_kvm() == 0)79if __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!!