PageRenderTime 25ms CodeModel.GetById 2ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/qt_manifestmodel_test.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 154 lines | 146 code | 8 blank | 0 comment | 2 complexity | 877dcfb2721c74f49e95d503e4f5c8f3 MD5 | raw file
  1from nose.tools import *
  2from PyQt4.QtCore import QModelIndex, QString
  3from tortoisehg.hgqt.manifestmodel import ManifestModel
  4from tests import get_fixture_repo, with_encoding
  5
  6_aloha_ja = u'\u3042\u308d\u306f\u30fc'
  7
  8def setup():
  9    global _repos
 10    _repos = {}
 11    for name in ('subdirs', 'euc-jp-path'):
 12        _repos[name] = get_fixture_repo(name)
 13
 14def newmodel(name='subdirs', rev=0):
 15    return ManifestModel(_repos[name], rev=rev)
 16
 17def test_data():
 18    m = newmodel()
 19    assert_equals('bar', m.data(m.index(1, 0)))
 20    assert_equals('baz', m.data(m.index(0, 0)))
 21    assert_equals('foo', m.data(m.index(2, 0)))
 22
 23def test_data_subdir():
 24    m = newmodel()
 25    assert_equals('bax', m.data(m.index(0, 0, m.index(0, 0))))
 26    assert_equals('box', m.data(m.index(1, 0, m.index(0, 0))))
 27
 28def test_data_inexistent():
 29    m = newmodel()
 30    assert_equals(None, m.data(QModelIndex()))
 31    assert_equals(None, m.data(m.index(0, 0, m.index(1, 0))))
 32
 33@with_encoding('euc-jp')
 34def test_data_eucjp():
 35    m = newmodel(name='euc-jp-path')
 36    assert_equals(_aloha_ja, m.data(m.index(0, 0)))
 37
 38def test_isdir():
 39    m = newmodel()
 40    assert m.isDir(m.indexFromPath(''))
 41    assert m.isDir(m.indexFromPath('baz'))
 42    assert not m.isDir(m.indexFromPath('foo'))
 43
 44def test_rowcount():
 45    m = newmodel()
 46    assert_equals(3, m.rowCount())
 47
 48def test_rowcount_subdirs():
 49    m = newmodel()
 50    assert_equals(2, m.rowCount(m.index(0, 0)))
 51
 52def test_rowcount_invalid():
 53    m = newmodel()
 54    assert_equals(0, m.rowCount(m.index(1, 0)))
 55
 56def test_pathfromindex():
 57    m = newmodel()
 58    assert_equals('', m.filePath(QModelIndex()))
 59    assert_equals('bar', m.filePath(m.index(1, 0)))
 60    assert_equals('baz', m.filePath(m.index(0, 0)))
 61    assert_equals('baz/bax', m.filePath(m.index(0, 0, m.index(0, 0))))
 62
 63@with_encoding('euc-jp')
 64def test_pathfromindex_eucjp():
 65    m = newmodel(name='euc-jp-path')
 66    assert_equals(_aloha_ja, m.filePath(m.index(0, 0)))
 67
 68def test_indexfrompath():
 69    m = newmodel()
 70    assert_equals(QModelIndex(), m.indexFromPath(''))
 71    assert_equals(m.index(1, 0), m.indexFromPath('bar'))
 72    assert_equals(m.index(0, 0), m.indexFromPath('baz'))
 73    assert_equals(m.index(0, 0, m.index(0, 0)), m.indexFromPath('baz/bax'))
 74
 75def test_indexfrompath_qstr():
 76    m = newmodel()
 77    assert_equals(m.index(1, 0), m.indexFromPath(QString('bar')))
 78
 79@with_encoding('euc-jp')
 80def test_indexfrompath_eucjp():
 81    m = newmodel(name='euc-jp-path')
 82    assert_equals(m.index(0, 0), m.indexFromPath(_aloha_ja))
 83
 84def test_removed_should_be_listed():
 85    m = newmodel(rev=1)
 86    m.setStatusFilter('MARC')
 87    assert m.indexFromPath('baz/box').isValid()
 88
 89def test_status_role():
 90    m = newmodel(rev=0)
 91    assert_equals('A', m.data(m.indexFromPath('foo'),
 92                                  role=ManifestModel.StatusRole))
 93
 94    m = newmodel(rev=1)
 95    m.setStatusFilter('MARC')
 96    assert_equals('C', m.data(m.indexFromPath('foo'),
 97                              role=ManifestModel.StatusRole))
 98    assert_equals('R', m.data(m.indexFromPath('baz/box'),
 99                              role=ManifestModel.StatusRole))
100
101def test_status_role_invalid():
102    m = newmodel()
103    assert_equals(None, m.data(QModelIndex(),
104                               role=ManifestModel.StatusRole))
105
106def test_status_filter_modified():
107    m = newmodel(rev=1)
108    m.setStatusFilter('M')
109    assert_not_equals(QModelIndex(), m.indexFromPath('bar'))  # modified
110    assert_equals(QModelIndex(), m.indexFromPath('zzz'))  # added
111    assert_equals(QModelIndex(), m.indexFromPath('baz/box'))  # removed
112    assert_equals(QModelIndex(), m.indexFromPath('foo'))  # clean
113
114def test_status_filter_added():
115    m = newmodel(rev=1)
116    m.setStatusFilter('A')
117    assert_equals(QModelIndex(), m.indexFromPath('bar'))  # modified
118    assert_not_equals(QModelIndex(), m.indexFromPath('zzz'))  # added
119    assert_equals(QModelIndex(), m.indexFromPath('baz/box'))  # removed
120    assert_equals(QModelIndex(), m.indexFromPath('foo'))  # clean
121
122def test_status_filter_removed():
123    m = newmodel(rev=1)
124    m.setStatusFilter('R')
125    assert_equals(QModelIndex(), m.indexFromPath('bar'))  # modified
126    assert_equals(QModelIndex(), m.indexFromPath('zzz'))  # added
127    assert_not_equals(QModelIndex(), m.indexFromPath('baz/box'))  # removed
128    assert_equals(QModelIndex(), m.indexFromPath('foo'))  # clean
129
130def test_status_filter_clean():
131    m = newmodel(rev=1)
132    m.setStatusFilter('C')
133    assert_equals(QModelIndex(), m.indexFromPath('bar'))  # modified
134    assert_equals(QModelIndex(), m.indexFromPath('zzz'))  # added
135    assert_equals(QModelIndex(), m.indexFromPath('baz/box'))  # removed
136    assert_not_equals(QModelIndex(), m.indexFromPath('foo'))  # clean
137
138def test_status_filter_change():
139    m = newmodel(rev=1)
140    m.setStatusFilter('C')
141    assert_equals(QModelIndex(), m.indexFromPath('bar'))  # modified
142    assert_not_equals(QModelIndex(), m.indexFromPath('foo'))  # clean
143
144    m.setStatusFilter('M')
145    assert_not_equals(QModelIndex(), m.indexFromPath('bar'))  # modified
146    assert_equals(QModelIndex(), m.indexFromPath('foo'))  # clean
147
148def test_status_filter_multi():
149    m = newmodel(rev=1)
150    m.setStatusFilter('MC')
151    assert_not_equals(QModelIndex(), m.indexFromPath('bar'))  # modified
152    assert_equals(QModelIndex(), m.indexFromPath('zzz'))  # added
153    assert_equals(QModelIndex(), m.indexFromPath('baz/box'))  # removed
154    assert_not_equals(QModelIndex(), m.indexFromPath('foo'))  # clean