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

Side by Side Diff: appengine/swarming/swarming_bot/bot_code/bot_main_test.py

Issue 1390773002: Add an assert to ensure UTF-8 locale when handling file paths. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: More fixes Created 5 years, 2 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 2013 The Swarming Authors. All rights reserved. 2 # Copyright 2013 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed by the Apache v2.0 license that can be 3 # Use of this source code is governed by the Apache v2.0 license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import shutil 9 import shutil
10 import sys 10 import sys
11 import tempfile 11 import tempfile
12 import threading 12 import threading
13 import time 13 import time
14 import unittest 14 import unittest
15 15
16 import test_env_bot_code 16 import test_env_bot_code
17 test_env_bot_code.setup_test_env() 17 test_env_bot_code.setup_test_env()
18 18
19 # Creates a server mock for functions in net.py. 19 # Creates a server mock for functions in net.py.
20 import net_utils 20 import net_utils
21 21
22 import bot_main 22 import bot_main
23 import xsrf_client 23 import xsrf_client
24 from api import bot 24 from api import bot
25 from api import os_utilities 25 from api import os_utilities
26 from depot_tools import fix_encoding
27 from utils import file_path
26 from utils import logging_utils 28 from utils import logging_utils
27 from utils import net 29 from utils import net
28 from utils import subprocess42 30 from utils import subprocess42
29 from utils import zip_package 31 from utils import zip_package
30 32
31 33
32 # Access to a protected member XX of a client class - pylint: disable=W0212 34 # Access to a protected member XX of a client class - pylint: disable=W0212
33 35
34 36
35 class TestBotMain(net_utils.TestCase): 37 class TestBotMain(net_utils.TestCase):
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 with open(config_path, 'rb') as f: 69 with open(config_path, 'rb') as f:
68 config = json.load(f) 70 config = json.load(f)
69 self.mock(bot_main, 'get_config', lambda: config) 71 self.mock(bot_main, 'get_config', lambda: config)
70 self.mock( 72 self.mock(
71 bot_main, 'THIS_FILE', 73 bot_main, 'THIS_FILE',
72 os.path.join(test_env_bot_code.BOT_DIR, 'swarming_bot.zip')) 74 os.path.join(test_env_bot_code.BOT_DIR, 'swarming_bot.zip'))
73 75
74 def tearDown(self): 76 def tearDown(self):
75 os.environ.pop('SWARMING_BOT_ID', None) 77 os.environ.pop('SWARMING_BOT_ID', None)
76 os.chdir(self.old_cwd) 78 os.chdir(self.old_cwd)
77 shutil.rmtree(self.root_dir) 79 file_path.rmtree(self.root_dir)
78 super(TestBotMain, self).tearDown() 80 super(TestBotMain, self).tearDown()
79 81
80 def test_get_dimensions(self): 82 def test_get_dimensions(self):
81 dimensions = set(bot_main.get_dimensions()) 83 dimensions = set(bot_main.get_dimensions())
82 dimensions.discard('hidpi') 84 dimensions.discard('hidpi')
83 dimensions.discard('zone') # Only set on GCE bots. 85 dimensions.discard('zone') # Only set on GCE bots.
84 expected = {'cores', 'cpu', 'gpu', 'id', 'machine_type', 'os'} 86 expected = {'cores', 'cpu', 'gpu', 'id', 'machine_type', 'os'}
85 self.assertEqual(expected, dimensions) 87 self.assertEqual(expected, dimensions)
86 88
87 def test_get_dimensions_load_test(self): 89 def test_get_dimensions_load_test(self):
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 524
523 def run_bot(error): 525 def run_bot(error):
524 self.assertEqual(None, error) 526 self.assertEqual(None, error)
525 return 0 527 return 0
526 self.mock(bot_main, 'run_bot', run_bot) 528 self.mock(bot_main, 'run_bot', run_bot)
527 529
528 self.assertEqual(0, bot_main.main([])) 530 self.assertEqual(0, bot_main.main([]))
529 531
530 532
531 if __name__ == '__main__': 533 if __name__ == '__main__':
534 fix_encoding.fix_encoding()
532 if '-v' in sys.argv: 535 if '-v' in sys.argv:
533 unittest.TestCase.maxDiff = None 536 unittest.TestCase.maxDiff = None
534 logging.basicConfig( 537 logging.basicConfig(
535 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) 538 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
536 unittest.main() 539 unittest.main()
OLDNEW
« no previous file with comments | « appengine/swarming/server/bot_code_test.py ('k') | appengine/swarming/swarming_bot/bot_code/task_runner_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698