How to use test_error_message method in locust

Best Python code snippet using locust

test_cli_argparse.py

Source: test_cli_argparse.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Test CLI Argument Parser4"""5from unittest import TestCase6from ...exceptions import ScriptArgumentError7from ...exceptions import ScriptHelpArgumentError8# --------------------------------------------------------------------------- #9class Test_CliArgumentParser(TestCase):10 # ....................................................................... #11 def _makeOne(self, *args, **kwargs):12 from ...cli_argparse import CliArgumentParser13 return CliArgumentParser(*args, **kwargs)14 # ....................................................................... #15 def test_error(self):16 test_error_message = 'test_error_message'17 parser = self._makeOne()18 # test that error is raised19 self.assertRaises(ScriptArgumentError, parser.error, '')20 # test that correct error message is displayed21 self.assertRaisesRegexp(22 ScriptArgumentError,23 'test_error_message',24 parser.error,25 test_error_message)26 # ....................................................................... #27 def test_parse(self):28 test_return = "test_parse_args_return"29 def dummy_parse_args(*args, **kwargs):30 return test_return31 test_args = ['some_argument']32 parser = self._makeOne()33 self.assertEqual(34 parser.parse(args=test_args, _parse_args_method=dummy_parse_args),35 test_return)36 # ....................................................................... #37 def test_parse_no_arguments_specified_exception(self):38 test_args = []39 test_error_message = 'test_error_message'40 def dummy_format_help(*args, **kwargs):41 return test_error_message42 desired_error_message = "No script arguments specified\n\n%s" \43 % test_error_message44 parser = self._makeOne()45 self.assertRaisesRegexp(46 ScriptArgumentError,47 desired_error_message,48 parser.parse,49 args=test_args,50 _format_help_method=dummy_format_help)51 # ....................................................................... #52 def test_parse_help_argument_short_form_exception(self):53 test_args = ['-h']54 test_error_message = 'test_error_message'55 def dummy_format_help(*args, **kwargs):56 return test_error_message57 desired_error_message = test_error_message58 parser = self._makeOne()59 self.assertRaisesRegexp(60 ScriptHelpArgumentError,61 desired_error_message,62 parser.parse,63 args=test_args,64 _format_help_method=dummy_format_help)65 # ....................................................................... #66 def test_parse_help_argument_long_form_exception(self):67 test_args = ['-h']68 test_error_message = 'test_error_message'69 def dummy_format_help(*args, **kwargs):70 return test_error_message71 desired_error_message = test_error_message72 parser = self._makeOne()73 self.assertRaisesRegexp(74 ScriptHelpArgumentError,75 desired_error_message,76 parser.parse,77 args=test_args,78 _format_help_method=dummy_format_help)79 # ....................................................................... #80 def test_parse_help_argument_short_and_long_form_exception(self):81 test_args = ['-h', '--help']82 test_error_message = 'test_error_message'83 def dummy_format_help(*args, **kwargs):84 return test_error_message85 desired_error_message = test_error_message86 parser = self._makeOne()87 self.assertRaisesRegexp(88 ScriptHelpArgumentError,89 desired_error_message,90 parser.parse,91 args=test_args,92 _format_help_method=dummy_format_help)93# --------------------------------------------------------------------------- #94class DummyNamespace(object):95 pass96# --------------------------------------------------------------------------- #97class Test_CliArgumentParser_ArgListToDictAction(TestCase):98 # ....................................................................... #99 def _makeOne(self, *args, **kwargs):100 from ...cli_argparse import CliArgumentParser101 return CliArgumentParser.ArgListToDictAction(*args, **kwargs)102 # ....................................................................... #103 def test_ArgListToDictAction_callable(self):104 test_namespace = DummyNamespace()105 test_values = (("a", "b"), ("c", "d"))106 test_dest_variable = 'test_dest_variable'107 desired_dest_dict = {"a": "b", "c": "d"}108 action = self._makeOne(option_strings='', dest=test_dest_variable)109 # now call the action110 action(parser=None, namespace=test_namespace, values=test_values)111 self.assertDictEqual(112 getattr(test_namespace, test_dest_variable),113 desired_dest_dict)114 # ....................................................................... #115 def test_ArgListToDictAction_callable_duplicate_keys_overrides(self):116 test_namespace = DummyNamespace()117 test_values = (("a", "b"), ("c", "d"), ("a", "z"))118 test_dest_variable = 'test_dest_variable'119 desired_dest_dict = {"a": "z", "c": "d"}120 action = self._makeOne(option_strings='', dest=test_dest_variable)121 # now call the action122 action(parser=None, namespace=test_namespace, values=test_values)123 self.assertDictEqual(124 getattr(test_namespace, test_dest_variable),125 desired_dest_dict)126# --------------------------------------------------------------------------- #127class Test_SafeArgumentParser_split_argument(TestCase):128 # ....................................................................... #129 def _callFUT(self, test_list):130 from ...cli_argparse import CliArgumentParser131 parser = CliArgumentParser()132 return parser.split_argument(test_list)133 # ....................................................................... #134 def test_colon_separator(self):135 test_string = "a:b"136 desired_return_tuple = ("a", "b")137 self.assertTupleEqual(self._callFUT(test_string), desired_return_tuple)138 # ....................................................................... #139 def test_equal_separator(self):140 test_string = "a=b"141 desired_return_tuple = ("a", "b")142 self.assertTupleEqual(self._callFUT(test_string), desired_return_tuple)143 # ....................................................................... #144 def test_colon_separator_first(self):145 test_string = "a:=b"146 desired_return_tuple = ("a", "=b")147 self.assertTupleEqual(self._callFUT(test_string), desired_return_tuple)148 # ....................................................................... #149 def test_equal_separator_first(self):150 test_string = "a=:b"151 desired_return_tuple = ("a", ":b")152 self.assertTupleEqual(self._callFUT(test_string), desired_return_tuple)153 # ....................................................................... #154 def test_no_separator_exception(self):155 test_string = "ab"...

Full Screen

Full Screen

test_loggers_message.py

Source: test_loggers_message.py Github

copy

Full Screen

1import unittest2from rigelcore.loggers import MessageLogger3from unittest.mock import Mock, patch4class MessageLoggerTesting(unittest.TestCase):5 """6 Test suite for rigelcore.loggers.MessageLogger class.7 """8 @patch('rigelcore.loggers.message.rich_print')9 def test_log_error_message(self, print_mock: Mock) -> None:10 """11 Ensure that error messages are displayed with the proper style.12 """13 style = 'bold red'14 test_error_message = 'Test error message.'15 logger = MessageLogger()16 logger.error(test_error_message)17 print_mock.assert_called_once_with(f'[{style}]ERROR - {test_error_message}[/​{style}]')18 @patch('rigelcore.loggers.message.rich_print')19 def test_log_warning_message(self, print_mock: Mock) -> None:20 """21 Ensure that warning messages are displayed with the proper style.22 """23 style = 'bold yellow'24 test_error_message = 'Test warning message.'25 logger = MessageLogger()26 logger.warning(test_error_message)27 print_mock.assert_called_once_with(f'[{style}]WARNING - {test_error_message}[/​{style}]')28 @patch('rigelcore.loggers.message.rich_print')29 def test_log_info_message(self, print_mock: Mock) -> None:30 """31 Ensure that info messages are displayed with the proper style.32 """33 style = 'bold green'34 test_error_message = 'Test info message.'35 logger = MessageLogger()36 logger.info(test_error_message)37 print_mock.assert_called_once_with(f'[{style}]{test_error_message}[/​{style}]')38if __name__ == '__main__':...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Handle Dynamic Dropdowns In Selenium WebDriver With Java

Joseph, who has been working as a Quality Engineer, was assigned to perform web automation for the company’s website.

Top 17 Resources To Learn Test Automation

Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.

Migrating Test Automation Suite To Cypress 10

There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.

Website Testing: A Detailed Guide

Websites and web apps are growing in number day by day, and so are the expectations of people for a pleasant web experience. Even though the World Wide Web (WWW) was invented only in 1989 (32 years back), this technology has revolutionized the world we know back then. The best part is that it has made life easier for us. You no longer have to stand in long queues to pay your bills. You can get that done within a few minutes by visiting their website, web app, or mobile app.

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