~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/clean_tree.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 07:12:26 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129071226-a04b3f827880025d
Unshelve --pick was broken, because we deleted the whole patch, even when only
part of it was unshelved. So now if we unshelve part of a patch, the patch is
replaced with a new patch that has just the unshelved parts. That's a long way
of saying it does what you'd expect.

Implementing this required changing HunkSelector to return both the selected,
and unselected hunks (ie. patches to shelve, and patches to keep).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Aaron Bentley
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
 
18
 
import os
19
 
from StringIO import StringIO
20
 
from unittest import makeSuite
21
 
 
22
 
from bzrlib.bzrdir import BzrDir
23
 
try:
24
 
    from bzrlib.plugins.bzrtools.clean_tree import clean_tree, iter_deletables
25
 
except ImportError:
26
 
    from bzrtools.clean_tree import clean_tree, iter_deletables 
27
 
from bzrlib.osutils import has_symlinks
28
 
from bzrlib.tests import TestCaseInTempDir
29
 
 
30
 
 
31
 
class TestCleanTree(TestCaseInTempDir):
32
 
    def test_symlinks(self):
33
 
        if has_symlinks() is False:
34
 
            return
35
 
        os.mkdir('branch')
36
 
        BzrDir.create_standalone_workingtree('branch')
37
 
        os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
38
 
        os.mkdir('no-die-please')
39
 
        assert os.path.exists('branch/die-please')
40
 
        os.mkdir('no-die-please/child')
41
 
 
42
 
        clean_tree('branch')
43
 
        assert os.path.exists('no-die-please')
44
 
        assert os.path.exists('no-die-please/child')
45
 
 
46
 
    def test_iter_deletable(self):
47
 
        """Files are selected for deletion appropriately"""
48
 
        os.mkdir('branch')
49
 
        tree = BzrDir.create_standalone_workingtree('branch')
50
 
        f = file('branch/.bzrignore', 'wb')
51
 
        try:
52
 
            f.write('*~\n*.pyc\n.bzrignore\n')
53
 
        finally:
54
 
            f.close()
55
 
        file('branch/file.BASE', 'wb').write('contents')
56
 
        self.assertEqual(len(list(iter_deletables(tree))), 1)
57
 
        file('branch/file~', 'wb').write('contents')
58
 
        file('branch/file.pyc', 'wb').write('contents')
59
 
        dels = [r for a,r in iter_deletables(tree)]
60
 
        assert 'file~' not in dels
61
 
        assert 'file.pyc' not in dels
62
 
        dels = [r for a,r in iter_deletables(tree, detritus=True)]
63
 
        assert 'file~' in dels
64
 
        assert 'file.pyc' not in dels
65
 
        dels = [r for a,r in iter_deletables(tree, ignored=True)]
66
 
        assert 'file~' in dels
67
 
        assert 'file.BASE' in dels
68
 
        assert 'file.pyc' in dels
69
 
        dels = [r for a,r in iter_deletables(tree, unknown=False)]
70
 
        assert 'file.BASE' not in dels
71
 
 
72
 
def test_suite():
73
 
    return makeSuite(TestCleanTree)