Mercurial > hgsubversion
comparison tests/test_util.py @ 645:3cb5042531fb
tests: verify locations of any imported hgsubversion modules
| author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
|---|---|
| date | Wed, 14 Jul 2010 15:39:24 +0200 |
| parents | 95abc4cfc78f |
| children | c3900ad3bf69 |
comparison
equal
deleted
inserted
replaced
| 644:95abc4cfc78f | 645:3cb5042531fb |
|---|---|
| 140 raise | 140 raise |
| 141 if (s.st_mode & stat.S_IWRITE) == 0: | 141 if (s.st_mode & stat.S_IWRITE) == 0: |
| 142 os.chmod(f, s.st_mode | stat.S_IWRITE) | 142 os.chmod(f, s.st_mode | stat.S_IWRITE) |
| 143 shutil.rmtree(path) | 143 shutil.rmtree(path) |
| 144 | 144 |
| 145 def _verify_our_modules(): | |
| 146 ''' | |
| 147 Verify that hgsubversion was imported from the correct location. | |
| 148 | |
| 149 The correct location is any location within the parent directory of the | |
| 150 directory containing this file. | |
| 151 ''' | |
| 152 | |
| 153 for modname, module in sys.modules.iteritems(): | |
| 154 if not module or not modname.startswith('hgsubversion.'): | |
| 155 continue | |
| 156 | |
| 157 modloc = module.__file__ | |
| 158 cp = os.path.commonprefix((os.path.abspath(__file__), modloc)) | |
| 159 assert cp.rstrip(os.sep) == _rootdir, ( | |
| 160 'Module location verification failed: hgsubversion was imported ' | |
| 161 'from the wrong path!' | |
| 162 ) | |
| 145 | 163 |
| 146 class TestBase(unittest.TestCase): | 164 class TestBase(unittest.TestCase): |
| 147 def setUp(self): | 165 def setUp(self): |
| 166 _verify_our_modules() | |
| 167 | |
| 148 self.oldenv = dict([(k, os.environ.get(k, None), ) for k in | 168 self.oldenv = dict([(k, os.environ.get(k, None), ) for k in |
| 149 ('LANG', 'LC_ALL', 'HGRCPATH', )]) | 169 ('LANG', 'LC_ALL', 'HGRCPATH', )]) |
| 150 self.oldt = i18n.t | 170 self.oldt = i18n.t |
| 151 os.environ['LANG'] = os.environ['LC_ALL'] = 'C' | 171 os.environ['LANG'] = os.environ['LC_ALL'] = 'C' |
| 152 i18n.t = gettext.translation('hg', i18n.localedir, fallback=True) | 172 i18n.t = gettext.translation('hg', i18n.localedir, fallback=True) |
| 179 os.environ[var] = val | 199 os.environ[var] = val |
| 180 i18n.t = self.oldt | 200 i18n.t = self.oldt |
| 181 rmtree(self.tmpdir) | 201 rmtree(self.tmpdir) |
| 182 os.chdir(self.oldwd) | 202 os.chdir(self.oldwd) |
| 183 setattr(ui.ui, self.patch[0].func_name, self.patch[0]) | 203 setattr(ui.ui, self.patch[0].func_name, self.patch[0]) |
| 204 | |
| 205 _verify_our_modules() | |
| 184 | 206 |
| 185 def assertStringEqual(self, l, r): | 207 def assertStringEqual(self, l, r): |
| 186 try: | 208 try: |
| 187 self.assertEqual(l, r, 'failed string equality check, see stdout for details') | 209 self.assertEqual(l, r, 'failed string equality check, see stdout for details') |
| 188 except: | 210 except: |
