/tests/qt_manifestmodel_test.py

https://bitbucket.org/tortoisehg/hgtk/ · Python · 154 lines · 127 code · 27 blank · 0 comment · 1 complexity · 877dcfb2721c74f49e95d503e4f5c8f3 MD5 · raw file

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