Source

tcvshg / tests / __init__.py

import os, tempfile, shutil
from nose.tools import *
from mercurial import ui, commands, error
from tortoisehg.util import hglib
from tortoisehg.hgqt import thgrepo

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)


def create_fixture_repo(name, dirname=None):
    """Create the fixture repo and return thgrepo object"""
    path = os.path.join(_reposdir, dirname or name)
    repo = thgrepo.repository(ui.ui(), path, create=True)
    commands.import_(repo.ui, repo, os.path.join(FIXTURES_DIR, name + '.diff'),
                     base='', strip=1, exact=True)
    return repo

def get_fixture_repo(name):
    """Return the thgrepo object for the specified fixture repo"""
    path = os.path.join(_reposdir, name)
    try:
        return thgrepo.repository(ui.ui(), path)
    except error.RepoError:
        return create_fixture_repo(name)


def with_encoding(encoding, fallbackencoding=None):
    """Change locale encoding temporarily"""
    orig_encoding = hglib._encoding
    orig_fallbackencoding = hglib._fallbackencoding

    def setenc():
        hglib._encoding = encoding
        hglib._fallbackencoding = fallbackencoding or encoding

    def restoreenc():
        hglib._encoding = orig_encoding
        hglib._fallbackencoding = orig_fallbackencoding

    return with_setup(setenc, restoreenc)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.