Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: third_party/grpc/src/python/grpcio/tests/unit/test_common.py

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015, Google Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 """Common code used throughout tests of gRPC."""
31
32 import collections
33
34 INVOCATION_INITIAL_METADATA = ((b'0', b'abc'), (b'1', b'def'), (b'2', b'ghi'),)
35 SERVICE_INITIAL_METADATA = ((b'3', b'jkl'), (b'4', b'mno'), (b'5', b'pqr'),)
36 SERVICE_TERMINAL_METADATA = ((b'6', b'stu'), (b'7', b'vwx'), (b'8', b'yza'),)
37 DETAILS = b'test details'
38
39
40 def metadata_transmitted(original_metadata, transmitted_metadata):
41 """Judges whether or not metadata was acceptably transmitted.
42
43 gRPC is allowed to insert key-value pairs into the metadata values given by
44 applications and to reorder key-value pairs with different keys but it is not
45 allowed to alter existing key-value pairs or to reorder key-value pairs with
46 the same key.
47
48 Args:
49 original_metadata: A metadata value used in a test of gRPC. An iterable over
50 iterables of length 2.
51 transmitted_metadata: A metadata value corresponding to original_metadata
52 after having been transmitted via gRPC. An iterable over iterables of
53 length 2.
54
55 Returns:
56 A boolean indicating whether transmitted_metadata accurately reflects
57 original_metadata after having been transmitted via gRPC.
58 """
59 original = collections.defaultdict(list)
60 for key_value_pair in original_metadata:
61 key, value = tuple(key_value_pair)
62 original[key].append(value)
63 transmitted = collections.defaultdict(list)
64 for key_value_pair in transmitted_metadata:
65 key, value = tuple(key_value_pair)
66 transmitted[key].append(value)
67
68 for key, values in original.iteritems():
69 transmitted_values = transmitted[key]
70 transmitted_iterator = iter(transmitted_values)
71 try:
72 for value in values:
73 while True:
74 transmitted_value = next(transmitted_iterator)
75 if value == transmitted_value:
76 break
77 except StopIteration:
78 return False
79 else:
80 return True
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698