comparison tests/test_util.py @ 1101:4a92eb1484ba

layouts: fix crash when importing hgsubversion itself (issue #402) Mercurial extensions are a bit weird: they aren't normally in sys.path, so you can't assume that "import hgsubversion" works. Luckily, Mercurial sneaks a little treat into sys.modules so that "import hgext_hgsubversion" does work. In fact, to get things working *as a Mercurial extension*, all that's needed is that trivial change to two import lines, in layouts/detect.py and layouts/standard.py. Unfortunately, hgsubversion is also imported as a Python module, in its own test suite. In that context, there is no "hgext_" trick -- unless we do it in ourselves, which I've done in TestBase.setUp(). That would work fine ... except that test_util imports from hgsubversion, which ends up importing hgsubversion.layouts.{detect,standard}, which want the "hgext_" trick to work. But it hasn't been done yet when we're still importing; it doesn't happen until setUp() runs. So make those two imports happen late, in the functions that need them. Incidentally, this is only necessary to support Mercurial <= 2.7. Mercurial got a bit smarter in 2.8: http://selenic.com/repo/hg/rev/621a26eb3a99
author Greg Ward <greg@gerg.ca>
date Thu, 02 Jan 2014 21:53:39 -0500
parents cd0d14e25757
children a22d4972e01f
comparison
equal deleted inserted replaced
1100:91cf81a36236 1101:4a92eb1484ba
432 432
433 stupid = False 433 stupid = False
434 434
435 def setUp(self): 435 def setUp(self):
436 _verify_our_modules() 436 _verify_our_modules()
437 if 'hgsubversion' in sys.modules:
438 sys.modules['hgext_hgsubversion'] = sys.modules['hgsubversion']
437 439
438 # the Python 2.7 default of 640 is obnoxiously low 440 # the Python 2.7 default of 640 is obnoxiously low
439 self.maxDiff = 4096 441 self.maxDiff = 4096
440 442
441 self.oldenv = dict([(k, os.environ.get(k, None),) for k in 443 self.oldenv = dict([(k, os.environ.get(k, None),) for k in