Changeset 8 in tailor


Ignore:
Timestamp:
06/03/04 00:57:51 (9 years ago)
Author:
lele@…
Hash name:
20040602225751-97f81-1c36a93fad42a806dc78c71fb57407335ad81be1
Message:

Better tests for new return of merge and update

Location:
cvsync
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cvsync/svn.py

    r6 r8  
    1919 
    2020class SvnUpdate(SystemCommand): 
    21     COMMAND = "svn update --quiet --revision %(revision)s %(entry)s" 
     21    COMMAND = "svn update --revision %(revision)s %(entry)s" 
    2222 
    2323 
     
    248248         
    249249    def update(self, revision="HEAD"): 
    250         """Bring this directory up to its HEAD revision in the repository.""" 
     250        """ 
     251        Bring this directory up to its HEAD revision in the 
     252        repository.  Return a dictionary of changed items, grouped by 
     253        kind of change. 
     254        """ 
    251255 
    252256        svnup = SvnUpdate() 
    253         svnup(entry=self.root, revision=revision) 
     257        out = svnup(output=True, entry=self.root, revision=revision) 
     258         
     259        result = {} 
     260        for line in out: 
     261            if len(line)>2 and line[0] in 'ADUCG' and line[1] == ' ': 
     262                try: result[line[0]].append(line[2:-1]) 
     263                except KeyError: result[line[0]] = [line[2:-1]] 
     264             
     265        return result 
    254266     
    255267    def commit(self, logfile=None, message=None): 
     
    342354 
    343355    def merge(self, uri, startrev, endrev, dest, dry_run=False): 
    344         """Perform the merge.""" 
     356        """ 
     357        Perform the merge and return a dictionary of changed items, 
     358        grouped by kind of change.""" 
    345359 
    346360        svnm = SvnMerge() 
     
    348362                   source=uri, dest=dest, dry_run=dry_run) 
    349363 
    350         merged = False 
     364        result = {} 
    351365        if not dry_run: 
    352366            for line in out: 
    353                 if line.startswith('C '): 
    354                     print "CONFLICT:", line 
    355                 merged = True 
    356              
    357         return merged 
     367                if len(line)>2 and line[0] in 'ADUCG' and line[1] == ' ': 
     368                    try: result[line[0]].append(line[2:-1]) 
     369                    except KeyError: result[line[0]] = [line[2:-1]] 
     370             
     371        return result 
    358372 
    359373    def diff(self, uri, rev): 
  • cvsync/tailor.py

    r6 r8  
    140140        if options.svn_update and not options.dry_run: 
    141141            self.wc.update() 
     142             
    142143        return self.merge(options) 
    143144 
     
    179180                path,action = event 
    180181                oldpath = action[1] 
    181                 if pathactions.get(oldpath) == u'D': 
     182                if pathactions.get(oldpath) == 'D': 
    182183                    dwc.rename(oldpath, path) 
    183184                    done[path] = done[oldpath] = True 
     
    190191                if done.get(path): continue 
    191192                 
    192                 if action == u'D': 
     193                if action == 'D': 
    193194                    dwc.remove(path) 
    194195 
     
    308309        Fetch the upstream info and perform a merge of the eventual changes, 
    309310        then update the properties. 
     311 
     312        Return True if there something to commit, False otherwise. 
    310313        """ 
    311314 
     
    317320        head = getHeadRevision(uri, rev) 
    318321        if rev <> head: 
    319             merged = self.wc.merge(uri, rev, head, 
    320                                    self.project, dry_run=options.dry_run) 
     322            changes = self.wc.merge(uri, rev, head, 
     323                                    self.project, dry_run=options.dry_run) 
     324 
     325            conflicts = changes.get('C') 
     326            if conflicts: 
     327                print "CONFLICT:", conflicts 
     328 
     329            merged = len(changes)<>0 
    321330            if merged: 
    322331                self.updateUpstreamInfo(rev=head) 
  • cvsync/tests/svn.py

    r4 r8  
    2626 
    2727    def __init__(self, path): 
    28         from os.path import abspath, join, exists 
     28        from os.path import abspath, exists 
    2929 
    3030        self.repospath = path 
     
    5151        TestCase.__init__(self, methodName) 
    5252 
    53         repos = '/tmp/cvsync.test' 
     53        repos = '/tmp/basic.rep' 
    5454        self.repos = TestRepository(repos) 
    55         wc = '/tmp/cvsync.wc' 
     55        wc = '/tmp/basic.wc' 
    5656        self.wc = SvnWorkingDir(wc) 
    5757 
     58    def __del__(self): 
     59        from shutil import rmtree 
     60        from os.path import exists 
     61         
     62        if exists(self.repos.repospath): rmtree(self.repos.repospath) 
     63        if exists(self.wc.root): rmtree(self.wc.root) 
     64         
    5865    def testCheckout(self): 
    5966        """Verify that svn checkout returns right info""" 
     
    6269        self.assertEqual(info['URL'], self.repos.reposurl) 
    6370        self.assertEqual(info['Revision'], '0') 
    64      
     71 
     72    def testInfoA_update(self): 
     73        """Verify update return right info""" 
     74 
     75        changes = self.wc.update(revision='1') 
     76        self.assertEqual(len(changes), 1) 
     77        self.assertEqual(len(changes['A']), 6) 
     78         
     79    def testInfoB_merge(self): 
     80        """Verify merge return right info""" 
     81 
     82        changes = self.wc.merge(self.repos.reposurl, '1', '2', self.wc.root) 
     83        self.assertEqual(len(changes), 1) 
     84        self.assertEqual(len(changes['U']), 3) 
     85 
     86    def testInfoC_update(self): 
     87        """Verify update after merge return right info""" 
     88 
     89        changes = self.wc.update(revision='2') 
     90        self.assertEqual(len(changes), 1) 
     91        self.assertEqual(len(changes['G']), 3) 
     92         
    6593class SvnLogTest(TestCase): 
    6694    """Test `svn log` parse functionality.""" 
    6795 
    6896    def __init__(self, methodName): 
     97        TestCase.__init__(self, methodName) 
     98 
     99        repos = '/tmp/log.rep' 
     100        self.repos = TestRepository(repos) 
     101        wc = '/tmp/log.wc' 
     102        self.wc = SvnWorkingDir(wc) 
     103        self.wc.checkout(self.repos.reposurl + '@0') 
     104 
     105    def __del__(self): 
     106        from shutil import rmtree 
    69107        from os.path import exists 
    70108         
    71         TestCase.__init__(self, methodName) 
    72  
    73         repos = '/tmp/cvsync.test' 
    74         self.repos = TestRepository(repos) 
    75         wc = '/tmp/cvsync.wc' 
    76         self.wc = SvnWorkingDir(wc) 
    77         if not exists(wc): 
    78             self.wc.checkout(self.repos.reposurl + '@0') 
     109        if exists(self.repos.repospath): rmtree(self.repos.repospath) 
     110        if exists(self.wc.root): rmtree(self.wc.root) 
    79111         
    80112    def testLogParser(self): 
Note: See TracChangeset for help on using the changeset viewer.