Best Python code snippet using autotest_python
metahost_scheduler_unittest.py
Source:metahost_scheduler_unittest.py
1#!/usr/bin/python2try:3 import autotest.common as common # pylint: disable=W06114except ImportError:5 import common # pylint: disable=W06116import unittest7from autotest.client.shared.test_utils import mock8from autotest.frontend import setup_django_environment # pylint: disable=W06119from autotest.frontend import setup_test_environment # pylint: disable=W061110from autotest.scheduler import metahost_scheduler, scheduler_models11class LabelMetahostSchedulerTest(unittest.TestCase):12 def setUp(self):13 self.god = mock.mock_god()14 self.scheduling_utility = self.god.create_mock_class(15 metahost_scheduler.HostSchedulingUtility, 'utility')16 self.metahost_scheduler = metahost_scheduler.LabelMetahostScheduler()17 def tearDown(self):18 self.god.unstub_all()19 def entry(self):20 return self.god.create_mock_class(scheduler_models.HostQueueEntry,21 'entry')22 def test_can_schedule_metahost(self):23 entry = self.entry()24 entry.meta_host = None25 self.assertFalse(self.metahost_scheduler.can_schedule_metahost(entry))26 entry.meta_host = 127 self.assert_(self.metahost_scheduler.can_schedule_metahost(entry))28 def test_schedule_metahost(self):29 entry = self.entry()30 entry.meta_host = 131 host = object()32 self.scheduling_utility.hosts_in_label.expect_call(1).and_return(33 [2, 3, 4, 5])34 # 2 is in ineligible_hosts35 (self.scheduling_utility.ineligible_hosts_for_entry.expect_call(entry)36 .and_return([2]))37 self.scheduling_utility.is_host_usable.expect_call(2).and_return(True)38 # 3 is unusable39 self.scheduling_utility.is_host_usable.expect_call(3).and_return(False)40 self.scheduling_utility.remove_host_from_label.expect_call(3, 1)41 # 4 is ineligible for the job42 self.scheduling_utility.is_host_usable.expect_call(4).and_return(True)43 (self.scheduling_utility.is_host_eligible_for_job.expect_call(4, entry)44 .and_return(False))45 # 5 runs46 self.scheduling_utility.is_host_usable.expect_call(5).and_return(True)47 (self.scheduling_utility.is_host_eligible_for_job.expect_call(5, entry)48 .and_return(True))49 self.scheduling_utility.remove_host_from_label.expect_call(5, 1)50 self.scheduling_utility.pop_host.expect_call(5).and_return(host)51 entry.set_host.expect_call(host)52 self.metahost_scheduler.schedule_metahost(entry,53 self.scheduling_utility)54 self.god.check_playback()55 def test_no_hosts(self):56 entry = self.entry()57 entry.meta_host = 158 self.scheduling_utility.hosts_in_label.expect_call(1).and_return(())59 (self.scheduling_utility.ineligible_hosts_for_entry.expect_call(entry)60 .and_return(()))61 self.metahost_scheduler.schedule_metahost(entry,62 self.scheduling_utility)63 self.god.check_playback()64if __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!!