Yuya Nishihara avatar Yuya Nishihara committed eef147e

tests: manifestmodel: add basic tests for subrepo attributes and filter

Comments (0)

Files changed (1)

tests/qt_manifestmodel_test.py

     global _tmpdir
     _tmpdir = helpers.mktmpdir(__name__)
 
+def alldata(model, parent=QModelIndex()):
+    return [model.data(model.index(r, 0, parent))
+            for r in xrange(model.rowCount(parent))]
+
+
 class ManifestModelTest(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
         hg.ftouch('foo', 'bar', 'baz/bax', 'baz/box')
         hg.addremove()
         hg.commit('-m', 'foobar')
+
         hg.fwrite('bar', 'hello\n')
         hg.remove('baz/box')
         hg.ftouch('zzz')
         hg.addremove()
         hg.commit('-m', 'remove baz/box, add zzz, modify bar')
+
+        hg.clone('-U', '.', 'sub')
+        hg.fappend('.hgsub', 'sub = sub\n')
+        hg.commit('-Am', 'add empty sub')
+
+        hg.update('-R', 'sub', '1')
+        hg.commit('-Am', 'update sub')
+
         cls.repo = thgrepo.repository(path=hg.path)
 
     @classmethod
         self.assertEqual(None, m.data(QModelIndex()))
         self.assertEqual(None, m.data(m.index(0, 0, m.index(1, 0))))
 
+    def test_data_subrepo(self):
+        m = self.new_model(3)
+        self.assertEqual(['baz', 'sub', '.hgsub'],  alldata(m)[:3])
+        self.assertEqual(['baz', 'bar', 'foo', 'zzz'],
+                         alldata(m, m.indexFromPath('sub')))
+
+    def test_data_empty_subrepo(self):
+        m = self.new_model(2)
+        # FIXME: empty subrepo should be sorted as dir, but actually it isn't
+        #self.assertEqual(['baz', 'sub', '.hgsub'],  alldata(m)[:3])
+
     def test_isdir(self):
-        m = self.new_model(0)
+        m = self.new_model(3)
         self.assertTrue(m.isDir(m.indexFromPath('')))
         self.assertTrue(m.isDir(m.indexFromPath('baz')))
         self.assertFalse(m.isDir(m.indexFromPath('foo')))
+        self.assertTrue(m.isDir(m.indexFromPath('sub')))
+        self.assertFalse(m.isDir(m.indexFromPath('sub/foo')))
+        self.assertTrue(m.isDir(m.indexFromPath('sub/baz')))
 
     def test_rowcount(self):
         m = self.new_model(0)
         m = self.new_model(0)
         self.assertEqual(m.index(1, 0), m.indexFromPath(QString('bar')))
 
+    def test_subrepotype(self):
+        m = self.new_model(2)
+        self.assertEqual('hg', m.subrepoType(m.indexFromPath('sub')))
+        self.assertEqual(None, m.subrepoType(m.indexFromPath('foo')))
+
     def test_removed_should_be_listed(self):
         m = self.new_model(1)
         m.setStatusFilter('MARC')
         self.assertEqual('R', m.data(m.indexFromPath('baz/box'),
                                      role=ManifestModel.StatusRole))
 
+        m = self.new_model(2)
+        self.assertEqual('S', m.data(m.indexFromPath('sub'),
+                                     role=ManifestModel.StatusRole))
+
     def test_status_role_invalid(self):
         m = self.new_model(0)
         self.assertEqual(None, m.data(QModelIndex(),
         self.assertNotEqual(QModelIndex(), m.indexFromPath('bar'))  # modified
         self.assertEqual(QModelIndex(), m.indexFromPath('foo'))  # clean
 
+    def test_status_filter_subrepo(self):
+        m = self.new_model(3)
+        m.setStatusFilter('S')
+        self.assertTrue(m.indexFromPath('sub').isValid())
+        self.assertEqual(1, m.rowCount())
+        self.assertEqual(0, m.rowCount(m.indexFromPath('sub')))
+
     def test_status_filter_multi(self):
         m = self.new_model(1)
         m.setStatusFilter('MC')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.