Best Python code snippet using molecule_python
_metadata_test.py
Source: _metadata_test.py
1# Copyright 2020 gRPC authors.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""Tests for the metadata abstraction that's used in the asynchronous driver."""15import logging16import unittest17from grpc.experimental.aio import Metadata18class TestTypeMetadata(unittest.TestCase):19 """Tests for the metadata type"""20 _DEFAULT_DATA = (("key1", "value1"), ("key2", "value2"))21 _MULTI_ENTRY_DATA = (("key1", "value1"), ("key1", "other value 1"),22 ("key2", "value2"))23 def test_init_metadata(self):24 test_cases = {25 "emtpy": (),26 "with-single-data": self._DEFAULT_DATA,27 "with-multi-data": self._MULTI_ENTRY_DATA,28 }29 for case, args in test_cases.items():30 with self.subTest(case=case):31 metadata = Metadata(*args)32 self.assertEqual(len(metadata), len(args))33 def test_get_item(self):34 metadata = Metadata(("key", "value1"), ("key", "value2"),35 ("key2", "other value"))36 self.assertEqual(metadata["key"], "value1")37 self.assertEqual(metadata["key2"], "other value")38 self.assertEqual(metadata.get("key"), "value1")39 self.assertEqual(metadata.get("key2"), "other value")40 with self.assertRaises(KeyError):41 metadata["key not found"]42 self.assertIsNone(metadata.get("key not found"))43 def test_add_value(self):44 metadata = Metadata()45 metadata.add("key", "value")46 metadata.add("key", "second value")47 metadata.add("key2", "value2")48 self.assertEqual(metadata["key"], "value")49 self.assertEqual(metadata["key2"], "value2")50 def test_get_all_items(self):51 metadata = Metadata(*self._MULTI_ENTRY_DATA)52 self.assertEqual(metadata.get_all("key1"), ["value1", "other value 1"])53 self.assertEqual(metadata.get_all("key2"), ["value2"])54 self.assertEqual(metadata.get_all("non existing key"), [])55 def test_container(self):56 metadata = Metadata(*self._MULTI_ENTRY_DATA)57 self.assertIn("key1", metadata)58 def test_equals(self):59 metadata = Metadata()60 for key, value in self._DEFAULT_DATA:61 metadata.add(key, value)62 metadata2 = Metadata(*self._DEFAULT_DATA)63 self.assertEqual(metadata, metadata2)64 self.assertNotEqual(metadata, "foo")65 def test_repr(self):66 metadata = Metadata(*self._DEFAULT_DATA)67 expected = "Metadata({0!r})".format(self._DEFAULT_DATA)68 self.assertEqual(repr(metadata), expected)69 def test_set(self):70 metadata = Metadata(*self._MULTI_ENTRY_DATA)71 override_value = "override value"72 for _ in range(3):73 metadata["key1"] = override_value74 self.assertEqual(metadata["key1"], override_value)75 self.assertEqual(metadata.get_all("key1"),76 [override_value, "other value 1"])77 empty_metadata = Metadata()78 for _ in range(3):79 empty_metadata["key"] = override_value80 self.assertEqual(empty_metadata["key"], override_value)81 self.assertEqual(empty_metadata.get_all("key"), [override_value])82 def test_set_all(self):83 metadata = Metadata(*self._DEFAULT_DATA)84 metadata.set_all("key", ["value1", b"new value 2"])85 self.assertEqual(metadata["key"], "value1")86 self.assertEqual(metadata.get_all("key"), ["value1", b"new value 2"])87 def test_delete_values(self):88 metadata = Metadata(*self._MULTI_ENTRY_DATA)89 del metadata["key1"]90 self.assertEqual(metadata.get("key1"), "other value 1")91 metadata.delete_all("key1")92 self.assertNotIn("key1", metadata)93 metadata.delete_all("key2")94 self.assertEqual(len(metadata), 0)95 with self.assertRaises(KeyError):96 del metadata["other key"]97 def test_metadata_from_tuple(self):98 scenarios = (99 (None, Metadata()),100 (Metadata(), Metadata()),101 (self._DEFAULT_DATA, Metadata(*self._DEFAULT_DATA)),102 (self._MULTI_ENTRY_DATA, Metadata(*self._MULTI_ENTRY_DATA)),103 (Metadata(*self._DEFAULT_DATA), Metadata(*self._DEFAULT_DATA)),104 )105 for source, expected in scenarios:106 with self.subTest(raw_metadata=source, expected=expected):107 self.assertEqual(expected, Metadata.from_tuple(source))108if __name__ == '__main__':109 logging.basicConfig()...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
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!!