How to use get_stdout method in avocado

Best Python code snippet using avocado_python

test_management_inactive_users.py

Source:test_management_inactive_users.py Github

copy

Full Screen

...55 last_login=days_91,56 date_joined=days_91)57 self.landing_page.save_revision(user=self.page_editor)58 self.stdout = StringIO()59 def get_stdout(self):60 return self.stdout.getvalue()61 def test_format_inactive_users_last_login(self):62 short_date = date_format(self.user_1.last_login,63 "SHORT_DATETIME_FORMAT")64 self.assertEqual(65 Command().format_inactive_users([self.user_1]),66 '\tuser_1: {}\n'.format(short_date)67 )68 def test_format_inactive_users_never_logged_in(self):69 self.assertEqual(70 Command().format_inactive_users([self.user_5]),71 '\tuser_5: never\n'72 )73 def test_get_inactive_users(self):74 """ Test that three users are listed for the default 90 period75 including one that last logged in 90 days ago. """76 call_command('inactive_users', stdout=self.stdout)77 self.assertIn("user_1", self.get_stdout())78 self.assertIn("user_2", self.get_stdout())79 self.assertIn("user_4", self.get_stdout())80 self.assertNotIn("üser_3", self.get_stdout())81 self.assertNotIn("user_5", self.get_stdout())82 self.assertNotIn("user_6", self.get_stdout())83 def test_get_inactive_users_87_days(self):84 """ Test that four users are listed for a custom 87 day period """85 call_command('inactive_users', period=87, stdout=self.stdout)86 self.assertIn("user_1", self.get_stdout())87 self.assertIn("user_2", self.get_stdout())88 self.assertIn("üser_3", self.get_stdout())89 self.assertIn("user_4", self.get_stdout())90 self.assertNotIn("user_5", self.get_stdout())91 self.assertNotIn("user_6", self.get_stdout())92 def test_get_inactive_users_92_days(self):93 """ Test that no users are listed for a custom 92 day period """94 call_command('inactive_users', period=92, stdout=self.stdout)95 self.assertNotIn("user_1", self.get_stdout())96 self.assertNotIn("user_2", self.get_stdout())97 self.assertNotIn("üser_3", self.get_stdout())98 self.assertNotIn("user_4", self.get_stdout())99 self.assertNotIn("user_5", self.get_stdout())100 self.assertNotIn("user_6", self.get_stdout())101 self.assertIn("No users are inactive", self.get_stdout())102 @override_settings(EMAIL_SUBJECT_PREFIX='[Prefix]')103 def test_sends_email(self):104 """ Test that mail.EmailMessage is called with the appropriate105 list of users """106 mail.outbox = []107 call_command('inactive_users',108 emails=['test@example.com'],109 stdout=self.stdout)110 # Outbox will have one system-owner email111 self.assertEqual(len(mail.outbox), 1)112 # Test the first (summary) email for inactive users only113 email = mail.outbox[0]114 self.assertEqual(email.to, ['test@example.com'])115 self.assertEqual(email.from_email, 'webmaster@localhost')116 self.assertIn('[Prefix]', email.subject)117 self.assertIn('Inactive users as of', email.subject)118 message = email.message().as_string()119 self.assertIn("user_1", message)120 self.assertIn("user_2", message)121 self.assertIn("user_4", message)122 self.assertNotIn("üser_3", message)123 self.assertNotIn("user_5", message)124 self.assertIn("test@example.com", self.get_stdout())125 def test_sends_email_when_warning(self):126 """ Test that mail.EmailMessage is called with the appropriate127 list of users """128 mail.outbox = []129 call_command('inactive_users',130 '--warn-users',131 stdout=self.stdout)132 # Should see 5 warnings since we're not passing `--deactivate`.133 self.assertEqual(len(mail.outbox), 5)134 def test_sends_email_when_deactivating(self):135 """ Test that mail.EmailMessage is called with the appropriate136 list of users """137 mail.outbox = []138 call_command('inactive_users',...

Full Screen

Full Screen

test_shell_cmd.py

Source:test_shell_cmd.py Github

copy

Full Screen

...12 while not shcmd.is_done():13 pass14 self.assertTrue(shcmd.is_done())15 self.assertEqual(shcmd.get_retcode(), 0)16 self.assertEqual(shcmd.get_stdout(), "5\n")17 #Assert out can be retrieved multiple times18 self.assertEqual(shcmd.get_stdout(), "5\n")19 self.assertEqual(shcmd.get_stderr(), "")20 def test_short_cmd(self):21 self.short_cmd_impl(None, None, None)22 with open("/tmp/short_cmd_test_out", "w") as stdout:23 with open("/tmp/short_cmd_test_err", "w") as stderr:24 self.short_cmd_impl(None, stdout, stderr)25 def test_same_file_handle(self):26 with open("/tmp/same_file_handle_test", "w") as stdout:27 cmd = "echo $((2 + 3)) && ls non_existing_file"28 cmd = shell_cmd.ShellCmd(cmd, None, stdout, stdout)29 while not cmd.is_done():30 pass31 self.assertEqual(cmd.get_stdout(), cmd.get_stdout())32 def test_abortable_cmd(self):33 cmd = "yes"34 shcmd = shell_cmd.ShellCmd(cmd)35 self.assertFalse(shcmd.is_done())36 self.assertIsNone(shcmd.get_retcode())37 for i in range(0,4):38 time.sleep(0.2)39 self.assertFalse(shcmd.is_done())40 shcmd.kill()41 self.assertTrue(shcmd.is_done())42 self.assertIsNotNone(shcmd.get_retcode())43 self.assertNotEqual(shcmd.get_retcode(), 0)44 self.assertEqual(shcmd.get_stderr(), "")45 def test_error_cmd(self):46 cmd = "ls /usr && ls non_existing_file"47 shcmd = shell_cmd.ShellCmd(cmd)48 while not shcmd.is_done():49 pass50 self.assertTrue(shcmd.is_done())51 self.assertIsNotNone(shcmd.get_retcode())52 self.assertNotEqual(shcmd.get_retcode(), 0)53 self.assertNotEqual(shcmd.get_stdout(), "")54 self.assertNotEqual(shcmd.get_stderr(), "")55if __name__ == '__main__':56 import rosunit...

Full Screen

Full Screen

git.py

Source:git.py Github

copy

Full Screen

1import subprocess as sp2def get_commit_hash():3 return get_stdout(["git rev-parse HEAD"])4def get_branch():5 return get_stdout(["git rev-parse --abbrev-ref HEAD"])6def set_new_branch(branch_name):7 get_stdout([f"git checkout -b {branch_name}"])8def set_branch(branch_name):9 get_stdout([f"git checkout {branch_name}"])10def push_new_branch(branch_name):11 get_stdout([f"git push -u origin {branch_name}"])12def get_stdout(cmd):13 proc = sp.run(cmd, shell=True, check=True, stdout=sp.PIPE, encoding="utf-8")...

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 avocado 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