OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 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 """Simplify unit tests based on pymox.""" | 6 """Simplify unit tests based on pymox.""" |
7 | 7 |
8 import os | 8 import os |
9 import random | 9 import random |
10 import string | 10 import string |
11 | 11 from pymox import mox |
12 mox = None | |
13 | |
14 def OnTestsLoad(): | |
15 import sys | |
16 old_path = sys.path | |
17 global mox | |
18 try: | |
19 directory, _file = os.path.split(__file__) | |
20 sys.path.append(os.path.abspath(os.path.join(directory, 'pymox'))) | |
21 sys.path.append(os.path.abspath(os.path.join(directory, '..'))) | |
22 try: | |
23 import mox as Mox | |
24 mox = Mox | |
25 except ImportError: | |
26 print "Trying to automatically checkout pymox." | |
27 import subprocess | |
28 subprocess.call(['svn', 'co', 'http://pymox.googlecode.com/svn/trunk', | |
29 os.path.join(directory, 'pymox')], | |
30 shell=sys.platform.startswith('win')) | |
31 try: | |
32 import pymox.mox as Mox | |
33 mox = Mox | |
34 except ImportError: | |
35 print >> sys.stderr, ("\nError, failed to load pymox\n") | |
36 raise | |
37 finally: | |
38 # Restore the path | |
39 sys.path = old_path | |
40 | |
41 | |
42 # Automatically fetch pymox. | |
43 OnTestsLoad() | |
44 | 12 |
45 | 13 |
46 class SuperMoxTestBase(mox.MoxTestBase): | 14 class SuperMoxTestBase(mox.MoxTestBase): |
47 # Backup the separator in case it gets mocked | 15 # Backup the separator in case it gets mocked |
48 _OS_SEP = os.sep | 16 _OS_SEP = os.sep |
49 _RANDOM_CHOICE = random.choice | 17 _RANDOM_CHOICE = random.choice |
50 _RANDOM_RANDINT = random.randint | 18 _RANDOM_RANDINT = random.randint |
51 _STRING_LETTERS = string.letters | 19 _STRING_LETTERS = string.letters |
52 | 20 |
53 ## Some utilities for generating arbitrary arguments. | 21 ## Some utilities for generating arbitrary arguments. |
(...skipping 28 matching lines...) Expand all Loading... |
82 # Skip over members starting with '_' since they are usually not meant to | 50 # Skip over members starting with '_' since they are usually not meant to |
83 # be for public use. | 51 # be for public use. |
84 actual_members = [x for x in sorted(dir(object)) | 52 actual_members = [x for x in sorted(dir(object)) |
85 if not x.startswith('_')] | 53 if not x.startswith('_')] |
86 expected_members = sorted(members) | 54 expected_members = sorted(members) |
87 if actual_members != expected_members: | 55 if actual_members != expected_members: |
88 diff = ([i for i in actual_members if i not in expected_members] + | 56 diff = ([i for i in actual_members if i not in expected_members] + |
89 [i for i in expected_members if i not in actual_members]) | 57 [i for i in expected_members if i not in actual_members]) |
90 print diff | 58 print diff |
91 self.assertEqual(actual_members, expected_members) | 59 self.assertEqual(actual_members, expected_members) |
OLD | NEW |