~bzr-pqm/bzr/bzr.dev

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
1 by mbp at sourcefrog
import from baz patch-364
33
34
The basic object is a Branch.  We have a special helper class
35
ScratchBranch that automatically makes a directory and cleans itself
36
up, but is in other respects identical.
37
38
ScratchBranches are initially empty:
39
33 by mbp at sourcefrog
fix up doctest for code rearrangement
40
>>> b = bzrlib.ScratchBranch()
1 by mbp at sourcefrog
import from baz patch-364
41
>>> b.show_status()
42
43
New files in that directory are, it is initially unknown:
44
45
>>> file(b.base + '/hello.c', 'wt').write('int main() {}')
46
>>> b.show_status()
47
?       hello.c
48
49
That's not quite true; some files (like editor backups) are ignored by
50
default:
51
52
>>> file(b.base + '/hello.c~', 'wt').write('int main() {}')
53
>>> b.show_status()
54
?       hello.c
55
>>> list(b.unknowns())
56
['hello.c']
57
58
The ``add`` command marks a file to be added in the next revision:
59
60
>>> b.add('hello.c')
61
>>> b.show_status()
62
A       hello.c
63
64
You can also add files that otherwise would be ignored.  The ignore
65
patterns only apply to files that would be otherwise unknown, so they
66
have no effect once it's added.
67
68
>>> b.add('hello.c~')
69
>>> b.show_status()
70
A       hello.c
71
A       hello.c~
72
73
It is an error to add a file that isn't present in the working copy:
74
75
  >>> b.add('nothere')
76
  Traceback (most recent call last):
77
  ...
78
  BzrError: ('cannot add: not a regular file or directory: nothere', [])
79
80
If we add a file and then change our mind, we can either revert it or
81
remove the file.  If we revert, we are left with the working copy (in
82
either I or ? state).  If we remove, the working copy is gone.  Let's
83
do that to the backup, presumably added accidentally.
84
85
  >>> b.remove('hello.c~')
86
  >>> b.show_status()
87
  A       hello.c
88
89
Now to commit, creating a new revision.  (Fake the date and name for
90
reproducibility.)
91
92
  >>> b.commit('start hello world', timestamp=0, committer='foo@nowhere')
93
  >>> b.show_status()
94
  >>> b.show_status(show_all=True)
95
  .       hello.c
96
  I       hello.c~
97
98
99
We can look back at history
100
101
  >>> r = b.get_revision(b.lookup_revision(1))
102
  >>> r.message
103
  'start hello world'
369 by Martin Pool
- Split out log printing into new show_log function
104
  >>> bzrlib.show_log(b, show_timezone='utc')
1 by mbp at sourcefrog
import from baz patch-364
105
  ----------------------------------------
106
  revno: 1
107
  committer: foo@nowhere
12 by mbp at sourcefrog
new --timezone option for bzr log
108
  timestamp: Thu 1970-01-01 00:00:00 +0000
1 by mbp at sourcefrog
import from baz patch-364
109
  message:
110
    start hello world
111
112
(The other fields will be a bit unpredictable, depending on who ran
113
this test and when.)
114
115
As of 2005-02-21, we can also add subdirectories to the revision!
116
117
  >>> os.mkdir(b.base + "/lib")
118
  >>> b.show_status()
119
  ?       lib/
120
  >>> b.add('lib')
121
  >>> b.show_status()
122
  A       lib/
123
  >>> b.commit('add subdir')
124
  >>> b.show_status()
125
  >>> b.show_status(show_all=True)
126
  .       hello.c
127
  I       hello.c~
128
  .       lib/
129
130
and we can also add files within subdirectories:
131
132
  >>> file(b.base + '/lib/hello', 'w').write('hello!\n')
133
  >>> b.show_status()
134
  ?       lib/hello
135
  
136
  
137
Tests for adding subdirectories, etc.
138
139
    >>> b = bzrlib.branch.ScratchBranch()
67 by mbp at sourcefrog
use abspath() for the function that makes an absolute
140
    >>> os.mkdir(b.abspath('d1'))
