Best Python code snippet using avocado_python
test_element.py
Source:test_element.py
...12 self.assertTrue(isinstance(widget, SearchableText))13 self.assertEqual(14 widget.get_plain_text(),15 u"content")16 def test_to_text(self):17 self.assertEqual(18 str(Text(b"content")), "content")19 self.assertEqual(20 str(Text(u"content")), "content")21 def test_markup_to_text(self):22 self.assertEqual(23 str(Text([("aaa", u"bbb"), u"ccc"])), "bbbccc")24class TestProp(unittest.TestCase):25 def test_widget(self):26 widget = Prop(u"key", u"value").widget(None)27 self.assertIsInstance(widget, SearchableText)28 self.assertEqual(29 widget.text,30 [('view-item key', u'key: '),31 ('view-item value', u'value')])32 def test_widget_with_padding(self):33 prop = Prop(u"key", u"value")34 prop.max_key_length = 535 self.assertEqual(36 prop.widget(None).text,37 [('view-item key', u'key : '),38 ('view-item value', u'value')])39 def test_to_text(self):40 self.assertEqual(41 str(Prop(u"key", u"value")),42 "key: value")43 def test_to_text_with_padding(self):44 prop = Prop(u"key", u"value")45 prop.max_key_length = 546 self.assertEqual(47 str(prop),48 "key : value")49class TestGroup(unittest.TestCase):50 def test_widget_with_title(self):51 widgets = Group(52 "title",53 items=[54 Text("first line"),55 Text("second line")]56 ).widgets(None)57 self.assertEqual(len(widgets), 3)58 self.assertTrue(isinstance(widgets[0], TitleWidget))59 self.assertTrue(isinstance(widgets[1], SearchableText))60 self.assertTrue(isinstance(widgets[2], SearchableText))61 def test_widget_without_title(self):62 widgets = Group(63 "title",64 items=[65 Text("first line"),66 Text("second line")],67 show_title=False).widgets(None)68 self.assertEqual(len(widgets), 2)69 self.assertTrue(isinstance(widgets[0], SearchableText))70 self.assertTrue(isinstance(widgets[1], SearchableText))71 def test_to_text(self):72 self.assertEqual(73 str(Group(u"title", items=[Text(u"first line"), Text(u"second line")],74 show_title=True)),75 u"title\nfirst line\nsecond line")76 self.assertEqual(77 str(Group(u"title", items=[Text(u"first line"), Text(u"second line")],78 show_title=False)),79 u"first line\nsecond line")80class TestPropsGroup(unittest.TestCase):81 def test_calc_key_length(self):82 props_group = PropsGroup(83 "title",84 items=[85 Prop("key", "value"),86 Prop("longkey", "value"),87 Prop("k", "value")]88 )89 self.assertEqual(props_group.items[0].max_key_length, 7)90 self.assertEqual(props_group.items[1].max_key_length, 7)91 self.assertEqual(props_group.items[2].max_key_length, 7)92 def test_empty_items(self):93 props_group = PropsGroup("title", items=[])94 self.assertEqual(len(props_group.items), 0)95class TestView(unittest.TestCase):96 def test_widget(self):97 view = View([98 Group("group1", [Text("content1")]),99 Group("group2", [Text("content2")])]100 )101 widget = view.widget(None)102 self.assertTrue(isinstance(widget, ContentWidget))103 contents = widget._w.body104 self.assertEqual(len(contents), 6)105 self.assertIsInstance(contents[0], TitleWidget)106 self.assertIsInstance(contents[1], SearchableText)107 self.assertIsInstance(contents[2], EmptyLine)108 self.assertIsInstance(contents[3], TitleWidget)109 self.assertIsInstance(contents[4], SearchableText)110 self.assertIsInstance(contents[5], EmptyLine)111 def test_empty_widget(self):112 view = View([])113 contents = view.widget(None)._w.body114 self.assertEqual(len(contents), 1)115 self.assertIsInstance(contents[0], EmptyLine)116 def test_actions(self):117 action = mock.Mock()118 controller = mock.Mock()119 context = mock.Mock()120 context.config.keys = dict()121 view = View([122 Group("group1", [Text("content1")]),123 Group("group2", [Text("content2")])],124 actions=dict(a=action)125 )126 widget = view.widget("message", controller=controller, context=context)127 widget.keypress((0, 0), "a")128 action.assert_called_with(controller, "message")129 self.assertEqual(130 widget.keypress((0, 0), "b"),131 "b")132 def test_to_text(self):133 view = View([134 Group("group1", [Text("content1")]),135 Group("group2", [Text("content2")])]136 )137 self.assertEqual(138 str(view),139 u"group1\ncontent1\n\ngroup2\ncontent2\n")140class TestTitleWidget(unittest.TestCase):141 def test_render(self):142 widget = TitleWidget("content")143 contents = [c for c in widget.render((7,)).content()]144 self.assertEqual(len(contents), 1)145 self.assertEqual(len(contents[0]), 1)146 self.assertEqual(contents[0][0], ("view-title", None, b"content"))...
test_to_text.py
Source:test_to_text.py
1import sys2from collections import deque3from dataclasses import dataclass4from itertools import chain5from textwrap import dedent6from typing import Callable7import pytest8from pytest_embrace.case import CaseTypeInfo9AssertionHelper = Callable[[str, str], None]10@pytest.fixture11def assert_valid_text_is() -> AssertionHelper:12 def do_assert(actual: str, expected: str) -> None:13 assert dedent(expected).lstrip("\n") == actual14 try:15 exec(actual, globals(), locals()) # check that it's valid16 except Exception as e:17 raise pytest.fail(f"Invalid python generated: {actual}") from e18 return do_assert19@dataclass20class GlobalsCase:21 x: float22 y: str23def test_to_text_globals(assert_valid_text_is: AssertionHelper) -> None:24 target = CaseTypeInfo(GlobalsCase, caller_name="the_case")25 text = target.to_text()26 assert_valid_text_is(27 text,28 """29 from pytest_embrace import CaseArtifact30 from tests.test_case.test_to_text import GlobalsCase31 x: float32 y: str33 def test(the_case: CaseArtifact[GlobalsCase]) -> None:34 ...35 """,36 )37@dataclass38class SomeCaseWithImports:39 foo: Callable[[deque], chain]40def test_to_text_builtins(assert_valid_text_is: AssertionHelper) -> None:41 target = CaseTypeInfo(SomeCaseWithImports, caller_name="the_case")42 assert_valid_text_is(43 target.to_text(),44 """45 from collections import deque46 from collections.abc import Callable47 from itertools import chain48 from pytest_embrace import CaseArtifact49 from tests.test_case.test_to_text import SomeCaseWithImports50 foo: Callable[[deque], chain]51 def test(the_case: CaseArtifact[SomeCaseWithImports]) -> None:52 ...53 """54 if sys.version_info >= (3, 9)55 else (56 """57 from collections import deque58 from itertools import chain59 from typing import Callable60 from pytest_embrace import CaseArtifact61 from tests.test_case.test_to_text import SomeCaseWithImports62 foo: Callable[[deque], chain]63 def test(the_case: CaseArtifact[SomeCaseWithImports]) -> None:64 ...65 """66 ),...
test_tsigkeyring.py
Source:test_tsigkeyring.py
...13 def test_from_text(self):14 """text keyring -> rich keyring"""15 rkeyring = dns.tsigkeyring.from_text(text_keyring)16 self.assertEqual(rkeyring, rich_keyring)17 def test_to_text(self):18 """text keyring -> rich keyring -> text keyring"""19 tkeyring = dns.tsigkeyring.to_text(rich_keyring)20 self.assertEqual(tkeyring, text_keyring)21 def test_from_and_to_text(self):22 """text keyring -> rich keyring -> text keyring"""23 rkeyring = dns.tsigkeyring.from_text(text_keyring)24 tkeyring = dns.tsigkeyring.to_text(rkeyring)...
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!!