tests/test-hgwebdir-paths.py
author Sean Farley <sean.michael.farley@gmail.com>
Sat, 13 Jul 2013 19:59:21 -0500
changeset 19537 6e3e8575276d
parent 15381 c519cd8f0169
child 28932 4eac86331acb
permissions -rw-r--r--
basectx: add an empty class that will be used as a parent of all contexts At the moment, there is no simple way to check if an object is a context because there is no common parent class. If there were, we could use 'isinstance' everywhere. Simply having memctx inherit from workingctx or changectx would allow the use of 'isinstance' but that could lead to some confusing situations of reading the code since we have three distinct concepts of a context: - changectx represents a changeset *already* in the repo, and is therefore immutable - workingctx represents changes on disk in the working directory - memctx represents changes solely in memory which may or may not be on disk Therefore, I propose refactoring context.py to have all three contexts inherit from a parent class 'basectx'.

import os
from mercurial import hg, ui
from mercurial.hgweb.hgwebdir_mod import hgwebdir

os.mkdir('webdir')
os.chdir('webdir')

webdir = os.path.realpath('.')

u = ui.ui()
hg.repository(u, 'a', create=1)
hg.repository(u, 'b', create=1)
os.chdir('b')
hg.repository(u, 'd', create=1)
os.chdir('..')
hg.repository(u, 'c', create=1)
os.chdir('..')

paths = {'t/a/': '%s/a' % webdir,
         'b': '%s/b' % webdir,
         'coll': '%s/*' % webdir,
         'rcoll': '%s/**' % webdir}

config = os.path.join(webdir, 'hgwebdir.conf')
configfile = open(config, 'w')
configfile.write('[paths]\n')
for k, v in paths.items():
    configfile.write('%s = %s\n' % (k, v))
configfile.close()

confwd = hgwebdir(config)
dictwd = hgwebdir(paths)

assert len(confwd.repos) == len(dictwd.repos), 'different numbers'
assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos)

found = dict(confwd.repos)
for key, path in dictwd.repos:
    assert key in found, 'repository %s was not found' % key
    assert found[key] == path, 'different paths for repo %s' % key