Best Python code snippet using autotest_python
test_entry.py
Source:test_entry.py
...6class TestParseEntry(unittest.TestCase):7 maxDiff = None8 def setUp(self):9 self.parser = FluentParser(with_spans=False)10 def test_simple_message(self):11 input = """\12 foo = Foo13 """14 output = {15 "comment": None,16 "value": {17 "elements": [18 {19 "span": None,20 "type": "TextElement",21 "value": "Foo"22 }23 ],24 "span": None,25 "type": "Pattern"26 },27 "attributes": [],28 "type": "Message",29 "span": None,30 "id": {31 "span": None,32 "type": "Identifier",33 "name": "foo"34 }35 }36 message = self.parser.parse_entry(dedent_ftl(input))37 self.assertEqual(message.to_json(), output)38 def test_ignore_attached_comment(self):39 input = """\40 # Attached Comment41 foo = Foo42 """43 output = {44 "comment": None,45 "value": {46 "elements": [47 {48 "span": None,49 "type": "TextElement",50 "value": "Foo"51 }52 ],53 "span": None,54 "type": "Pattern"55 },56 "attributes": [],57 "type": "Message",58 "id": {59 "name": "foo",60 "span": None,61 "type": "Identifier"62 },63 "span": None,64 "type": "Message"65 }66 message = self.parser.parse_entry(dedent_ftl(input))67 self.assertEqual(message.to_json(), output)68 def test_return_junk(self):69 input = """\70 # Attached Comment71 junk72 """73 output = {74 "content": "junk\n",75 "annotations": [76 {77 "arguments": ["="],78 "code": "E0003",79 "message": "Expected token: \"=\"",80 "span": {81 "end": 23,82 "start": 23,83 "type": "Span"84 },85 "type": "Annotation"86 }87 ],88 "span": None,89 "type": "Junk"90 }91 message = self.parser.parse_entry(dedent_ftl(input))92 self.assertEqual(message.to_json(), output)93 def test_ignore_all_valid_comments(self):94 input = """\95 # Attached Comment96 ## Group Comment97 ### Resource Comment98 foo = Foo99 """100 output = {101 "comment": None,102 "value": {103 "elements": [104 {105 "span": None,106 "type": "TextElement",107 "value": "Foo"108 }109 ],110 "span": None,111 "type": "Pattern"112 },113 "attributes": [],114 "span": None,115 "type": "Message",116 "id": {117 "name": "foo",118 "span": None,119 "type": "Identifier"120 }121 }122 message = self.parser.parse_entry(dedent_ftl(input))123 self.assertEqual(message.to_json(), output)124 def test_do_not_ignore_invalid_comments(self):125 input = """\126 # Attached Comment127 ##Invalid Comment128 """129 output = {130 "content": "##Invalid Comment\n",131 "annotations": [132 {133 "arguments": [" "],134 "code": "E0003",135 "message": "Expected token: \" \"",136 "span": {137 "end": 21,138 "start": 21,139 "type": "Span"140 },141 "type": "Annotation"142 }143 ],144 "span": None,145 "type": "Junk"146 }147 message = self.parser.parse_entry(dedent_ftl(input))148 self.assertEqual(message.to_json(), output)149class TestSerializeEntry(unittest.TestCase):150 def setUp(self):151 self.serializer = FluentSerializer()152 def test_simple_message(self):153 input = {154 "comment": None,155 "value": {156 "elements": [157 {158 "type": "TextElement",159 "value": "Foo"160 }161 ],162 "type": "Pattern"163 },164 "attributes": [],165 "type": "Message",166 "id": {...
test_message.py
Source:test_message.py
...29@pytest.fixture(scope='function')30def patched_provider():31 return PatchedProvider()32@pytest.fixture(scope='function')33def test_simple_message(patched_provider):34 return message.MockMessage(message_pb2.SimpleMessage.DESCRIPTOR, patched_provider)35@pytest.fixture(scope='function')36def test_dependent_message(patched_provider):37 return message.MockMessage(message_pb2.DependentMessage.DESCRIPTOR, patched_provider)38class TestMessage:39 @staticmethod40 def test_message_get_attr(test_simple_message):41 assert test_simple_message.name == 'test'42 assert test_simple_message.decimal == 42.043 assert test_simple_message.count == 4244 assert test_simple_message.is_simple45 with pytest.raises(errors.UnknownFieldError):46 test_simple_message.asdf47 @staticmethod...
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!!