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

  • Committer: Martin Pool
  • Date: 2006-06-06 08:09:09 UTC
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060606080909-f7c9ea6defe2e751
Remove Scratch objects used by doctests

Some old doctests rely on special Scratch object which clean up
temporary directory when they're deleted.  This is a bit undesirable
because deletion is not predictable and the classes aren't used enough
to be worthwhile.

 * Remove ScratchBranch, ScratchDir, ScratchTransport, etc
 * Remove old doctests or convert to unittests
 * Incidental cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1307
1307
        return result
1308
1308
 
1309
1309
 
1310
 
class ScratchDir(BzrDir6):
1311
 
    """Special test class: a bzrdir that cleans up itself..
1312
 
 
1313
 
    >>> d = ScratchDir()
1314
 
    >>> base = d.transport.base
1315
 
    >>> isdir(base)
1316
 
    True
1317
 
    >>> b.transport.__del__()
1318
 
    >>> isdir(base)
1319
 
    False
1320
 
    """
1321
 
 
1322
 
    def __init__(self, files=[], dirs=[], transport=None):
1323
 
        """Make a test branch.
1324
 
 
1325
 
        This creates a temporary directory and runs init-tree in it.
1326
 
 
1327
 
        If any files are listed, they are created in the working copy.
1328
 
        """
1329
 
        if transport is None:
1330
 
            transport = bzrlib.transport.local.ScratchTransport()
1331
 
            # local import for scope restriction
1332
 
            BzrDirFormat6().initialize(transport.base)
1333
 
            super(ScratchDir, self).__init__(transport, BzrDirFormat6())
1334
 
            self.create_repository()
1335
 
            self.create_branch()
1336
 
            self.create_workingtree()
1337
 
        else:
1338
 
            super(ScratchDir, self).__init__(transport, BzrDirFormat6())
1339
 
 
1340
 
        # BzrBranch creates a clone to .bzr and then forgets about the
1341
 
        # original transport. A ScratchTransport() deletes itself and
1342
 
        # everything underneath it when it goes away, so we need to
1343
 
        # grab a local copy to prevent that from happening
1344
 
        self._transport = transport
1345
 
 
1346
 
        for d in dirs:
1347
 
            self._transport.mkdir(d)
1348
 
            
1349
 
        for f in files:
1350
 
            self._transport.put(f, 'content of %s' % f)
1351
 
 
1352
 
    def clone(self):
1353
 
        """
1354
 
        >>> orig = ScratchDir(files=["file1", "file2"])
1355
 
        >>> os.listdir(orig.base)
1356
 
        [u'.bzr', u'file1', u'file2']
1357
 
        >>> clone = orig.clone()
1358
 
        >>> if os.name != 'nt':
1359
 
        ...   os.path.samefile(orig.base, clone.base)
1360
 
        ... else:
1361
 
        ...   orig.base == clone.base
1362
 
        ...
1363
 
        False
1364
 
        >>> os.listdir(clone.base)
1365
 
        [u'.bzr', u'file1', u'file2']
1366
 
        """
1367
 
        from shutil import copytree
1368
 
        from bzrlib.osutils import mkdtemp
1369
 
        base = mkdtemp()
1370
 
        os.rmdir(base)
1371
 
        copytree(self.base, base, symlinks=True)
1372
 
        return ScratchDir(
1373
 
            transport=bzrlib.transport.local.ScratchTransport(base))
1374
 
 
1375
 
 
1376
1310
class Converter(object):
1377
1311
    """Converts a disk format object from one format to another."""
1378
1312