/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/__init__.py

  • Committer: Jan Balster
  • Date: 2006-08-15 12:39:42 UTC
  • mfrom: (1923 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1928.
  • Revision ID: jan@merlinux.de-20060815123942-22c388c6e9a8ac91
merge bzr.dev 1923

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
110
110
    import bzrlib.tests.bzrdir_implementations
111
111
    import bzrlib.tests.interrepository_implementations
112
112
    import bzrlib.tests.interversionedfile_implementations
 
113
    import bzrlib.tests.intertree_implementations
113
114
    import bzrlib.tests.repository_implementations
114
115
    import bzrlib.tests.revisionstore_implementations
 
116
    import bzrlib.tests.tree_implementations
115
117
    import bzrlib.tests.workingtree_implementations
116
118
    return [
117
119
            bzrlib.doc,
120
122
            bzrlib.tests.bzrdir_implementations,
121
123
            bzrlib.tests.interrepository_implementations,
122
124
            bzrlib.tests.interversionedfile_implementations,
 
125
            bzrlib.tests.intertree_implementations,
123
126
            bzrlib.tests.repository_implementations,
124
127
            bzrlib.tests.revisionstore_implementations,
 
128
            bzrlib.tests.tree_implementations,
125
129
            bzrlib.tests.workingtree_implementations,
126
130
            ]
127
131
 
227
231
            self.stream.write('E')
228
232
        elif self.dots:
229
233
            self.pb.update(self._ellipsise_unimportant_words('ERROR', 13), self.testsRun, None)
 
234
            self.pb.note(self._ellipsise_unimportant_words(
 
235
                            test.id() + ': ERROR',
 
236
                            osutils.terminal_width()))
230
237
        self.stream.flush()
231
238
        if self.stop_early:
232
239
            self.stop()
240
247
            self.stream.write('F')
241
248
        elif self.dots:
242
249
            self.pb.update(self._ellipsise_unimportant_words('FAIL', 13), self.testsRun, None)
 
250
            self.pb.note(self._ellipsise_unimportant_words(
 
251
                            test.id() + ': FAIL',
 
252
                            osutils.terminal_width()))
243
253
        self.stream.flush()
244
254
        if self.stop_early:
245
255
            self.stop()
275
285
        self.stream.flush()
276
286
        # seems best to treat this as success from point-of-view of unittest
277
287
        # -- it actually does nothing so it barely matters :)
278
 
        unittest.TestResult.addSuccess(self, test)
 
288
        try:
 
289
            test.tearDown()
 
290
        except KeyboardInterrupt:
 
291
            raise
 
292
        except:
 
293
            self.addError(test, test.__exc_info())
 
294
        else:
 
295
            unittest.TestResult.addSuccess(self, test)
279
296
 
280
297
    def printErrorList(self, flavour, errors):
281
298
        for test, err in errors:
568
585
 
569
586
        Read contents into memory, close, and delete.
570
587
        """
 
588
        if self._log_file is None:
 
589
            return
571
590
        bzrlib.trace.disable_test_log(self._log_nonce)
572
591
        self._log_file.seek(0)
573
592
        self._log_contents = self._log_file.read()
590
609
        new_env = {
591
610
            'HOME': os.getcwd(),
592
611
            'APPDATA': os.getcwd(),
593
 
            'BZREMAIL': None,
 
612
            'BZR_EMAIL': None,
 
613
            'BZREMAIL': None, # may still be present in the environment
594
614
            'EMAIL': None,
595
615
        }
596
616
        self.__old_env = {}
755
775
            encoding = bzrlib.user_encoding
756
776
        return self.run_bzr(*args, **kwargs)[0].decode(encoding)
757
777
 
 
778
    def run_bzr_error(self, error_regexes, *args, **kwargs):
 
779
        """Run bzr, and check that stderr contains the supplied regexes
 
780
        
 
781
        :param error_regexes: Sequence of regular expressions which 
 
782
            must each be found in the error output. The relative ordering
 
783
            is not enforced.
 
784
        :param args: command-line arguments for bzr
 
785
        :param kwargs: Keyword arguments which are interpreted by run_bzr
 
786
            This function changes the default value of retcode to be 3,
 
787
            since in most cases this is run when you expect bzr to fail.
 
788
        :return: (out, err) The actual output of running the command (in case you
 
789
                 want to do more inspection)
 
790
 
 
791
        Examples of use:
 
792
            # Make sure that commit is failing because there is nothing to do
 
793
            self.run_bzr_error(['no changes to commit'],
 
794
                               'commit', '-m', 'my commit comment')
 
795
            # Make sure --strict is handling an unknown file, rather than
 
796
            # giving us the 'nothing to do' error
 
797
            self.build_tree(['unknown'])
 
798
            self.run_bzr_error(['Commit refused because there are unknown files'],
 
799
                               'commit', '--strict', '-m', 'my commit comment')
 
800
        """
 
801
        kwargs.setdefault('retcode', 3)
 
802
        out, err = self.run_bzr(*args, **kwargs)
 
803
        for regex in error_regexes:
 
804
            self.assertContainsRe(err, regex)
 
805
        return out, err
 
806
 
758
807
    def run_bzr_subprocess(self, *args, **kwargs):
759
808
        """Run bzr in a subprocess for testing.
760
809
 
932
981
        shape is a sequence of file specifications.  If the final
933
982
        character is '/', a directory is created.
934
983
 
 
984
        This assumes that all the elements in the tree being built are new.
 
985
 
935
986
        This doesn't add anything to a branch.
936
987
        :param line_endings: Either 'binary' or 'native'
937
988
                             in binary mode, exact contents are written
942
993
                          VFS's. If the transport is readonly or None,
943
994
                          "." is opened automatically.
944
995
        """
945
 
        # XXX: It's OK to just create them using forward slashes on windows?
 
996
        # It's OK to just create them using forward slashes on windows.
946
997
        if transport is None or transport.is_readonly():
947
998
            transport = get_transport(".")
948
999
        for name in shape:
957
1008
                else:
958
1009
                    raise errors.BzrError('Invalid line ending request %r' % (line_endings,))
959
1010
                content = "contents of %s%s" % (name.encode('utf-8'), end)
960
 
                transport.put(urlutils.escape(name), StringIO(content))
 
1011
                # Technically 'put()' is the right command. However, put
 
1012
                # uses an AtomicFile, which requires an extra rename into place
 
1013
                # As long as the files didn't exist in the past, append() will
 
1014
                # do the same thing as put()
 
1015
                # On jam's machine, make_kernel_like_tree is:
 
1016
                #   put:    4.5-7.5s (averaging 6s)
 
1017
                #   append: 2.9-4.5s
 
1018
                transport.append(urlutils.escape(name), StringIO(content))
961
1019
 
962
1020
    def build_tree_contents(self, shape):
963
1021
        build_tree_contents(shape)
1196
1254
             lsprof_timed=None,
1197
1255
             bench_history=None):
1198
1256
    """Run the whole test suite under the enhanced runner"""
 
1257
    # XXX: Very ugly way to do this...
 
1258
    # Disable warning about old formats because we don't want it to disturb
 
1259
    # any blackbox tests.
 
1260
    from bzrlib import repository
 
1261
    repository._deprecation_warning_done = True
 
1262
 
1199
1263
    global default_transport
1200
1264
    if transport is None:
1201
1265
        transport = default_transport
1224
1288
    testmod_names = [
1225
1289
                   'bzrlib.tests.test_ancestry',
1226
1290
                   'bzrlib.tests.test_api',
 
1291
                   'bzrlib.tests.test_atomicfile',
1227
1292
                   'bzrlib.tests.test_bad_files',
1228
1293
                   'bzrlib.tests.test_branch',
1229
1294
                   'bzrlib.tests.test_bundle',
1236
1301
                   'bzrlib.tests.test_decorators',
1237
1302
                   'bzrlib.tests.test_diff',
1238
1303
                   'bzrlib.tests.test_doc_generate',
1239
 
                   'bzrlib.tests.test_emptytree',
1240
1304
                   'bzrlib.tests.test_errors',
1241
1305
                   'bzrlib.tests.test_escaped_store',
1242
1306
                   'bzrlib.tests.test_fetch',
1244
1308
                   'bzrlib.tests.test_graph',
1245
1309
                   'bzrlib.tests.test_hashcache',
1246
1310
                   'bzrlib.tests.test_http',
 
1311
                   'bzrlib.tests.test_http_response',
1247
1312
                   'bzrlib.tests.test_identitymap',
 
1313
                   'bzrlib.tests.test_ignores',
1248
1314
                   'bzrlib.tests.test_inv',
1249
1315
                   'bzrlib.tests.test_knit',
1250
1316
                   'bzrlib.tests.test_lockdir',
1267
1333
                   'bzrlib.tests.test_repository',
1268
1334
                   'bzrlib.tests.test_revision',
1269
1335
                   'bzrlib.tests.test_revisionnamespaces',
1270
 
                   'bzrlib.tests.test_revprops',
1271
1336
                   'bzrlib.tests.test_revisiontree',
1272
1337
                   'bzrlib.tests.test_rio',
1273
1338
                   'bzrlib.tests.test_sampler',
1286
1351
                   'bzrlib.tests.test_transactions',
1287
1352
                   'bzrlib.tests.test_transform',
1288
1353
                   'bzrlib.tests.test_transport',
 
1354
                   'bzrlib.tests.test_tree',
1289
1355
                   'bzrlib.tests.test_tsort',
1290
1356
                   'bzrlib.tests.test_tuned_gzip',
1291
1357
                   'bzrlib.tests.test_ui',
1303
1369
        ]
1304
1370
    suite = TestUtil.TestSuite()
1305
1371
    loader = TestUtil.TestLoader()
 
1372
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1306
1373
    from bzrlib.transport import TransportTestProviderAdapter
1307
1374
    adapter = TransportTestProviderAdapter()
1308
1375
    adapt_modules(test_transport_implementations, adapter, loader, suite)
1309
 
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1310
1376
    for package in packages_to_test():
1311
1377
        suite.addTest(package.test_suite())
1312
1378
    for m in MODULES_TO_TEST: