Commit 4d22dd5e authored by Yuya Nishihara's avatar Yuya Nishihara

tests: use unified temporary directory and add option to keep the content

It adds a little script to run nosetests with the helper plugin.

--HG--
branch : stable
parent 386ac935b51d
......@@ -4,16 +4,13 @@ from mercurial import ui, commands, error
from tortoisehg.util import hglib
from tortoisehg.hgqt import thgrepo
import helpers
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixtures')
def setup():
global _tempdir, _reposdir
_tempdir = tempfile.mkdtemp()
_reposdir = os.path.join(_tempdir, 'repos')
os.mkdir(_reposdir)
def teardown():
shutil.rmtree(_tempdir)
global _reposdir
_reposdir = helpers.mktmpdir('repos')
def create_fixture_repo(name, dirname=None):
......
"""Helper functions or classes imported from test case"""
import os, tempfile
def mktmpdir(prefix):
"""Create temporary directory under HGTMP"""
return tempfile.mkdtemp('', prefix, os.environ['HGTMP'])
"""Nose plugin to set up test environment"""
import os, shutil, tempfile
from nose import plugins
class HgEnvPlugin(plugins.Plugin):
"""Set up temporary environment"""
enabled = True
name = 'hgenv'
def options(self, parser, env):
parser.add_option('--keep-tmpdir', action='store_true', default=False,
help='Keep temporary directory after running tests')
parser.add_option('--tmpdir',
help=('Put temporary files in the given directory '
'(implies --keep-tmpdir)'))
def configure(self, options, conf):
self.keep_tmpdir = options.keep_tmpdir or bool(options.tmpdir)
self.tmpdir = options.tmpdir
def begin(self):
self._setuptmpdir()
def _setuptmpdir(self):
if self.tmpdir:
if os.path.exists(self.tmpdir):
raise Exception('temp dir %r already exists' % self.tmpdir)
os.makedirs(self.tmpdir)
else:
self.tmpdir = tempfile.mkdtemp('', 'thgtests.')
os.environ['HGTMP'] = self.tmpdir
def finalize(self, result):
if not self.keep_tmpdir:
shutil.rmtree(self.tmpdir)
#!/usr/bin/env python
"""Run a set of tests by nosetests
For details, please see:
- `./run-tests.py --help`
- http://readthedocs.org/docs/nose/en/latest/
- http://docs.python.org/library/unittest.html
"""
import os, sys
import nose
import nosehgenv
if __name__ == '__main__':
nose.main(addplugins=[nosehgenv.HgEnvPlugin()])
import os, tempfile, shutil
import os, tempfile
from nose.tools import *
from nose.plugins.skip import SkipTest
from StringIO import StringIO
from mercurial import config, error
from tortoisehg.util import wconfig
import helpers
def setup():
global _tempdir
_tempdir = tempfile.mkdtemp()
def teardown():
shutil.rmtree(_tempdir)
_tempdir = helpers.mktmpdir(__name__)
def newrconfig(vals={}):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment