bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
1  | 
#! /usr/bin/env python
 | 
2  | 
# -*- coding: UTF-8 -*-
 | 
|
3  | 
||
4  | 
# This program is free software; you can redistribute it and/or modify
 | 
|
5  | 
# it under the terms of the GNU General Public License as published by
 | 
|
6  | 
# the Free Software Foundation; either version 2 of the License, or
 | 
|
7  | 
# (at your option) any later version.
 | 
|
8  | 
||
9  | 
# This program is distributed in the hope that it will be useful,
 | 
|
10  | 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|
11  | 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|
12  | 
# GNU General Public License for more details.
 | 
|
13  | 
||
14  | 
# You should have received a copy of the GNU General Public License
 | 
|
15  | 
# along with this program; if not, write to the Free Software
 | 
|
16  | 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|
17  | 
||
18  | 
||
19  | 
||
20  | 
# XXX: We might prefer these to be in a text file rather than Python
 | 
|
21  | 
# source, but that only works in doctest from Python 2.4 and later,
 | 
|
22  | 
# which is not present in Warty.
 | 
|
23  | 
||
24  | 
r"""  | 
|
25  | 
Bazaar-NG test cases
 | 
|
26  | 
********************
 | 
|
27  | 
||
28  | 
These are run by ``bzr.doctest``.
 | 
|
29  | 
||
| 
52
by mbp at sourcefrog
 fixup doctest for new module structure  | 
30  | 
>>> import bzrlib, os
 | 
| 
100
by mbp at sourcefrog
 - add test case for ignore files  | 
31  | 
>>> from bzrlib import ScratchBranch
 | 
| 
160
by mbp at sourcefrog
 - basic support for moving files to different directories - have not done support for renaming them yet, but should be straightforward - some tests, but many cases are not handled yet i think  | 
32  | 
>>> from bzrlib.osutils import isdir, isfile
 | 
| 
33
by mbp at sourcefrog
 fix up doctest for code rearrangement  | 
33  | 
>>> bzrlib.commands.cmd_rocks()
 | 
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
34  | 
it sure does!
 | 
35  | 
||
36  | 
Hey, nice place to begin.
 | 
|
37  | 
||
38  | 
The basic object is a Branch.  We have a special helper class
 | 
|
39  | 
ScratchBranch that automatically makes a directory and cleans itself
 | 
|
40  | 
up, but is in other respects identical.
 | 
|
41  | 
||
42  | 
ScratchBranches are initially empty:
 | 
|
43  | 
||
| 
33
by mbp at sourcefrog
 fix up doctest for code rearrangement  | 
44  | 
>>> b = bzrlib.ScratchBranch()
 | 
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
45  | 
>>> b.show_status()
 | 
46  | 
||
47  | 
New files in that directory are, it is initially unknown:
 | 
|
48  | 
||
49  | 
>>> file(b.base + '/hello.c', 'wt').write('int main() {}')
 | 
|
50  | 
>>> b.show_status()
 | 
|
51  | 
?       hello.c
 | 
|
52  | 
||
53  | 
That's not quite true; some files (like editor backups) are ignored by
 | 
|
54  | 
default:
 | 
|
55  | 
||
56  | 
>>> file(b.base + '/hello.c~', 'wt').write('int main() {}')
 | 
|
57  | 
>>> b.show_status()
 | 
|
58  | 
?       hello.c
 | 
|
59  | 
>>> list(b.unknowns())
 | 
|
60  | 
['hello.c']
 | 
|
61  | 
||
62  | 
The ``add`` command marks a file to be added in the next revision:
 | 
|
63  | 
||
64  | 
>>> b.add('hello.c')
 | 
|
65  | 
>>> b.show_status()
 | 
|
66  | 
A       hello.c
 | 
|
67  | 
||
68  | 
You can also add files that otherwise would be ignored.  The ignore
 | 
|
69  | 
patterns only apply to files that would be otherwise unknown, so they
 | 
|
70  | 
have no effect once it's added.
 | 
|
71  | 
||
72  | 
>>> b.add('hello.c~')
 | 
|
73  | 
>>> b.show_status()
 | 
|
74  | 
A       hello.c
 | 
|
75  | 
A       hello.c~
 | 
|
76  | 
||
77  | 
It is an error to add a file that isn't present in the working copy:
 | 
|
78  | 
||
79  | 
  >>> b.add('nothere')
 | 
|
80  | 
  Traceback (most recent call last):
 | 
|
81  | 
  ...
 | 
|
82  | 
  BzrError: ('cannot add: not a regular file or directory: nothere', [])
 | 
|
83  | 
||
84  | 
If we add a file and then change our mind, we can either revert it or
 | 
|
85  | 
remove the file.  If we revert, we are left with the working copy (in
 | 
|
86  | 
either I or ? state).  If we remove, the working copy is gone.  Let's
 | 
|
87  | 
do that to the backup, presumably added accidentally.
 | 
|
88  | 
||
89  | 
  >>> b.remove('hello.c~')
 | 
|
90  | 
  >>> b.show_status()
 | 
|
91  | 
  A       hello.c
 | 
|
92  | 
||
93  | 
Now to commit, creating a new revision.  (Fake the date and name for
 | 
|
94  | 
reproducibility.)
 | 
|
95  | 
||
96  | 
  >>> b.commit('start hello world', timestamp=0, committer='foo@nowhere')
 | 
|
97  | 
  >>> b.show_status()
 | 
|
98  | 
  >>> b.show_status(show_all=True)
 | 
|
99  | 
  .       hello.c
 | 
|
100  | 
  I       hello.c~
 | 
|
101  | 
||
102  | 
||
103  | 
We can look back at history
 | 
|
104  | 
||
105  | 
  >>> r = b.get_revision(b.lookup_revision(1))
 | 
|
106  | 
  >>> r.message
 | 
|
107  | 
  'start hello world'
 | 
|
| 
12
by mbp at sourcefrog
 new --timezone option for bzr log  | 
108  | 
  >>> b.write_log(show_timezone='utc')
 | 
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
109  | 
  ----------------------------------------
 | 
110  | 
  revno: 1
 | 
|
111  | 
  committer: foo@nowhere
 | 
|
| 
12
by mbp at sourcefrog
 new --timezone option for bzr log  | 
112  | 
  timestamp: Thu 1970-01-01 00:00:00 +0000
 | 
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
113  | 
  message:
 | 
114  | 
    start hello world
 | 
|
115  | 
||
116  | 
(The other fields will be a bit unpredictable, depending on who ran
 | 
|
117  | 
this test and when.)
 | 
|
118  | 
||
119  | 
As of 2005-02-21, we can also add subdirectories to the revision!
 | 
|
120  | 
||
121  | 
  >>> os.mkdir(b.base + "/lib")
 | 
|
122  | 
  >>> b.show_status()
 | 
|
123  | 
  ?       lib/
 | 
|
124  | 
  >>> b.add('lib')
 | 
|
125  | 
  >>> b.show_status()
 | 
|
126  | 
  A       lib/
 | 
|
127  | 
  >>> b.commit('add subdir')
 | 
|
128  | 
  >>> b.show_status()
 | 
|
129  | 
  >>> b.show_status(show_all=True)
 | 
|
130  | 
  .       hello.c
 | 
|
131  | 
  I       hello.c~
 | 
|
132  | 
  .       lib/
 | 
|
133  | 
||
134  | 
and we can also add files within subdirectories:
 | 
|
135  | 
||
136  | 
  >>> file(b.base + '/lib/hello', 'w').write('hello!\n')
 | 
|
137  | 
  >>> b.show_status()
 | 
|
138  | 
  ?       lib/hello
 | 
|
139  | 
  
 | 
|
140  | 
  
 | 
|
141  | 
Tests for adding subdirectories, etc.
 | 
|
142  | 
||
143  | 
    >>> b = bzrlib.branch.ScratchBranch()
 | 
|
| 
67
by mbp at sourcefrog
 use abspath() for the function that makes an absolute  | 
144  | 
    >>> os.mkdir(b.abspath('d1'))
 | 
145  | 
    >>> os.mkdir(b.abspath('d2'))
 | 
|
146  | 
    >>> os.mkdir(b.abspath('d2/d3'))
 | 
|
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
147  | 
    >>> list(b.working_tree().unknowns())
 | 
148  | 
    ['d1', 'd2']
 | 
|
149  | 
||
150  | 
Create some files, but they're not seen as unknown yet:
 | 
|
151  | 
||
| 
67
by mbp at sourcefrog
 use abspath() for the function that makes an absolute  | 
152  | 
    >>> file(b.abspath('d1/f1'), 'w').close()
 | 
153  | 
    >>> file(b.abspath('d2/f2'), 'w').close()
 | 
|
154  | 
    >>> file(b.abspath('d2/f3'), 'w').close()
 | 
|
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
155  | 
    >>> [v[0] for v in b.inventory.directories()]
 | 
156  | 
    ['']
 | 
|
157  | 
    >>> list(b.working_tree().unknowns())
 | 
|
158  | 
    ['d1', 'd2']
 | 
|
159  | 
||
160  | 
Adding a directory, and we see the file underneath:
 | 
|
161  | 
    
 | 
|
162  | 
    >>> b.add('d1')
 | 
|
163  | 
    >>> [v[0] for v in b.inventory.directories()]
 | 
|
164  | 
    ['', 'd1']
 | 
|
165  | 
    >>> list(b.working_tree().unknowns())
 | 
|
| 
152
by mbp at sourcefrog
 order in which unknowns are reported has changed  | 
166  | 
    ['d2', 'd1/f1']
 | 
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
167  | 
    >>> # d2 comes first because it's in the top directory
 | 
168  | 
||
169  | 
    >>> b.add('d2')
 | 
|
170  | 
    >>> b.commit('add some stuff')
 | 
|
171  | 
    >>> list(b.working_tree().unknowns())
 | 
|
172  | 
    ['d1/f1', 'd2/d3', 'd2/f2', 'd2/f3']
 | 
|
173  | 
||
| 
56
by mbp at sourcefrog
 more add tests  | 
174  | 
    >>> b.add('d1/f1')
 | 
175  | 
    >>> list(b.working_tree().unknowns())
 | 
|
176  | 
    ['d2/d3', 'd2/f2', 'd2/f3']
 | 
|
177  | 
||
| 
100
by mbp at sourcefrog
 - add test case for ignore files  | 
178  | 
Tests for ignored files and patterns:
 | 
179  | 
||
180  | 
    >>> b = ScratchBranch(dirs=['src', 'doc'],
 | 
|
181  | 
    ...                   files=['configure.in', 'configure',
 | 
|
182  | 
    ...                          'doc/configure', 'foo.c',
 | 
|
183  | 
    ...                          'foo'])
 | 
|
184  | 
    >>> list(b.unknowns())
 | 
|
185  | 
    ['configure', 'configure.in', 'doc', 'foo', 'foo.c', 'src']
 | 
|
186  | 
    >>> b.add(['doc', 'foo.c', 'src', 'configure.in'])
 | 
|
187  | 
    >>> list(b.unknowns())
 | 
|
| 
152
by mbp at sourcefrog
 order in which unknowns are reported has changed  | 
188  | 
    ['configure', 'foo', 'doc/configure']
 | 
| 
100
by mbp at sourcefrog
 - add test case for ignore files  | 
189  | 
    >>> f = file(b.abspath('.bzrignore'), 'w')
 | 
190  | 
    >>> f.write('./configure\n'
 | 
|
191  | 
    ...         './foo\n')
 | 
|
192  | 
    >>> f.close()
 | 
|
193  | 
    >>> b.add('.bzrignore')
 | 
|
194  | 
    >>> list(b.unknowns())
 | 
|
| 
153
by mbp at sourcefrog
 update test for new ignore-pattern handling  | 
195  | 
    ['doc/configure']
 | 
| 
158
by mbp at sourcefrog
 few more test cases  | 
196  | 
    >>> b.commit("commit 1")
 | 
197  | 
    >>> list(b.unknowns())
 | 
|
198  | 
    ['doc/configure']
 | 
|
199  | 
    >>> b.add("doc/configure")
 | 
|
200  | 
    >>> b.commit("commit more")
 | 
|
| 
160
by mbp at sourcefrog
 - basic support for moving files to different directories - have not done support for renaming them yet, but should be straightforward - some tests, but many cases are not handled yet i think  | 
201  | 
    >>> del b
 | 
202  | 
||
203  | 
Renames, etc:
 | 
|
204  | 
||
205  | 
    >>> b = ScratchBranch(files=['foo'], dirs=['subdir'])
 | 
|
206  | 
    >>> b.add(['foo', 'subdir'])
 | 
|
207  | 
    >>> b.commit('add foo')
 | 
|
208  | 
    >>> list(b.unknowns())
 | 
|
209  | 
    []
 | 
|
210  | 
    >>> b.rename(['foo'], 'subdir')
 | 
|
211  | 
    foo => subdir/foo
 | 
|
212  | 
    >>> b.show_status()
 | 
|
213  | 
    R       foo => subdir/foo
 | 
|
| 
164
by mbp at sourcefrog
 new 'renames' command  | 
214  | 
    >>> bzrlib.commands.cmd_renames(b.base)
 | 
215  | 
    foo => subdir/foo
 | 
|
| 
160
by mbp at sourcefrog
 - basic support for moving files to different directories - have not done support for renaming them yet, but should be straightforward - some tests, but many cases are not handled yet i think  | 
216  | 
    >>> b.commit("move foo to subdir")
 | 
217  | 
    >>> isfile(b.abspath('foo'))
 | 
|
218  | 
    False
 | 
|
219  | 
    >>> isfile(b.abspath('subdir/foo'))
 | 
|
220  | 
    True
 | 
|
| 
158
by mbp at sourcefrog
 few more test cases  | 
221  | 
|
| 
1
by mbp at sourcefrog
 import from baz patch-364  | 
222  | 
"""
 |