141
    >>> os.mkdir(b.abspath('d2'))
142
    >>> os.mkdir(b.abspath('d2/d3'))
1 by mbp at sourcefrog
import from baz patch-364
143
    >>> list(b.working_tree().unknowns())
144
    ['d1', 'd2']
145
146
Create some files, but they're not seen as unknown yet:
147
67 by mbp at sourcefrog
use abspath() for the function that makes an absolute
148
    >>> file(b.abspath('d1/f1'), 'w').close()
149
    >>> file(b.abspath('d2/f2'), 'w').close()
150
    >>> file(b.abspath('d2/f3'), 'w').close()
1 by mbp at sourcefrog
import from baz patch-364
151
    >>> [v[0] for v in b.inventory.directories()]
152
    ['']
153
    >>> list(b.working_tree().unknowns())
154
    ['d1', 'd2']
155
156
Adding a directory, and we see the file underneath:
157
    
158
    >>> b.add('d1')
159
    >>> [v[0] for v in b.inventory.directories()]
160
    ['', 'd1']
161
    >>> list(b.working_tree().unknowns())
152 by mbp at sourcefrog
order in which unknowns are reported has changed
162
    ['d2', 'd1/f1']
1 by mbp at sourcefrog
import from baz patch-364
163
    >>> # d2 comes first because it's in the top directory
164
165
    >>> b.add('d2')
166
    >>> b.commit('add some stuff')
167
    >>> list(b.working_tree().unknowns())
168
    ['d1/f1', 'd2/d3', 'd2/f2', 'd2/f3']
169
56 by mbp at sourcefrog
more add tests
170
    >>> b.add('d1/f1')
171
    >>> list(b.working_tree().unknowns())
172
    ['d2/d3', 'd2/f2', 'd2/f3']
173
100 by mbp at sourcefrog
- add test case for ignore files
174
Tests for ignored files and patterns:
175
176
    >>> b = ScratchBranch(dirs=['src', 'doc'],
177
    ...                   files=['configure.in', 'configure',
178
    ...                          'doc/configure', 'foo.c',
179
    ...                          'foo'])
180
    >>> list(b.unknowns())
181
    ['configure', 'configure.in', 'doc', 'foo', 'foo.c', 'src']
182
    >>> b.add(['doc', 'foo.c', 'src', 'configure.in'])
183
    >>> list(b.unknowns())
152 by mbp at sourcefrog
order in which unknowns are reported has changed
184
    ['configure', 'foo', 'doc/configure']
100 by mbp at sourcefrog
- add test case for ignore files
185
    >>> f = file(b.abspath('.bzrignore'), 'w')
186
    >>> f.write('./configure\n'
187
    ...         './foo\n')
188
    >>> f.close()
189
    >>> b.add('.bzrignore')
190
    >>> list(b.unknowns())
153 by mbp at sourcefrog
update test for new ignore-pattern handling
191
    ['doc/configure']
158 by mbp at sourcefrog
few more test cases
192
    >>> b.commit("commit 1")
193
    >>> list(b.unknowns())
194
    ['doc/configure']
195
    >>> b.add("doc/configure")
196
    >>> 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
197
    >>> del b
198
199
Renames, etc:
200
201
    >>> b = ScratchBranch(files=['foo'], dirs=['subdir'])
202
    >>> b.add(['foo', 'subdir'])
203
    >>> b.commit('add foo')
204
    >>> list(b.unknowns())
205
    []
174 by mbp at sourcefrog
- New 'move' command; now separated out from rename
206
    >>> b.move(['foo'], 'subdir')
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
207
    foo => subdir/foo
208
    >>> b.show_status()
209
    R       foo => subdir/foo
210
    >>> b.commit("move foo to subdir")
211
    >>> isfile(b.abspath('foo'))
212
    False
213
    >>> isfile(b.abspath('subdir/foo'))
214
    True
158 by mbp at sourcefrog
few more test cases
215
1 by mbp at sourcefrog
import from baz patch-364
216
"""