Chromium Code Reviews| Index: tools/android/loading/loading_trace_analyzer_unittest.py |
| diff --git a/tools/android/loading/loading_trace_analyzer_unittest.py b/tools/android/loading/loading_trace_analyzer_unittest.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c733defd5a71e87a972850c729dd11f8676488ff |
| --- /dev/null |
| +++ b/tools/android/loading/loading_trace_analyzer_unittest.py |
| @@ -0,0 +1,84 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import gzip |
| +import os |
| +import re |
| +import shutil |
| +import subprocess |
| +import tempfile |
| +import unittest |
| + |
| +LOADING_DIR = os.path.dirname(__file__) |
| +TEST_DATA_DIR = os.path.join(LOADING_DIR, 'testdata') |
| +LOADING_TRACE_ANALYZER = os.path.join(LOADING_DIR, 'loading_trace_analyzer.py') |
|
mattcary
2016/02/26 09:42:29
Generally it would be better to call loading_trace
gabadie
2016/02/29 18:58:45
Done. But I am a not fan of this. It has just move
|
| + |
| + |
| +class LoadingTraceAnalyzerTest(unittest.TestCase): |
| + _ROLLING_STONE = os.path.join(TEST_DATA_DIR, 'rollingstone.trace.gz') |
| + |
| + def setUp(self): |
| + self._temp_dir = tempfile.mkdtemp() |
| + self.trace_path = self._TmpPath('trace.json') |
| + with gzip.GzipFile(self._ROLLING_STONE) as f: |
| + with open(self.trace_path, 'w') as g: |
| + g.write(f.read()) |
| + |
| + def tearDown(self): |
| + shutil.rmtree(self._temp_dir) |
| + |
| + def _Cmd(self, args): |
| + cmd = ['python', LOADING_TRACE_ANALYZER] |
| + cmd.extend(args) |
| + print cmd |
| + process = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
| + process.stdout, _ = process.communicate() |
| + process.stdout = process.stdout.split('\n')[:-1] |
| + return process |
| + |
| + def _TmpPath(self, name): |
| + return os.path.join(self._temp_dir, name) |
| + |
| + def test_RequestsCmd(self): |
|
pasko
2016/02/26 16:50:53
It seems that naming like testRequestsCmd (without
gabadie
2016/02/29 18:58:45
Done.
|
| + process = self._Cmd(['requests', self.trace_path]) |
| + self.assertEquals(0, process.returncode) |
| + self.assertNotEqual(0, len(process.stdout)) |
| + |
| + process = self._Cmd(['requests', |
| + '--output', self._TmpPath('output0'), |
| + self.trace_path]) |
| + self.assertEquals(0, process.returncode) |
| + self.assertEqual(0, len(process.stdout)) |
| + with open(self._TmpPath('output0')) as f: |
| + self.assertNotEqual(0, len(f.readlines())) |
| + |
| + process = self._Cmd(['requests', |
| + '--output-format', 'hello {protocol} world {url}', |
| + self.trace_path]) |
| + self.assertEquals(0, process.returncode) |
| + self.assertNotEqual(0, len(process.stdout)) |
| + for line in process.stdout: |
| + self.assertTrue(re.match(r'^hello \S+ world \S+$', line)) |
| + |
| + process = self._Cmd(['requests', |
| + '--output-format', '{url}', |
| + '--where', '{url}', r'^http://.*$', |
| + self.trace_path]) |
| + self.assertEqual(0, process.returncode) |
| + self.assertNotEqual(0, len(process.stdout)) |
| + for line in process.stdout: |
| + self.assertTrue(line.startswith('http://')) |
| + |
| + process = self._Cmd(['requests', |
| + '--output-format', '{url}', |
| + '--where', '{url}', r'^https://.*$', |
| + self.trace_path]) |
| + self.assertEqual(0, process.returncode) |
| + self.assertNotEqual(0, len(process.stdout)) |
| + for line in process.stdout: |
| + self.assertTrue(line.startswith('https://')) |
| + |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |