changeset 34:f6e1d9a6e0cd

client: change return value of status() to a list of (code, file path)
author Idan Kamara <idankk86@gmail.com>
date Sun, 14 Aug 2011 00:51:15 +0300
parents d74a5891d9d1
children 1e33bbea23e5
files hglib/client.py tests/test-copy.py tests/test-status.py tests/test-update.py
diffstat 4 files changed, 29 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/client.py	Sun Aug 14 00:49:56 2011 +0300
+++ b/hglib/client.py	Sun Aug 14 00:51:15 2011 +0300
@@ -521,7 +521,7 @@
                ignored=False, copies=False, subrepos=False, include=None,
                exclude=None):
         """
-        Return a dictionary with the following keys:
+        Return a list of (code, file path) where code can be:
 
                 M = modified
                 A = added
@@ -531,8 +531,6 @@
                 ? = untracked
                 I = ignored
                   = origin of the previous file listed as A (added)
-
-        And a list of files to match as values.
         """
         if rev and change:
             raise ValueError('cannot specify both rev and change')
@@ -544,14 +542,13 @@
         args.append('-0')
 
         out = self.rawcommand(args)
-        d = dict((c, []) for c in 'MARC!?I')
+        l = []
 
         for entry in out.split('\0'):
             if entry:
-                t, f = entry.split(' ', 1)
-                d[t].append(f)
+                l.append(tuple(entry.rsplit(' ', 1)))
 
-        return d
+        return l
 
     def tip(self):
         args = cmdbuilder('tip', template=templates.changeset)
--- a/tests/test-copy.py	Sun Aug 14 00:49:56 2011 +0300
+++ b/tests/test-copy.py	Sun Aug 14 00:51:15 2011 +0300
@@ -7,10 +7,10 @@
         self.client.commit('first', addremove=True)
 
         self.assertTrue(self.client.copy('a', 'b'))
-        self.assertEquals(self.client.status()['A'], ['b'])
+        self.assertEquals(self.client.status(), [('A', 'b')])
         self.append('c', 'a')
         self.assertTrue(self.client.copy('a', 'c', after=True))
-        self.assertEquals(self.client.status()['A'], ['b', 'c'])
+        self.assertEquals(self.client.status(), [('A', 'b'), ('A', 'c')])
 
     # hg returns 0 even if there were warnings
     #def test_warnings(self):
--- a/tests/test-status.py	Sun Aug 14 00:49:56 2011 +0300
+++ b/tests/test-status.py	Sun Aug 14 00:51:15 2011 +0300
@@ -2,8 +2,7 @@
 
 class test_status(common.basetest):
     def test_empty(self):
-        d = dict((c, []) for c in 'MARC!?I')
-        self.assertEquals(self.client.status(), d)
+        self.assertEquals(self.client.status(), [])
 
     def test_one_of_each(self):
         self.append('.hgignore', 'ignored')
@@ -12,7 +11,7 @@
         self.append('modified', 'a')
         self.append('removed', 'a')
         self.append('missing', 'a')
-        rev0 = self.client.commit('first', addremove=True)
+        self.client.commit('first', addremove=True)
         self.append('modified', 'a')
         self.append('added', 'a')
         self.client.add(['added'])
@@ -20,12 +19,23 @@
         self.client.remove(['removed'])
         self.append('untracked')
 
-        d = {'M' : ['modified'],
-             'A' : ['added'],
-             'R' : ['removed'],
-             'C' : ['.hgignore', 'clean'],
-             '!' : ['missing'],
-             '?' : ['untracked'],
-             'I' : ['ignored']}
+        l = [('M', 'modified'),
+             ('A', 'added'),
+             ('R', 'removed'),
+             ('C', '.hgignore'),
+             ('C', 'clean'),
+             ('!', 'missing'),
+             ('?', 'untracked'),
+             ('I', 'ignored')]
 
-        self.assertEquals(self.client.status(all=True), d)
+        st = self.client.status(all=True)
+
+        for i in l:
+            self.assertTrue(i in st)
+
+    def test_copy(self):
+        self.append('source', 'a')
+        self.client.commit('first', addremove=True)
+        self.client.copy('source', 'dest')
+        l = [('A', 'dest'), (' ', 'source')]
+        self.assertEquals(self.client.status(copies=True), l)
--- a/tests/test-update.py	Sun Aug 14 00:49:56 2011 +0300
+++ b/tests/test-update.py	Sun Aug 14 00:51:15 2011 +0300
@@ -24,7 +24,7 @@
         self.assertEquals(m, 0)
         self.assertEquals(r, 0)
         self.assertEquals(ur, 1)
-        self.assertEquals(self.client.status()['M'][0], 'a')
+        self.assertTrue(('M', 'a') in self.client.status())
 
     def test_merge(self):
         self.append('a', '\n\n\n\nb')
@@ -39,7 +39,7 @@
         self.assertEquals(m, 1)
         self.assertEquals(r, 0)
         self.assertEquals(ur, 0)
-        self.assertEquals(self.client.status()['M'][0], 'a')
+        self.assertEquals(self.client.status(), [('M', 'a')])
 
     def test_tip(self):
         self.client.update(self.rev0)