/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_export.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-20 23:43:18 UTC
  • mto: This revision was merged to the branch mainline in revision 2027.
  • Revision ID: john@arbash-meinel.com-20060920234318-05de23e98f7e7876
Move out export tests from test_too_much, refactor
and re-enable doc tests for export.get_root_name()

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
        # Make sure the exported directory contains 'a', but does not contain
112
112
        # '.bzrignore'.
113
113
        self.assertEqual(['a'], files)
 
114
 
 
115
    def example_branch(self):
 
116
        tree = self.make_branch_and_tree('branch')
 
117
        f = open('branch/hello', 'wb')
 
118
        try:
 
119
            f.write('foo')
 
120
        finally:
 
121
            f.close()
 
122
        tree.add('hello')
 
123
        tree.commit('setup')
 
124
 
 
125
        f = open('branch/goodbye', 'wb')
 
126
        try:
 
127
            f.write('baz')
 
128
        finally:
 
129
            f.close()
 
130
        tree.add('goodbye')
 
131
        tree.commit('setup')
 
132
        return tree
 
133
        
 
134
    def test_basic_directory_export(self):
 
135
        self.example_branch()
 
136
        os.chdir('branch')
 
137
 
 
138
        # Directory exports
 
139
        self.run_bzr('export', '../latest')
 
140
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('../latest')))
 
141
        self.check_file_contents('../latest/goodbye', 'baz')
 
142
        self.run_bzr('export', '../first', '-r', '1')
 
143
        self.assertEqual(['hello'], sorted(os.listdir('../first')))
 
144
        self.check_file_contents('../first/hello', 'foo')
 
145
 
 
146
        # Even with .gz and .bz2 it is still a directory
 
147
        self.run_bzr('export', '../first.gz', '-r', '1')
 
148
        self.check_file_contents('../first.gz/hello', 'foo')
 
149
        self.run_bzr('export', '../first.bz2', '-r', '1')
 
150
        self.check_file_contents('../first.bz2/hello', 'foo')
 
151
 
 
152
    def test_basic_tarfile_export(self):
 
153
        self.example_branch()
 
154
        os.chdir('branch')
 
155
 
 
156
        self.run_bzr('export', '../first.tar', '-r', '1')
 
157
        self.failUnless(os.path.isfile('../first.tar'))
 
158
        tf = tarfile.open('../first.tar')
 
159
        try:
 
160
            self.assertEqual(['first/hello'], sorted(tf.getnames()))
 
161
            self.assertEqual('foo', tf.extractfile('first/hello').read())
 
162
        finally:
 
163
            tf.close()
 
164
 
 
165
        self.run_bzr('export', '../first.tar.gz', '-r', '1')
 
166
        self.failUnless(os.path.isfile('../first.tar.gz'))
 
167
        self.run_bzr('export', '../first.tbz2', '-r', '1')
 
168
        self.failUnless(os.path.isfile('../first.tbz2'))
 
169
        self.run_bzr('export', '../first.tar.bz2', '-r', '1')
 
170
        self.failUnless(os.path.isfile('../first.tar.bz2'))
 
171
        self.run_bzr('export', '../first.tar.tbz2', '-r', '1')
 
172
        self.failUnless(os.path.isfile('../first.tar.tbz2'))
 
173
 
 
174
        tf = tarfile.open('../first.tar.tbz2', 'r:bz2')
 
175
        try:
 
176
            self.assertEqual(['first.tar/hello'], sorted(tf.getnames()))
 
177
            self.assertEqual('foo', tf.extractfile('first.tar/hello').read())
 
178
        finally:
 
179
            tf.close()
 
180
        self.run_bzr('export', '../first2.tar', '-r', '1', '--root', 'pizza')
 
181
        tf = tarfile.open('../first2.tar')
 
182
        try:
 
183
            self.assertEqual(['pizza/hello'], sorted(tf.getnames()))
 
184
            self.assertEqual('foo', tf.extractfile('pizza/hello').read())
 
185
        finally:
 
186
            tf.close()
 
187
 
 
188
    def test_basic_zipfile_export(self):
 
189
        self.example_branch()
 
190
        os.chdir('branch')
 
191
 
 
192
        self.run_bzr('export', '../first.zip', '-r', '1')
 
193
        self.failUnlessExists('../first.zip')
 
194
        zf = zipfile.ZipFile('../first.zip')
 
195
        try:
 
196
            self.assertEqual(['first/hello'], sorted(zf.namelist()))
 
197
            self.assertEqual('foo', zf.read('first/hello'))
 
198
        finally:
 
199
            zf.close()
 
200
 
 
201
        self.run_bzr('export', '../first2.zip', '-r', '1', '--root', 'pizza')
 
202
        zf = zipfile.ZipFile('../first2.zip')
 
203
        try:
 
204
            self.assertEqual(['pizza/hello'], sorted(zf.namelist()))
 
205
            self.assertEqual('foo', zf.read('pizza/hello'))
 
206
        finally:
 
207
            zf.close()
 
208
        
 
209
        self.run_bzr('export', '../first-zip', '--format=zip', '-r', '1')
 
210
        zf = zipfile.ZipFile('../first-zip')
 
211
        try:
 
212
            self.assertEqual(['first-zip/hello'], sorted(zf.namelist()))
 
213
            self.assertEqual('foo', zf.read('first-zip/hello'))
 
214
        finally:
 
215
            zf.close()
 
216