How to use analyze_perf_constraints method in autotest

Best Python code snippet using autotest_python

test_unittest.py

Source:test_unittest.py Github

copy

Full Screen

1#!/usr/bin/python2"""Unit Tests for autotest.client.common_lib.test"""3__author__ = 'gps@google.com (Gregory P. Smith)'4import unittest5from cStringIO import StringIO6import common7from autotest_lib.client.common_lib import error, test8from autotest_lib.client.common_lib.test_utils import mock9class TestTestCase(unittest.TestCase):10 class _neutered_base_test(test.base_test):11 """A child class of base_test to avoid calling the constructor."""12 def __init__(self, *args, **kwargs):13 class MockJob(object):14 pass15 class MockProfilerManager(object):16 def active(self):17 return False18 self.job = MockJob()19 self.job.profilers = MockProfilerManager()20 self.iteration = 021 self.before_iteration_hooks = []22 self.after_iteration_hooks = []23 def setUp(self):24 self.god = mock.mock_god()25 self.test = self._neutered_base_test()26 def tearDown(self):27 self.god.unstub_all()28class Test_base_test_execute(TestTestCase):29 # Test the various behaviors of the base_test.execute() method.30 def setUp(self):31 TestTestCase.setUp(self)32 self.god.stub_function(self.test, 'run_once_profiling')33 self.god.stub_function(self.test, 'postprocess')34 self.god.stub_function(self.test, 'process_failed_constraints')35 def test_call_run_once(self):36 # setup37 self.god.stub_function(self.test, 'drop_caches_between_iterations')38 self.god.stub_function(self.test, 'run_once')39 self.god.stub_function(self.test, 'postprocess_iteration')40 self.god.stub_function(self.test, 'analyze_perf_constraints')41 before_hook = self.god.create_mock_function('before_hook')42 after_hook = self.god.create_mock_function('after_hook')43 self.test.register_before_iteration_hook(before_hook)44 self.test.register_after_iteration_hook(after_hook)45 # tests the test._call_run_once implementation46 self.test.drop_caches_between_iterations.expect_call()47 before_hook.expect_call(self.test)48 self.test.run_once.expect_call(1, 2, arg='val')49 after_hook.expect_call(self.test)50 self.test.postprocess_iteration.expect_call()51 self.test.analyze_perf_constraints.expect_call([])52 self.test._call_run_once([], (1, 2), {'arg': 'val'})53 self.god.check_playback()54 def _expect_call_run_once(self):55 self.test._call_run_once.expect_call((), (), {})56 def test_execute_test_length(self):57 # test that test_length overrides iterations and works.58 self.god.stub_function(self.test, '_call_run_once')59 self._expect_call_run_once()60 self._expect_call_run_once()61 self._expect_call_run_once()62 self.test.run_once_profiling.expect_call(None)63 self.test.postprocess.expect_call()64 self.test.process_failed_constraints.expect_call()65 fake_time = iter(xrange(4)).next66 self.test.execute(iterations=1, test_length=3, _get_time=fake_time)67 self.god.check_playback()68 def test_execute_iterations(self):69 # test that iterations works.70 self.god.stub_function(self.test, '_call_run_once')71 iterations = 272 for _ in range(iterations):73 self._expect_call_run_once()74 self.test.run_once_profiling.expect_call(None)75 self.test.postprocess.expect_call()76 self.test.process_failed_constraints.expect_call()77 self.test.execute(iterations=iterations)78 self.god.check_playback()79 def _mock_calls_for_execute_no_iterations(self):80 self.test.run_once_profiling.expect_call(None)81 self.test.postprocess.expect_call()82 self.test.process_failed_constraints.expect_call()83 def test_execute_iteration_zero(self):84 # test that iterations=0 works.85 self._mock_calls_for_execute_no_iterations()86 self.test.execute(iterations=0)87 self.god.check_playback()88 def test_execute_profile_only(self):89 # test that profile_only=True works. (same as iterations=0)90 self._mock_calls_for_execute_no_iterations()91 self.test.execute(profile_only=True, iterations=2)92 self.god.check_playback()93 def test_execute_postprocess_profiled_false(self):94 # test that postprocess_profiled_run=False works95 self.god.stub_function(self.test, '_call_run_once')96 self._expect_call_run_once()97 self.test.run_once_profiling.expect_call(False)98 self.test.postprocess.expect_call()99 self.test.process_failed_constraints.expect_call()100 self.test.execute(postprocess_profiled_run=False, iterations=1)101 self.god.check_playback()102 def test_execute_postprocess_profiled_true(self):103 # test that postprocess_profiled_run=True works104 self.god.stub_function(self.test, '_call_run_once')105 self._expect_call_run_once()106 self.test.run_once_profiling.expect_call(True)107 self.test.postprocess.expect_call()108 self.test.process_failed_constraints.expect_call()109 self.test.execute(postprocess_profiled_run=True, iterations=1)110 self.god.check_playback()111if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful