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

Side by Side Diff: client/tests/isolate_test.py

Issue 1233303003: Migrate and merge logging_utils from swarming_bot into client/utils. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Created 5 years, 5 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2012 The Swarming Authors. All rights reserved. 2 # Copyright 2012 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 that 3 # Use of this source code is governed under the Apache License, Version 2.0 that
4 # can be found in the LICENSE file. 4 # can be found in the LICENSE file.
5 5
6 import cStringIO 6 import cStringIO
7 import hashlib 7 import hashlib
8 import json 8 import json
9 import logging 9 import logging
10 import optparse 10 import optparse
11 import os 11 import os
12 import shutil 12 import shutil
13 import subprocess 13 import subprocess
14 import sys 14 import sys
15 import tempfile 15 import tempfile
16 16
17 ROOT_DIR = unicode(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 17 ROOT_DIR = unicode(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18 sys.path.insert(0, ROOT_DIR) 18 sys.path.insert(0, ROOT_DIR)
19 sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party')) 19 sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party'))
20 20
21 from depot_tools import auto_stub 21 from depot_tools import auto_stub
22 import auth 22 import auth
23 import isolate 23 import isolate
24 import isolate_format 24 import isolate_format
25 import isolated_format 25 import isolated_format
26 import isolateserver 26 import isolateserver
27 from utils import file_path 27 from utils import file_path
28 from utils import logging_utils
28 from utils import tools 29 from utils import tools
29 import test_utils 30 import test_utils
30 31
31 ALGO = hashlib.sha1 32 ALGO = hashlib.sha1
32 33
33 34
34 NO_RUN_ISOLATE = { 35 NO_RUN_ISOLATE = {
35 'tests/isolate/files1/subdir/42.txt': 36 'tests/isolate/files1/subdir/42.txt':
36 'the answer to life the universe and everything\n', 37 'the answer to life the universe and everything\n',
37 'tests/isolate/files1/test_file1.txt': 'Foo\n', 38 'tests/isolate/files1/test_file1.txt': 'Foo\n',
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 97
97 class IsolateBase(auto_stub.TestCase): 98 class IsolateBase(auto_stub.TestCase):
98 def setUp(self): 99 def setUp(self):
99 super(IsolateBase, self).setUp() 100 super(IsolateBase, self).setUp()
100 self.mock(auth, 'ensure_logged_in', lambda _: None) 101 self.mock(auth, 'ensure_logged_in', lambda _: None)
101 self.old_cwd = os.getcwd() 102 self.old_cwd = os.getcwd()
102 self.cwd = file_path.get_native_path_case( 103 self.cwd = file_path.get_native_path_case(
103 unicode(tempfile.mkdtemp(prefix=u'isolate_'))) 104 unicode(tempfile.mkdtemp(prefix=u'isolate_')))
104 # Everything should work even from another directory. 105 # Everything should work even from another directory.
105 os.chdir(self.cwd) 106 os.chdir(self.cwd)
107 self.mock(
108 logging_utils.OptionParserWithLogging, 'logger_root',
109 logging.Logger('unittest'))
106 110
107 def tearDown(self): 111 def tearDown(self):
108 try: 112 try:
109 os.chdir(self.old_cwd) 113 os.chdir(self.old_cwd)
110 file_path.rmtree(self.cwd) 114 file_path.rmtree(self.cwd)
111 finally: 115 finally:
112 super(IsolateBase, self).tearDown() 116 super(IsolateBase, self).tearDown()
113 117
114 118
115 class IsolateTest(IsolateBase): 119 class IsolateTest(IsolateBase):
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 }, f) 1373 }, f)
1370 1374
1371 self.mock(sys, 'stdout', cStringIO.StringIO()) 1375 self.mock(sys, 'stdout', cStringIO.StringIO())
1372 cmd = [ 1376 cmd = [
1373 '--isolate-server', 'http://localhost:1', 1377 '--isolate-server', 'http://localhost:1',
1374 '--dump-json', 'json_output.json', 1378 '--dump-json', 'json_output.json',
1375 join('x.isolated.gen.json'), 1379 join('x.isolated.gen.json'),
1376 join('y.isolated.gen.json'), 1380 join('y.isolated.gen.json'),
1377 ] 1381 ]
1378 self.assertEqual( 1382 self.assertEqual(
1379 0, isolate.CMDbatcharchive(tools.OptionParserWithLogging(), cmd)) 1383 0,
1384 isolate.CMDbatcharchive(logging_utils.OptionParserWithLogging(), cmd))
1380 expected = [ 1385 expected = [
1381 { 1386 {
1382 'base_url': 'http://localhost:1', 1387 'base_url': 'http://localhost:1',
1383 'infiles': { 1388 'infiles': {
1384 join(isolated_file_x): { 1389 join(isolated_file_x): {
1385 'priority': '0', 1390 'priority': '0',
1386 }, 1391 },
1387 join('foo'): { 1392 join('foo'): {
1388 'h': '520d41b29f891bbaccf31d9fcfa72e82ea20fcf0', 1393 'h': '520d41b29f891bbaccf31d9fcfa72e82ea20fcf0',
1389 's': 4, 1394 's': 4,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 1614
1610 1615
1611 def clear_env_vars(): 1616 def clear_env_vars():
1612 for e in ('ISOLATE_DEBUG', 'ISOLATE_SERVER'): 1617 for e in ('ISOLATE_DEBUG', 'ISOLATE_SERVER'):
1613 os.environ.pop(e, None) 1618 os.environ.pop(e, None)
1614 1619
1615 1620
1616 if __name__ == '__main__': 1621 if __name__ == '__main__':
1617 clear_env_vars() 1622 clear_env_vars()
1618 test_utils.main() 1623 test_utils.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698