OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import hashlib | 6 import hashlib |
7 import json | 7 import json |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 result_file = os.path.join(self.tempdir, 'foo.results') | 98 result_file = os.path.join(self.tempdir, 'foo.results') |
99 write_json(result_file, result_data) | 99 write_json(result_file, result_data) |
100 | 100 |
101 cmd = [ | 101 cmd = [ |
102 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'), | 102 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'), |
103 '--manifest', result_file, | 103 '--manifest', result_file, |
104 '--cache', self.cache, | 104 '--cache', self.cache, |
105 '--remote', self.table, | 105 '--remote', self.table, |
106 ] | 106 ] |
107 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 107 proc = subprocess.Popen( |
| 108 cmd, |
| 109 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 110 universal_newlines=True) |
108 out, err = proc.communicate() | 111 out, err = proc.communicate() |
109 self.assertEquals(1070, len(out)) | 112 self.assertEquals(1070, len(out)) |
110 self.assertEquals('', err) | 113 self.assertEquals('', err) |
111 self.assertEquals(6, proc.returncode) | 114 self.assertEquals(6, proc.returncode) |
112 | 115 |
113 def test_hash(self): | 116 def test_hash(self): |
114 # Loads the manifest from the store as a hash, then run the child. | 117 # Loads the manifest from the store as a hash, then run the child. |
115 # Store the executable in the hash table. | 118 # Store the executable in the hash table. |
116 shutil.copyfile(self.test, os.path.join(self.table, self.test_sha1)) | 119 shutil.copyfile(self.test, os.path.join(self.table, self.test_sha1)) |
117 # Store a .results file in the hash table. The file name is the content's | 120 # Store a .results file in the hash table. The file name is the content's |
118 # sha1, so first generate the content. | 121 # sha1, so first generate the content. |
119 result_data = { | 122 result_data = { |
120 'files': { | 123 'files': { |
121 'gtest_fake.py': { | 124 'gtest_fake.py': { |
122 'sha-1': self.test_sha1, | 125 'sha-1': self.test_sha1, |
123 }, | 126 }, |
124 }, | 127 }, |
125 'command': ['python', 'gtest_fake.py'], | 128 'command': ['python', 'gtest_fake.py'], |
126 } | 129 } |
127 result_sha1 = self._store_result(result_data) | 130 result_sha1 = self._store_result(result_data) |
128 | 131 |
129 cmd = [ | 132 cmd = [ |
130 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'), | 133 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'), |
131 '--hash', result_sha1, | 134 '--hash', result_sha1, |
132 '--cache', self.cache, | 135 '--cache', self.cache, |
133 '--remote', self.table, | 136 '--remote', self.table, |
134 ] | 137 ] |
135 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 138 proc = subprocess.Popen( |
| 139 cmd, |
| 140 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 141 universal_newlines=True) |
136 out, err = proc.communicate() | 142 out, err = proc.communicate() |
137 self.assertEquals(1070, len(out)) | 143 self.assertEquals(1070, len(out)) |
138 self.assertEquals('', err) | 144 self.assertEquals('', err) |
139 self.assertEquals(6, proc.returncode) | 145 self.assertEquals(6, proc.returncode) |
140 | 146 |
141 def test_fail_empty_manifest(self): | 147 def test_fail_empty_manifest(self): |
142 result_sha1 = self._store_result({}) | 148 result_sha1 = self._store_result({}) |
143 cmd = [ | 149 cmd = [ |
144 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'), | 150 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'), |
145 '--hash', result_sha1, | 151 '--hash', result_sha1, |
146 '--cache', self.cache, | 152 '--cache', self.cache, |
147 '--remote', self.table, | 153 '--remote', self.table, |
148 ] | 154 ] |
149 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 155 proc = subprocess.Popen( |
| 156 cmd, |
| 157 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 158 universal_newlines=True) |
150 out, err = proc.communicate() | 159 out, err = proc.communicate() |
151 self.assertEquals('', out) | 160 self.assertEquals('', out) |
152 self.assertEquals('No file to map\n', err) | 161 self.assertEquals('No file to map\n', err) |
153 self.assertEquals(1, proc.returncode) | 162 self.assertEquals(1, proc.returncode) |
154 | 163 |
155 | 164 |
156 if __name__ == '__main__': | 165 if __name__ == '__main__': |
157 VERBOSE = '-v' in sys.argv | 166 VERBOSE = '-v' in sys.argv |
158 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 167 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
159 unittest.main() | 168 unittest.main() |
OLD | NEW |