OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import os |
| 7 import shutil |
| 8 import subprocess |
| 9 import sys |
| 10 import tempfile |
| 11 import unittest |
| 12 |
| 13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 14 |
| 15 |
| 16 class Isolate(unittest.TestCase): |
| 17 def setUp(self): |
| 18 self.tempdir = tempfile.mkdtemp() |
| 19 self.result = os.path.join(self.tempdir, 'result') |
| 20 |
| 21 def tearDown(self): |
| 22 shutil.rmtree(self.tempdir) |
| 23 |
| 24 def _execute(self, args): |
| 25 cmd = [ |
| 26 sys.executable, os.path.join(ROOT_DIR, 'isolate.py'), |
| 27 '--root', ROOT_DIR, |
| 28 '--result', self.result, |
| 29 ] |
| 30 subprocess.check_call( |
| 31 cmd + args, |
| 32 stdout=subprocess.PIPE, |
| 33 stderr=subprocess.STDOUT) |
| 34 |
| 35 def test_check(self): |
| 36 cmd = [ |
| 37 '--mode', 'check', |
| 38 'isolate_test.py', |
| 39 ] |
| 40 self._execute(cmd) |
| 41 self.assertTrue(os.path.isfile(self.result)) |
| 42 |
| 43 def test_check_non_existant(self): |
| 44 cmd = [ |
| 45 '--mode', 'check', |
| 46 'NonExistentFile', |
| 47 ] |
| 48 try: |
| 49 self._execute(cmd) |
| 50 self.fail() |
| 51 except subprocess.CalledProcessError: |
| 52 pass |
| 53 self.assertFalse(os.path.isfile(self.result)) |
| 54 |
| 55 def test_run(self): |
| 56 cmd = [ |
| 57 '--mode', 'run', |
| 58 'isolate_test.py', |
| 59 '--', |
| 60 sys.executable, 'isolate_test.py', '--ok', |
| 61 ] |
| 62 self._execute(cmd) |
| 63 self.assertTrue(os.path.isfile(self.result)) |
| 64 |
| 65 def test_run_fail(self): |
| 66 cmd = [ |
| 67 '--mode', 'run', |
| 68 'isolate_test.py', |
| 69 '--', |
| 70 sys.executable, 'isolate_test.py', '--fail', |
| 71 ] |
| 72 try: |
| 73 self._execute(cmd) |
| 74 self.fail() |
| 75 except subprocess.CalledProcessError: |
| 76 pass |
| 77 self.assertFalse(os.path.isfile(self.result)) |
| 78 |
| 79 |
| 80 def main(): |
| 81 if len(sys.argv) == 1: |
| 82 unittest.main() |
| 83 if sys.argv[1] == '--ok': |
| 84 return 0 |
| 85 if sys.argv[1] == '--fail': |
| 86 return 1 |
| 87 unittest.main() |
| 88 |
| 89 |
| 90 if __name__ == '__main__': |
| 91 sys.exit(main()) |
OLD | NEW |