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

Side by Side Diff: third_party/google-endpoints/apitools/base/py/buffered_stream_test.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 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 #
2 # Copyright 2015 Google Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """Tests for buffered_stream."""
17
18 import string
19
20 import six
21 import unittest2
22
23 from apitools.base.py import buffered_stream
24 from apitools.base.py import exceptions
25
26
27 class BufferedStreamTest(unittest2.TestCase):
28
29 def setUp(self):
30 self.stream = six.StringIO(string.ascii_letters)
31 self.value = self.stream.getvalue()
32 self.stream.seek(0)
33
34 def testEmptyBuffer(self):
35 bs = buffered_stream.BufferedStream(self.stream, 0, 0)
36 self.assertEqual('', bs.read(0))
37 self.assertEqual(0, bs.stream_end_position)
38
39 def testOffsetStream(self):
40 bs = buffered_stream.BufferedStream(self.stream, 50, 100)
41 self.assertEqual(len(self.value), len(bs))
42 self.assertEqual(self.value, bs.read(len(self.value)))
43 self.assertEqual(50 + len(self.value), bs.stream_end_position)
44
45 def testUnexhaustedStream(self):
46 bs = buffered_stream.BufferedStream(self.stream, 0, 50)
47 self.assertEqual(50, bs.stream_end_position)
48 self.assertEqual(False, bs.stream_exhausted)
49 self.assertEqual(self.value[0:50], bs.read(50))
50 self.assertEqual(False, bs.stream_exhausted)
51 self.assertEqual('', bs.read(0))
52 self.assertEqual('', bs.read(100))
53
54 def testExhaustedStream(self):
55 bs = buffered_stream.BufferedStream(self.stream, 0, 100)
56 self.assertEqual(len(self.value), bs.stream_end_position)
57 self.assertEqual(True, bs.stream_exhausted)
58 self.assertEqual(self.value, bs.read(100))
59 self.assertEqual('', bs.read(0))
60 self.assertEqual('', bs.read(100))
61
62 def testArbitraryLengthRead(self):
63 bs = buffered_stream.BufferedStream(self.stream, 0, 20)
64 with self.assertRaises(exceptions.NotYetImplementedError):
65 bs.read()
66 with self.assertRaises(exceptions.NotYetImplementedError):
67 bs.read(size=-1)
OLDNEW
« no previous file with comments | « third_party/google-endpoints/apitools/base/py/buffered_stream.py ('k') | third_party/google-endpoints/apitools/base/py/cli.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698