view tests/common.py @ 123:cdde1656346f

client: add 'hidden' property to show hidden changesets. This enables interactions with the obsolete changesets in the repository: - add the attribute in client class - add the keyword to the relevant commands - enable log without hidden changesets even when self.hidden is True - add a few tests with the hidden keyword This changeset mirrors the behavior of the mercurial global command --hidden: an attribute is added to the client library. If set at True, adds the hidden keyword to all command which can use it to show hidden changesets. The alternative would be to add the keyword in rawcommand, but the hidden flag is not relevant for commands such as add or branch.
author Paul Tonelli <paul.tonelli@logilab.fr>
date Thu, 22 May 2014 15:23:12 +0200
parents d1a42c1d0b61
children 1b47146a4a2c
line wrap: on
line source

import os, sys, tempfile, shutil
import unittest

import hglib
from hglib import client

def resultappender(list):
    def decorator(f):
        def decorated(*args, **kwargs):
            list.append(args[0])
            return f(*args, **kwargs)
        return decorated
    return decorator

class basetest(unittest.TestCase):
    def setUp(self):
        self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
            os.path.join(os.environ["HGTMP"], self.__class__.__name__)

        self.clients = []
        self._oldopen = hglib.client.hgclient.open
        # hglib.open = resultappender(self.clients)(hglib.open)
        hglib.client.hgclient.open = resultappender(self.clients)(hglib.client.hgclient.open)

        os.mkdir(self._testtmp)
        os.chdir(self._testtmp)
        # until we can run norepo commands in the cmdserver
        os.system('hg init')
        self.client = hglib.open()

    def tearDown(self):
        # on Windows we cannot rmtree before closing all instances because of used
        # files
        hglib.client.hgclient.open = self._oldopen
        for client in self.clients:
            if client.server is not None:
                client.close()
        os.chdir('..')
        try:
            shutil.rmtree(self._testtmp)
        except AttributeError:
            pass # if our setUp was overriden

    def append(self, path, *args):
        f = open(path, 'ab')
        for a in args:
            f.write(str(a))
        f.close()