Best Python code snippet using slash
test_color_strings.py
Source:test_color_strings.py
...10 self.assertEqual(11 colored.get_colored(), colorama.Fore.RED + orig + colorama.Fore.RESET)12 def test_get_formatter(self):13 f = ColorString.get_formatter("red")14 self.assert_colored(15 f("test"), colorama.Fore.RED + "test" + colorama.Fore.RESET, "test")16 def test_transformations(self):17 for modifier in [18 (lambda s: s.ljust(20)),19 ]:20 self.assertEqual(modifier(ColorString("string", "red")).get_colored(),21 ColorString(modifier("string"), "red").get_colored())22 def test_len(self):23 for x in ["test", "me", "here!!!"]:24 self.assertEqual(len(ColorString(x, "red")), len(x))25 self.assertEqual(len("hello" + ColorString(" there", "red")), len("hello there"))26 def test_formatting(self):27 orig = "value1=%s, value2=%s"28 values = (6, 7)29 orig_formatted = orig % values30 colored = ColorString(orig, 'red')31 colored_formatted = colored % values32 self.assert_colored(33 colored_formatted,34 colorama.Fore.RED + orig_formatted + colorama.Fore.RESET,35 orig_formatted36 )37 self.assertIsInstance(colored_formatted, ColorString)38 self.assertEqual(colored_formatted._color, 'red') # pylint: disable=protected-access39 self.assertEqual(colored_formatted._string, orig_formatted) # pylint: disable=protected-access40 def test_concatenation_postfix(self):41 self.assert_colored(42 ColorString('a', color='red') + 'b',43 colorama.Fore.RED + 'a' + colorama.Fore.RESET + 'b',44 'ab'45 )46 def test_concatenation_prefix(self):47 self.assert_colored(48 'a' + ColorString('b', color='red'),49 'a' + colorama.Fore.RED + 'b' + colorama.Fore.RESET,50 'ab'51 )52 def test_complex_concatenation(self):53 self.assert_colored(54 'this is ' +55 ColorString('a message', color='red') + ' to be colored',56 'this is ' + colorama.Fore.RED + 'a message' +57 colorama.Fore.RESET + ' to be colored',58 'this is a message to be colored'59 )60 def assert_colored(self, s, colored, uncolored):61 self.assertIsInstance(s, ColorStringBase)62 self.assertEqual(str(s), str(uncolored))63 self.assertEqual(repr(s), repr(uncolored))...
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!!