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

Unified Diff: tools/android/loading/loading_trace_analyzer_unittest.py

Issue 1738803003: tools/android/loading: Implements loading_trace_analyzer.py's unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i11
Patch Set: Created 4 years, 10 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
« no previous file with comments | « tools/android/loading/loading_trace_analyzer.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()
« no previous file with comments | « tools/android/loading/loading_trace_analyzer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698