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

Unified Diff: tools/isolate/isolate_test.py

Issue 10080013: Makes the code simpler by automatically deducing the root directory to use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix file sharing on windows Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« tools/isolate/isolate.py ('K') | « tools/isolate/isolate_smoke_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/isolate/isolate_test.py
diff --git a/tools/isolate/isolate_test.py b/tools/isolate/isolate_test.py
index 3e5eac986f084d8b5b5a7bd33a55fff18a736b0a..b04f44f0409b7226a4a56457a863e6c78b3e61af 100755
--- a/tools/isolate/isolate_test.py
+++ b/tools/isolate/isolate_test.py
@@ -3,12 +3,53 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
+import os
+import tempfile
import unittest
import isolate
+ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
+
class Isolate(unittest.TestCase):
+ def setUp(self):
+ # Everything should work even from another directory.
+ os.chdir(os.path.dirname(ROOT_DIR))
+
+ def _run_process_options(self, values, variables, more_expected_data):
+ """Runs isolate.process_options() and verify the results."""
+ fd, temp_path = tempfile.mkstemp()
+ try:
+ # Reuse the file descriptor. On windows, it needs to be closed before
+ # process_options() opens it, because mkstemp() opens it without file
+ # sharing enabled.
+ with os.fdopen(fd, 'w') as f:
+ json.dump(values, f)
+ root_dir, infiles, data = isolate.process_options(
+ variables,
+ temp_path,
+ os.path.join('isolate', 'data', 'isolate', 'touch_root.isolate'),
+ self.fail)
+ finally:
+ os.remove(temp_path)
+
+ expected_data = {
+ u'command': ['python', 'touch_root.py'],
+ u'read_only': None,
+ u'relative_cwd': 'data/isolate',
+ u'resultfile': temp_path,
+ u'resultdir': tempfile.gettempdir(),
+ u'variables': {},
+ }
+ expected_data.update(more_expected_data)
+ expected_files = sorted(
+ ('isolate.py', os.path.join('data', 'isolate', 'touch_root.py')))
+ self.assertEquals(ROOT_DIR, root_dir)
+ self.assertEquals(expected_files, sorted(infiles))
+ self.assertEquals(expected_data, data)
+
def test_load_empty(self):
content = "{}"
variables = {}
@@ -18,6 +59,34 @@ class Isolate(unittest.TestCase):
self.assertEquals([], infiles)
self.assertEquals(None, read_only)
+ def test_process_options_empty(self):
+ # Passing nothing generates nothing unexpected.
+ self._run_process_options({}, [], {})
+
+ def test_process_options(self):
+ # The previous unexpected variables are kept, the 'variables' dictionary is
+ # updated.
+ values = {
+ 'command': 'maybe',
+ 'foo': 'bar',
+ 'read_only': 2,
+ 'relative_cwd': None,
+ 'resultdir': '2',
+ 'resultfile': [],
+ 'variables': {
+ 'unexpected': 'seriously',
+ },
+ }
+
+ expected_data = {
+ u'foo': u'bar',
+ u'variables': {
+ 'expected': 'very',
+ u'unexpected': u'seriously',
+ },
+ }
+ self._run_process_options(values, ['expected=very'], expected_data)
+
if __name__ == '__main__':
unittest.main()
« tools/isolate/isolate.py ('K') | « tools/isolate/isolate_smoke_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698