Ejemplo n.º 1
0
 def test_diff_outside_tree(self):
     tree = self.make_branch_and_tree('branch1')
     tree.commit('nothing')
     tree.commit('nothing')
     # A directory we can run commands from which we hope is not contained
     # in a bzr tree (though if there is one at or above $TEMPDIR, this is
     # false and may cause test failures).
     # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
     tmp_dir = osutils.realpath(osutils.mkdtemp())
     self.addCleanup(osutils.rmtree, tmp_dir)
     # We expect a read-to-root attempt to occur.
     self.permit_url('file:///')
     expected_error = u'bzr: ERROR: Not a branch: "%s/branch2/".\n' % tmp_dir
     # -r X..Y
     out, err = self.run_bzr('diff -r revno:2:branch2..revno:1', retcode=3,
         working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(expected_error, err)
     # -r X
     out, err = self.run_bzr('diff -r revno:2:branch2', retcode=3,
         working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(expected_error, err)
     # -r X..
     out, err = self.run_bzr('diff -r revno:2:branch2..', retcode=3,
         working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(expected_error, err)
     # no -r at all.
     out, err = self.run_bzr('diff', retcode=3, working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % tmp_dir, err)
Ejemplo n.º 2
0
 def test_diff_outside_tree(self):
     tree = self.make_branch_and_tree('branch1')
     tree.commit('nothing')
     tree.commit('nothing')
     # A directory we can run commands from which we hope is not contained
     # in a bzr tree (though if there is one at or above $TEMPDIR, this is
     # false and may cause test failures).
     # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
     tmp_dir = osutils.realpath(osutils.mkdtemp())
     self.addCleanup(osutils.rmtree, tmp_dir)
     # We expect a read-to-root attempt to occur.
     self.permit_url('file:///')
     expected_error = u'bzr: ERROR: Not a branch: "%s/branch2/".\n' % tmp_dir
     # -r X..Y
     out, err = self.run_bzr('diff -r revno:2:branch2..revno:1',
                             retcode=3,
                             working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(expected_error, err)
     # -r X
     out, err = self.run_bzr('diff -r revno:2:branch2',
                             retcode=3,
                             working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(expected_error, err)
     # -r X..
     out, err = self.run_bzr('diff -r revno:2:branch2..',
                             retcode=3,
                             working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(expected_error, err)
     # no -r at all.
     out, err = self.run_bzr('diff', retcode=3, working_dir=tmp_dir)
     self.assertEqual('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % tmp_dir, err)
Ejemplo n.º 3
0
 def __init__(self, prefix="", suffix="", cleanup=True, readonly=True):
     """
 Create a temporary directory.
 """
     self.path = osutils.mkdtemp(prefix=prefix, suffix=suffix + "_tmp")
     self.readonly = readonly
     self.cleaned = not cleanup
     return
Ejemplo n.º 4
0
 def __init__(self, prefix='', suffix='', cleanup=True, readonly=True):
     """
 Create a temporary directory.
 """
     self.path = osutils.mkdtemp(prefix=prefix, suffix=suffix + '_tmp')
     self.readonly = readonly
     self.cleaned = (not cleanup)
     return
Ejemplo n.º 5
0
 def test_cwd_log(self):
     # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
     tmp_dir = osutils.realpath(osutils.mkdtemp())
     # We expect a read-to-root attempt to occur.
     self.permit_url('file:///')
     self.addCleanup(osutils.rmtree, tmp_dir)
     out, err = self.run_bzr('log', retcode=3, working_dir=tmp_dir)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (tmp_dir, ),
                      err)
Ejemplo n.º 6
0
    def _probe(self):
        if CaseInsCasePresFilenameFeature.available():
            return False

        from bzrlib import tests

        if tests.TestCaseWithMemoryTransport.TEST_ROOT is None:
            root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
            tests.TestCaseWithMemoryTransport.TEST_ROOT = root
        else:
            root = tests.TestCaseWithMemoryTransport.TEST_ROOT
        tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
            dir=root)
        name_a = osutils.pathjoin(tdir, 'a')
        name_A = osutils.pathjoin(tdir, 'A')
        os.mkdir(name_a)
        result = osutils.isdir(name_A)
        tests._rmtree_temp_dir(tdir)
        return result
Ejemplo n.º 7
0
 def test_cwd_log(self):
     # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
     tmp_dir = osutils.realpath(osutils.mkdtemp())
     # We expect a read-to-root attempt to occur.
     self.permit_url('file:///')
     self.addCleanup(osutils.rmtree, tmp_dir)
     out, err = self.run_bzr('log', retcode=3, working_dir=tmp_dir)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n'
                      % (tmp_dir,),
                      err)
Ejemplo n.º 8
0
 def __init__(self, dir=None):
     self.dir = osutils.mkdtemp(prefix="merge-test", dir=dir)
     self.tree_root = generate_ids.gen_root_id()
     def wt(name):
        path = pathjoin(self.dir, name)
        os.mkdir(path)
        wt = bzrlib.bzrdir.BzrDir.create_standalone_workingtree(path)
        # the tests perform pulls, so need a branch that is writeable.
        wt.lock_write()
        wt.set_root_id(self.tree_root)
        wt.flush()
        tt = TreeTransform(wt)
        return wt, tt
     self.base, self.base_tt = wt('base')
     self.this, self.this_tt = wt('this')
     self.other, self.other_tt = wt('other')
Ejemplo n.º 9
0
    def __init__(self, dir=None):
        self.dir = osutils.mkdtemp(prefix="merge-test", dir=dir)
        self.tree_root = generate_ids.gen_root_id()

        def wt(name):
            path = pathjoin(self.dir, name)
            os.mkdir(path)
            wt = controldir.ControlDir.create_standalone_workingtree(path)
            # the tests perform pulls, so need a branch that is writeable.
            wt.lock_write()
            wt.set_root_id(self.tree_root)
            wt.flush()
            tt = TreeTransform(wt)
            return wt, tt

        self.base, self.base_tt = wt('base')
        self.this, self.this_tt = wt('this')
        self.other, self.other_tt = wt('other')
Ejemplo n.º 10
0
    def compose(self, prompt, to, subject, attachment, mime_subtype,
                extension, basename=None, body=None):
        """See MailClient.compose.

        Writes the attachment to a temporary file, invokes _compose.
        """
        if basename is None:
            basename = 'attachment'
        pathname = osutils.mkdtemp(prefix='bzr-mail-')
        attach_path = osutils.pathjoin(pathname, basename + extension)
        outfile = open(attach_path, 'wb')
        try:
            outfile.write(attachment)
        finally:
            outfile.close()
        if body is not None:
            kwargs = {'body': body}
        else:
            kwargs = {}
        self._compose(prompt, to, subject, attach_path, mime_subtype,
                      extension, **kwargs)
Ejemplo n.º 11
0
    def test_relpath(self):
        """test for branch path lookups

        bzrlib.osutils._relpath do a simple but subtle
        job: given a path (either relative to cwd or absolute), work out
        if it is inside a branch and return the path relative to the base.
        """
        dtmp = osutils.mkdtemp()
        self.addCleanup(osutils.rmtree, dtmp)
        # On Mac OSX, /tmp actually expands to /private/tmp
        dtmp = realpath(dtmp)

        def rp(p):
            return relpath(dtmp, p)

        # check paths inside dtmp while standing outside it
        self.assertEqual('foo', rp(pathjoin(dtmp, 'foo')))

        # root = nothing
        self.assertEqual('', rp(dtmp))
        self.assertRaises(errors.PathNotChild, rp, '/etc')

        # now some near-miss operations -- note that
        # os.path.commonprefix gets these wrong!
        self.assertRaises(errors.PathNotChild, rp, dtmp.rstrip('\\/') + '2')
        self.assertRaises(errors.PathNotChild, rp,
                          dtmp.rstrip('\\/') + '2/foo')

        # now operations based on relpath of files in current
        # directory, or nearby

        os.chdir(dtmp)
        self.assertEqual('foo/bar/quux', rp('foo/bar/quux'))
        self.assertEqual('foo', rp('foo'))
        self.assertEqual('foo', rp('./foo'))
        self.assertEqual('foo', rp(abspath('foo')))
        self.assertRaises(errors.PathNotChild, rp, '../foo')
Ejemplo n.º 12
0
    def test_relpath(self):
        """test for branch path lookups

        bzrlib.osutils._relpath do a simple but subtle
        job: given a path (either relative to cwd or absolute), work out
        if it is inside a branch and return the path relative to the base.
        """
        dtmp = osutils.mkdtemp()
        self.addCleanup(osutils.rmtree, dtmp)
        # On Mac OSX, /tmp actually expands to /private/tmp
        dtmp = realpath(dtmp)

        def rp(p):
            return relpath(dtmp, p)

        # check paths inside dtmp while standing outside it
        self.assertEqual('foo', rp(pathjoin(dtmp, 'foo')))

        # root = nothing
        self.assertEqual('', rp(dtmp))
        self.assertRaises(errors.PathNotChild, rp, '/etc')

        # now some near-miss operations -- note that
        # os.path.commonprefix gets these wrong!
        self.assertRaises(errors.PathNotChild, rp, dtmp.rstrip('\\/') + '2')
        self.assertRaises(errors.PathNotChild, rp, dtmp.rstrip('\\/') + '2/foo')

        # now operations based on relpath of files in current
        # directory, or nearby

        os.chdir(dtmp)
        self.assertEqual('foo/bar/quux', rp('foo/bar/quux'))
        self.assertEqual('foo', rp('foo'))
        self.assertEqual('foo', rp('./foo'))
        self.assertEqual('foo', rp(abspath('foo')))
        self.assertRaises(errors.PathNotChild, rp, '../foo')
Ejemplo n.º 13
0
 def _copy_to_tempdir(self, from_repo):
     tmp_dirname = osutils.mkdtemp(prefix='tmpbzrclone')
     tmp_bzrdir = from_repo.bzrdir._format.initialize(tmp_dirname)
     tmp_repo = from_repo._format.initialize(tmp_bzrdir)
     from_repo.copy_content_into(tmp_repo)
     return tmp_dirname, tmp_repo