How to use make_dummy_entry method in autotest

Best Python code snippet using autotest_python

base_job_unittest.py

Source:base_job_unittest.py Github

copy

Full Screen

...818 def decrement(self):819 self.indent -= 1820 self.indenter = stub_indenter()821 self.logger = base_job.status_logger(self.job, self.indenter)822 def make_dummy_entry(self, rendered_text, start=False, end=False,823 subdir=None):824 """Helper to make a dummy status log entry with custom rendered text.825 Helpful when validating the logging since it lets the test control826 the rendered text and so it doesn't depend on the exact formatting827 of a "real" status log entry.828 @param rendred_text: The value to return when rendering the entry.829 @param start: An optional value indicating if this should be the start830 of a nested group.831 @param end: An optional value indicating if this should be the end832 of a nested group.833 @param subdir: An optional value to use for the entry subdir field.834 @return: A dummy status log entry object with the given subdir field835 and a render implementation that returns rendered_text.836 """837 assert not start or not end # real entries would never be both838 class dummy_entry(object):839 def is_start(self):840 return start841 def is_end(self):842 return end843 def render(self):844 return rendered_text845 entry = dummy_entry()846 entry.subdir = subdir847 return entry848 def test_render_includes_indent(self):849 entry = self.make_dummy_entry('LINE0')850 self.assertEqual('LINE0', self.logger.render_entry(entry))851 self.indenter.increment()852 self.indenter.increment()853 self.assertEqual('\t\tLINE0', self.logger.render_entry(entry))854 def test_render_handles_start(self):855 entry = self.make_dummy_entry('LINE10', start=True)856 self.indenter.increment()857 self.assertEqual('\tLINE10', self.logger.render_entry(entry))858 def test_render_handles_end(self):859 entry = self.make_dummy_entry('LINE20', end=True)860 self.indenter.increment()861 self.indenter.increment()862 self.indenter.increment()863 self.assertEqual('\t\tLINE20', self.logger.render_entry(entry))864 def test_writes_toplevel_log(self):865 entries = [self.make_dummy_entry('LINE%d' % x) for x in xrange(3)]866 for entry in entries:867 self.logger.record_entry(entry)868 self.assertEqual('LINE0\nLINE1\nLINE2\n', open('status').read())869 def test_uses_given_filenames(self):870 os.mkdir('sub')871 self.logger = base_job.status_logger(self.job, self.indenter,872 global_filename='global.log',873 subdir_filename='subdir.log')874 self.logger.record_entry(self.make_dummy_entry('LINE1', subdir='sub'))875 self.logger.record_entry(self.make_dummy_entry('LINE2', subdir='sub'))876 self.logger.record_entry(self.make_dummy_entry('LINE3'))877 self.assertEqual('LINE1\nLINE2\nLINE3\n', open('global.log').read())878 self.assertEqual('LINE1\nLINE2\n', open('sub/subdir.log').read())879 self.assertFalse(os.path.exists('status'))880 self.assertFalse(os.path.exists('sub/status'))881 self.assertFalse(os.path.exists('subdir.log'))882 self.assertFalse(os.path.exists('sub/global.log'))883 def test_filenames_are_mutable(self):884 os.mkdir('sub2')885 self.logger = base_job.status_logger(self.job, self.indenter,886 global_filename='global.log',887 subdir_filename='subdir.log')888 self.logger.record_entry(self.make_dummy_entry('LINE1', subdir='sub2'))889 self.logger.record_entry(self.make_dummy_entry('LINE2'))890 self.logger.global_filename = 'global.log2'891 self.logger.subdir_filename = 'subdir.log2'892 self.logger.record_entry(self.make_dummy_entry('LINE3', subdir='sub2'))893 self.logger.record_entry(self.make_dummy_entry('LINE4'))894 self.assertEqual('LINE1\nLINE2\n', open('global.log').read())895 self.assertEqual('LINE1\n', open('sub2/subdir.log').read())896 self.assertEqual('LINE3\nLINE4\n', open('global.log2').read())897 self.assertEqual('LINE3\n', open('sub2/subdir.log2').read())898 def test_writes_subdir_logs(self):899 os.mkdir('abc')900 os.mkdir('123')901 self.logger.record_entry(self.make_dummy_entry('LINE1'))902 self.logger.record_entry(self.make_dummy_entry('LINE2', subdir='abc'))903 self.logger.record_entry(self.make_dummy_entry('LINE3', subdir='abc'))904 self.logger.record_entry(self.make_dummy_entry('LINE4', subdir='123'))905 self.assertEqual('LINE1\nLINE2\nLINE3\nLINE4\n', open('status').read())906 self.assertEqual('LINE2\nLINE3\n', open('abc/status').read())907 self.assertEqual('LINE4\n', open('123/status').read())908 def test_writes_no_subdir_when_disabled(self):909 os.mkdir('sub')910 self.logger.record_entry(self.make_dummy_entry('LINE1'))911 self.logger.record_entry(self.make_dummy_entry('LINE2', subdir='sub'))912 self.logger.record_entry(self.make_dummy_entry(913 'LINE3', subdir='sub_nowrite'), log_in_subdir=False)914 self.logger.record_entry(self.make_dummy_entry('LINE4', subdir='sub'))915 self.assertEqual('LINE1\nLINE2\nLINE3\nLINE4\n', open('status').read())916 self.assertEqual('LINE2\nLINE4\n', open('sub/status').read())917 self.assert_(not os.path.exists('sub_nowrite/status'))918 def test_indentation(self):919 self.logger.record_entry(self.make_dummy_entry('LINE1', start=True))920 self.logger.record_entry(self.make_dummy_entry('LINE2'))921 self.logger.record_entry(self.make_dummy_entry('LINE3', start=True))922 self.logger.record_entry(self.make_dummy_entry('LINE4'))923 self.logger.record_entry(self.make_dummy_entry('LINE5'))924 self.logger.record_entry(self.make_dummy_entry('LINE6', end=True))925 self.logger.record_entry(self.make_dummy_entry('LINE7', end=True))926 self.logger.record_entry(self.make_dummy_entry('LINE8'))927 expected_log = ('LINE1\n\tLINE2\n\tLINE3\n\t\tLINE4\n\t\tLINE5\n'928 '\tLINE6\nLINE7\nLINE8\n')929 self.assertEqual(expected_log, open('status').read())930 def test_multiline_indent(self):931 self.logger.record_entry(self.make_dummy_entry('LINE1\n blah\n'))932 self.logger.record_entry(self.make_dummy_entry('LINE2', start=True))933 self.logger.record_entry(934 self.make_dummy_entry('LINE3\n blah\n two\n'))935 self.logger.record_entry(self.make_dummy_entry('LINE4', end=True))936 expected_log = ('LINE1\n blah\nLINE2\n'937 '\tLINE3\n blah\n two\nLINE4\n')938 self.assertEqual(expected_log, open('status').read())939 def test_hook_is_called(self):940 entries = [self.make_dummy_entry('LINE%d' % x) for x in xrange(5)]941 recorded_entries = []942 def hook(entry):943 recorded_entries.append(entry)944 self.logger = base_job.status_logger(self.job, self.indenter,945 record_hook=hook)946 for entry in entries:947 self.logger.record_entry(entry)948 self.assertEqual(entries, recorded_entries)949 def tearDown(self):950 os.chdir(self.original_wd)951 shutil.rmtree(self.testdir, ignore_errors=True)952class test_job_tags(unittest.TestCase):953 def setUp(self):954 class stub_job(base_job.base_job):...

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