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

Side by Side Diff: third_party/google-endpoints/apitools/gen/test_utils.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 """Various utilities used in tests."""
17
18 import contextlib
19 import os
20 import tempfile
21 import shutil
22 import sys
23
24 import six
25 import unittest2
26
27
28 RunOnlyOnPython27 = unittest2.skipUnless(
29 sys.version_info[:2] == (2, 7), 'Only runs in Python 2.7')
30
31
32 @contextlib.contextmanager
33 def TempDir(change_to=False):
34 if change_to:
35 original_dir = os.getcwd()
36 path = tempfile.mkdtemp()
37 try:
38 if change_to:
39 os.chdir(path)
40 yield path
41 finally:
42 if change_to:
43 os.chdir(original_dir)
44 shutil.rmtree(path)
45
46
47 @contextlib.contextmanager
48 def CaptureOutput():
49 new_stdout, new_stderr = six.StringIO(), six.StringIO()
50 old_stdout, old_stderr = sys.stdout, sys.stderr
51 try:
52 sys.stdout, sys.stderr = new_stdout, new_stderr
53 yield new_stdout, new_stderr
54 finally:
55 sys.stdout, sys.stderr = old_stdout, old_stderr
OLDNEW
« no previous file with comments | « third_party/google-endpoints/apitools/gen/service_registry.py ('k') | third_party/google-endpoints/apitools/gen/util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698