contrib/casesmash.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sun, 20 Apr 2014 11:22:08 -0700
changeset 21426 791bdd65acd3
parent 19378 9de689d20230
child 28351 42a7301fb4d5
permissions -rw-r--r--
run-tests: initial support for running tests with unittest The unittest package in Python's standard library provides an almost universal mechanism for defining and running tests. This patch starts the process of making run-tests.py talk to it. The main benefit of speaking unittest is that this will enable Mercurial's tests to be more easily consumed by other testing tools, like nose. This is useful for 3rd party extensions having their own test infrastructure, for example. Running tests in unittest mode will not result in completely sane behavior until the unittest mode is made the default execution mode. Expect things like double printing of output until support stabilizes.

import os, __builtin__
from mercurial import util

def lowerwrap(scope, funcname):
    f = getattr(scope, funcname)
    def wrap(fname, *args, **kwargs):
        d, base = os.path.split(fname)
        try:
            files = os.listdir(d or '.')
        except OSError:
            files = []
        if base in files:
            return f(fname, *args, **kwargs)
        for fn in files:
            if fn.lower() == base.lower():
                return f(os.path.join(d, fn), *args, **kwargs)
        return f(fname, *args, **kwargs)
    scope.__dict__[funcname] = wrap

def normcase(path):
    return path.lower()

os.path.normcase = normcase

for f in 'file open'.split():
    lowerwrap(__builtin__, f)

for f in "chmod chown open lstat stat remove unlink".split():
    lowerwrap(os, f)

for f in "exists lexists".split():
    lowerwrap(os.path, f)

lowerwrap(util, 'posixfile')