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

Side by Side Diff: third_party/pexpect/tests/test_performance.py

Issue 1398903002: Add third_party/pexpect (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@end-to-end-test
Patch Set: Created 5 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 '''
3 PEXPECT LICENSE
4
5 This license is approved by the OSI and FSF as GPL-compatible.
6 http://opensource.org/licenses/isc-license.txt
7
8 Copyright (c) 2012, Noah Spurrier <noah@noah.org>
9 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
10 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
11 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
12 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 '''
21 from __future__ import print_function
22
23 import unittest, time, sys
24 import platform
25 import pexpect
26 from . import PexpectTestCase
27
28 # This isn't exactly a unit test, but it fits in nicely with the rest of the tes ts.
29
30 class PerformanceTestCase (PexpectTestCase.PexpectTestCase):
31
32 '''Testing the performance of expect, with emphasis on wading through long
33 inputs. '''
34
35 if sys.version_info[0] >= 3:
36 @staticmethod
37 def _iter_n(n):
38 s = 'for n in range(1, %d+1): print(n)' % n
39 return s.encode('ascii')
40
41 else:
42 @staticmethod
43 def _iter_n(n):
44 return 'for n in range(1, %d+1): print(n)' % n
45
46 def plain_range(self, n):
47 e = pexpect.spawn('python', timeout=100)
48 self.assertEqual(e.expect(b'>>>'), 0)
49 e.sendline(self._iter_n(n))
50 self.assertEqual(e.expect(br'\.{3}'), 0)
51 e.sendline(b'')
52 self.assertEqual(e.expect([b'inquisition', '%d' % n]), 1)
53
54 def window_range(self, n):
55 e = pexpect.spawn('python', timeout=100)
56 self.assertEqual(e.expect(b'>>>'), 0)
57 e.sendline(self._iter_n(n))
58 self.assertEqual(e.expect(r'\.{3}'), 0)
59 e.sendline(b'')
60 self.assertEqual(e.expect([b'inquisition', '%d' % n], searchwindowsize=2 0), 1)
61
62 def exact_range(self, n):
63 e = pexpect.spawn('python', timeout=100)
64 self.assertEqual(e.expect_exact([b'>>>']), 0)
65 e.sendline(self._iter_n(n))
66 self.assertEqual(e.expect_exact([b'...']), 0)
67 e.sendline(b'')
68 self.assertEqual(e.expect_exact([b'inquisition', '%d' % n],timeout=520), 1)
69
70 def ewin_range(self, n):
71 e = pexpect.spawn('python', timeout=100)
72 self.assertEqual(e.expect_exact([b'>>>']), 0)
73 e.sendline(self._iter_n(n))
74 self.assertEqual(e.expect_exact([b'...']), 0)
75 e.sendline(b'')
76 self.assertEqual(e.expect_exact([b'inquisition', '%d' % n], searchwindow size=20), 1)
77
78 def faster_range(self, n):
79 e = pexpect.spawn('python', timeout=100)
80 self.assertEqual(e.expect(b'>>>'), 0)
81 e.sendline(('list(range(1, %d+1))' % n).encode('ascii'))
82 self.assertEqual(e.expect([b'inquisition', '%d' % n]), 1)
83
84 def test_100000(self):
85 if platform.python_implementation() == 'PyPy':
86 raise unittest.SkipTest("This test fails on PyPy because of REPL dif ferences")
87 print()
88 start_time = time.time()
89 self.plain_range (100000)
90 print("100000 calls to plain_range:", (time.time() - start_time))
91 start_time = time.time()
92 self.window_range(100000)
93 print("100000 calls to window_range:", (time.time() - start_time))
94 start_time = time.time()
95 self.exact_range (100000)
96 print("100000 calls to exact_range:", (time.time() - start_time))
97 start_time = time.time()
98 self.ewin_range (100000)
99 print("100000 calls to ewin_range:", (time.time() - start_time))
100 start_time = time.time()
101 self.faster_range(100000)
102 print("100000 calls to faster_range:", (time.time() - start_time))
103
104 if __name__ == "__main__":
105 unittest.main()
106
107 suite = unittest.makeSuite(PerformanceTestCase,'test')
OLDNEW
« no previous file with comments | « third_party/pexpect/tests/test_missing_command.py ('k') | third_party/pexpect/tests/test_pickling.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698