view tests/test_template_keywords.py @ 1512:6d0fe7ce9898

commands: fix command option registering A recent patch introduced svnopts as a way of sharing the svn command options between the old and the new way of registering a command. It turns out 'svnopts' was already used further up in the module to define the flags that should be added to *all* Mercurial commands. So our definition of it here cause us to add all of these options to all Mercurial commands. This was caught because it changes --rev to be '' instead of [], which breaks a number of assumptions in the other commands. Given that none of the subversion tests are command line tests, I'm not sure how to test this. It was caught in other extensions tests. (grafted from 3b1334407783a4379fd515e2ed9acc61e3f175ff) (grafted from 6db63ead5556f2bf72e423ca8c6df08ea3a5b009)
author Durham Goode <durham@fb.com>
date Wed, 24 May 2017 15:07:00 -0700
parents 8caf1226adec
children
line wrap: on
line source

import test_util

import unittest

from mercurial import commands
from mercurial import error
from mercurial import ui
try:
    from mercurial import templatekw
    templatekw.keywords
except ImportError:
    templatekw = None

try:
    from mercurial import revset
    revset.methods
except ImportError:
    revset = None

class CapturingUI(ui.ui):

    def __init__(self, *args, **kwds):
        super(CapturingUI, self).__init__(*args, **kwds)
        self._output = ""

    def write(self, msg, *args, **kwds):
        self._output += msg


class TestLogKeywords(test_util.TestBase):
    @test_util.requiresmodule(templatekw)
    def test_svn_keywords(self):
        defaults = {'date': None, 'rev': None, 'user': None, 'graph': True}
        repo = self._load_fixture_and_fetch('two_revs.svndump')

        # we want one commit that isn't from Subversion
        self.commitchanges([('foo', 'foo', 'frobnicate\n')])

        ui = CapturingUI()
        commands.log(ui, repo, template=('  rev: {rev} svnrev:{svnrev} '
                                         'svnpath:{svnpath} svnuuid:{svnuuid}\n'),
                     **defaults)
        print ui._output
        self.assertEqual(ui._output.strip(), '''
  rev: 2 svnrev: svnpath: svnuuid:
@
|
  rev: 1 svnrev:3 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
o
|
  rev: 0 svnrev:2 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
o
'''.strip())

    @test_util.requiresmodule(revset)
    @test_util.requiresmodule(templatekw)
    def test_svn_revsets(self):
        repo = self._load_fixture_and_fetch('two_revs.svndump')

        # we want one commit that isn't from Subversion
        self.commitchanges([('foo', 'foo', 'frobnicate\n')])

        defaults = {'date': None, 'rev': ['fromsvn()'], 'user': None}

        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
        self.assertEqual(ui._output, '0:2 1:3 ')

        defaults = {'date': None, 'rev': ['svnrev(2)'], 'user': None}

        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
        self.assertEqual(ui._output, '0:2 ')

        defaults = {'date': None, 'rev': ['fromsvn(1)'], 'user': None}

        self.assertRaises(error.ParseError,
                          commands.log, self.ui(), repo,
                          template='{rev}:{svnrev} ', **defaults)

        defaults = {'date': None, 'rev': ['svnrev(1, 2)'], 'user': None}

        self.assertRaises(error.ParseError,
                          commands.log, self.ui(), repo,
                          template='{rev}:{svnrev} ', **defaults)