tests/test_update.py @ c4095c3519d6

Fixed bug that was thowing a KeyError when including "{bookmark}" in the output.

This resolves issue #17 (Bookmarks have moved into core for 1.8) on https://bitbucket.org/sjl/hg-prompt/.

The end of the stack track was....
-----------------------------
  File "/Users/dak180/Applications/Build/hgExtensions/hg-prompt/prompt.py", line 101, in _bookmark
    book = extensions.find('bookmarks').current(repo)
  File "/sw/lib/python2.6/site-packages/mercurial/extensions.py", line 30, in find
    raise KeyError(name)
KeyError: 'bookmarks'
-----------------------------

I personally was getting this error on mercurial versions 1.8.1 and 1.6.3 (although I am not exactly sure why I got it on 1.6.3).
author Shaun Ek <shaune@providentmetals.com>
date Wed, 23 Mar 2011 15:42:04 -0400
parents 705378546da2
children (none)
'''Test output of {update}.'''

from nose import *
from util import *


@with_setup(setup_sandbox, teardown_sandbox)
def test_empty_repo():
    output = prompt(fs='{update}')
    assert output == ''
    
    output = prompt(fs='{ need to update? {update}}')
    assert output == ''


@with_setup(setup_sandbox, teardown_sandbox)
def test_single_branch():
    hg_commit()
    
    output = prompt(fs='{update}')
    assert output == ''
    
    output = prompt(fs='{ need to update? {update}}')
    assert output == ''
    
    hg_commit()
    
    output = prompt(fs='{update}')
    assert output == ''
    
    output = prompt(fs='{ need to update? {update}}')
    assert output == ''
    
    hg_update(0)
    
    output = prompt(fs='{update}')
    assert output == '^'
    
    output = prompt(fs='{ need to update? {update}}')
    assert output == ' need to update? ^'


@with_setup(setup_sandbox, teardown_sandbox)
def test_multiple_branches():
    hg_commit()
    hg_commit()
    hg_commit()
    
    hg_update(0)
    hg_commit('two.txt')
    hg_commit('two.txt')
    
    #  @    4
    #  |
    #  o    3 
    #  |
    #  | o  2
    #  | |
    #  | o  1
    #  |/
    #  |
    #  o    0
    
    hg_log()
    
    hg_update(4)
    output = prompt(fs='{update}')
    assert output == ''
    
    hg_update(3)
    output = prompt(fs='{update}')
    assert output == '^'
    
    # This test case matches the behavior of Mercurial, but it seems a bit
    # unintuitive to me.
    hg_update(2)
    output = prompt(fs='{update}')
    assert output == '^'
    
    hg_update(1)
    output = prompt(fs='{update}')
    assert output == '^'
    
    hg_update(0)
    output = prompt(fs='{update}')
    assert output == '^'


@with_setup(setup_sandbox, teardown_sandbox)
def test_multiple_named_branches():
    hg_commit()
    hg_commit()
    hg_commit()
    
    hg_update(0)
    hg_branch('test')
    hg_commit('two.txt')
    hg_commit('two.txt')
    
    #  @    4 (test)
    #  |
    #  o    3 (test)
    #  |
    #  | o  2 (default)
    #  | |
    #  | o  1 (default)
    #  |/
    #  |
    #  o    0 (default)
    
    hg_log()
    
    hg_update(4)
    output = prompt(fs='{update}')
    assert output == ''
    
    hg_update(3)
    output = prompt(fs='{update}')
    assert output == '^'
    
    hg_update(2)
    output = prompt(fs='{update}')
    assert output == ''
    
    hg_update(1)
    output = prompt(fs='{update}')
    assert output == '^'
    
    hg_update(0)
    output = prompt(fs='{update}')
    assert output == '^'