| 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 |
| 12 mox = None | 12 mox = None |
| 13 | 13 |
| 14 def OnTestsLoad(): | 14 def OnTestsLoad(): |
| 15 import sys | 15 import sys |
| 16 old_path = sys.path | 16 old_path = sys.path |
| 17 global mox | 17 global mox |
| 18 try: | 18 try: |
| 19 directory, _file = os.path.split(__file__) | 19 directory, _file = os.path.split(__file__) |
| 20 sys.path.append(os.path.abspath(os.path.join(directory, 'pymox'))) | 20 sys.path.append(os.path.abspath(os.path.join(directory, 'pymox'))) |
| 21 sys.path.append(os.path.abspath(os.path.join(directory, '..'))) | 21 sys.path.append(os.path.abspath(os.path.join(directory, '..'))) |
| 22 try: | 22 try: |
| 23 import mox as Mox | 23 import mox as Mox |
| 24 mox = Mox | 24 mox = Mox |
| 25 except ImportError: | 25 except ImportError: |
| 26 print "Trying to automatically checkout pymox." | 26 print "Trying to automatically checkout pymox." |
| 27 import subprocess | 27 import subprocess |
| 28 subprocess.call(['svn', 'co', 'http://pymox.googlecode.com/svn/trunk', | 28 subprocess.call(['svn', 'co', 'http://pymox.googlecode.com/svn/trunk', |
| 29 os.path.join(directory, 'pymox')], | 29 os.path.join(directory, 'pymox')], |
| 30 shell=True) | 30 shell=sys.platform.startswith('win')) |
| 31 try: | 31 try: |
| 32 import mox as Mox | 32 import pymox.mox as Mox |
| 33 mox = Mox | 33 mox = Mox |
| 34 except ImportError: | 34 except ImportError: |
| 35 print >> sys.stderr, ("\nError, failed to load pymox\n") | 35 print >> sys.stderr, ("\nError, failed to load pymox\n") |
| 36 raise | 36 raise |
| 37 finally: | 37 finally: |
| 38 # Restore the path | 38 # Restore the path |
| 39 sys.path = old_path | 39 sys.path = old_path |
| 40 | 40 |
| 41 | 41 |
| 42 # Automatically fetch pymox. | 42 # Automatically fetch pymox. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 # Skip over members starting with '_' since they are usually not meant to | 82 # Skip over members starting with '_' since they are usually not meant to |
| 83 # be for public use. | 83 # be for public use. |
| 84 actual_members = [x for x in sorted(dir(object)) | 84 actual_members = [x for x in sorted(dir(object)) |
| 85 if not x.startswith('_')] | 85 if not x.startswith('_')] |
| 86 expected_members = sorted(members) | 86 expected_members = sorted(members) |
| 87 if actual_members != expected_members: | 87 if actual_members != expected_members: |
| 88 diff = ([i for i in actual_members if i not in expected_members] + | 88 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]) | 89 [i for i in expected_members if i not in actual_members]) |
| 90 print diff | 90 print diff |
| 91 self.assertEqual(actual_members, expected_members) | 91 self.assertEqual(actual_members, expected_members) |
| OLD | NEW |