Rev 4774: Cleanup imports in test_conflicts in file:///home/vila/src/bzr/cleanup/various/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Dec 10 15:10:36 GMT 2009
At file:///home/vila/src/bzr/cleanup/various/
------------------------------------------------------------
revno: 4774
revision-id: v.ladeuil+lp at free.fr-20091210151036-yz9ak6m51do9xru3
parent: pqm at pqm.ubuntu.com-20091027155759-zjw6vnvs7fyk0lch
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: various
timestamp: Thu 2009-12-10 16:10:36 +0100
message:
Cleanup imports in test_conflicts
-------------- next part --------------
=== modified file 'bzrlib/tests/test_conflicts.py'
--- a/bzrlib/tests/test_conflicts.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_conflicts.py 2009-12-10 15:10:36 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,24 +17,14 @@
import os
-from bzrlib import bzrdir
-from bzrlib.tests import TestCaseWithTransport, TestCase
-from bzrlib.branch import Branch
-from bzrlib.conflicts import (
- ConflictList,
- ContentsConflict,
- DuplicateID,
- DuplicateEntry,
- MissingParent,
- NonDirectoryParent,
- ParentLoop,
- PathConflict,
- TextConflict,
- UnversionedParent,
- resolve,
- restore,
+from bzrlib import (
+ bzrdir,
+ conflicts,
+ errors,
+ tests,
+ workingtree,
)
-from bzrlib.errors import NotConflicted
+from bzrlib.tests import script
# TODO: Test commit with some added, and added-but-missing files
@@ -44,107 +34,118 @@
# be a sorted list.
# u'\xe5' == a with circle
# '\xc3\xae' == u'\xee' == i with hat
-# So these are u'pathg' and 'idg' only with a circle and a hat. (shappo?)
-example_conflicts = ConflictList([
- MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
- ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
- TextConflict(u'p\xe5tha'),
- PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
- DuplicateID('Unversioned existing file', u'p\xe5thc', u'p\xe5thc2',
- '\xc3\xaedc', '\xc3\xaedc'),
- DuplicateEntry('Moved existing file to', u'p\xe5thdd.moved', u'p\xe5thd',
- '\xc3\xaedd', None),
- ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
- None, '\xc3\xaed2e'),
- UnversionedParent('Versioned directory', u'p\xe5thf', '\xc3\xaedf'),
- NonDirectoryParent('Created directory', u'p\xe5thg', '\xc3\xaedg'),
+# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
+example_conflicts = conflicts.ConflictList(
+ [conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
+ conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
+ conflicts.TextConflict(u'p\xe5tha'),
+ conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
+ conflicts.DuplicateID('Unversioned existing file',
+ u'p\xe5thc', u'p\xe5thc2',
+ '\xc3\xaedc', '\xc3\xaedc'),
+ conflicts.DuplicateEntry('Moved existing file to',
+ u'p\xe5thdd.moved', u'p\xe5thd',
+ '\xc3\xaedd', None),
+ conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
+ None, '\xc3\xaed2e'),
+ conflicts.UnversionedParent('Versioned directory',
+ u'p\xe5thf', '\xc3\xaedf'),
+ conflicts.NonDirectoryParent('Created directory',
+ u'p\xe5thg', '\xc3\xaedg'),
])
-class TestConflicts(TestCaseWithTransport):
+class TestConflicts(tests.TestCaseWithTransport):
def test_conflicts(self):
"""Conflicts are detected properly"""
- tree = self.make_branch_and_tree('.',
- format=bzrdir.BzrDirFormat6())
- b = tree.branch
- file('hello', 'w').write('hello world4')
- file('hello.THIS', 'w').write('hello world2')
- file('hello.BASE', 'w').write('hello world1')
- file('hello.OTHER', 'w').write('hello world3')
- file('hello.sploo.BASE', 'w').write('yellow world')
- file('hello.sploo.OTHER', 'w').write('yellow world2')
+ # Use BzrDirFormat6 so we can fake conflicts
+ tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
+ self.build_tree_contents([('hello', 'hello world4'),
+ ('hello.THIS', 'hello world2'),
+ ('hello.BASE', 'hello world1'),
+ ('hello.OTHER', 'hello world3'),
+ ('hello.sploo.BASE', 'yellowworld'),
+ ('hello.sploo.OTHER', 'yellowworld2'),
+ ])
tree.lock_read()
- self.assertEqual(len(list(tree.list_files())), 6)
+ self.assertEqual(6, len(list(tree.list_files())))
tree.unlock()
- conflicts = tree.conflicts()
- self.assertEqual(len(conflicts), 2)
- self.assert_('hello' in conflicts[0].path)
- self.assert_('hello.sploo' in conflicts[1].path)
- restore('hello')
- restore('hello.sploo')
- self.assertEqual(len(tree.conflicts()), 0)
+ tree_conflicts = tree.conflicts()
+ self.assertEqual(2, len(tree_conflicts))
+ self.assertTrue('hello' in tree_conflicts[0].path)
+ self.assertTrue('hello.sploo' in tree_conflicts[1].path)
+ conflicts.restore('hello')
+ conflicts.restore('hello.sploo')
+ self.assertEqual(0, len(tree.conflicts()))
self.assertFileEqual('hello world2', 'hello')
self.assertFalse(os.path.lexists('hello.sploo'))
- self.assertRaises(NotConflicted, restore, 'hello')
- self.assertRaises(NotConflicted, restore, 'hello.sploo')
+ self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
+ self.assertRaises(errors.NotConflicted,
+ conflicts.restore, 'hello.sploo')
def test_resolve_conflict_dir(self):
tree = self.make_branch_and_tree('.')
- b = tree.branch
- file('hello', 'w').write('hello world4')
+ self.build_tree_contents([('hello', 'hello world4'),
+ ('hello.THIS', 'hello world2'),
+ ('hello.BASE', 'hello world1'),
+ ])
+ os.mkdir('hello.OTHER')
tree.add('hello', 'q')
- file('hello.THIS', 'w').write('hello world2')
- file('hello.BASE', 'w').write('hello world1')
- os.mkdir('hello.OTHER')
- l = ConflictList([TextConflict('hello')])
+ l = conflicts.ConflictList([conflicts.TextConflict('hello')])
l.remove_files(tree)
def test_select_conflicts(self):
tree = self.make_branch_and_tree('.')
- tree_conflicts = ConflictList([ContentsConflict('foo'),
- ContentsConflict('bar')])
- self.assertEqual((ConflictList([ContentsConflict('bar')]),
- ConflictList([ContentsConflict('foo')])),
- tree_conflicts.select_conflicts(tree, ['foo']))
- self.assertEqual((ConflictList(), tree_conflicts),
- tree_conflicts.select_conflicts(tree, [''],
- ignore_misses=True, recurse=True))
- tree_conflicts = ConflictList([ContentsConflict('foo/baz'),
- ContentsConflict('bar')])
- self.assertEqual((ConflictList([ContentsConflict('bar')]),
- ConflictList([ContentsConflict('foo/baz')])),
- tree_conflicts.select_conflicts(tree, ['foo'],
- recurse=True,
- ignore_misses=True))
- tree_conflicts = ConflictList([PathConflict('qux', 'foo/baz')])
- self.assertEqual((ConflictList(), tree_conflicts),
- tree_conflicts.select_conflicts(tree, ['foo'],
- recurse=True,
- ignore_misses=True))
- self.assertEqual((tree_conflicts, ConflictList()),
- tree_conflicts.select_conflicts(tree, ['foo'],
- ignore_misses=True))
+ clist = conflicts.ConflictList
+
+ def check_select(not_selected, selected, paths, **kwargs):
+ self.assertEqual(
+ (not_selected, selected),
+ tree_conflicts.select_conflicts(tree, paths, **kwargs))
+
+ foo = conflicts.ContentsConflict('foo')
+ bar = conflicts.ContentsConflict('bar')
+ tree_conflicts = clist([foo, bar])
+
+ check_select(clist([bar]), clist([foo]), ['foo'])
+ check_select(clist(), tree_conflicts,
+ [''], ignore_misses=True, recurse=True)
+
+ foobaz = conflicts.ContentsConflict('foo/baz')
+ tree_conflicts = clist([foobaz, bar])
+
+ check_select(clist([bar]), clist([foobaz]),
+ ['foo'], ignore_misses=True, recurse=True)
+
+ qux = conflicts.PathConflict('qux', 'foo/baz')
+ tree_conflicts = clist([qux])
+
+ check_select(clist(), tree_conflicts,
+ ['foo'], ignore_misses=True, recurse=True)
+ check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
def test_resolve_conflicts_recursive(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['dir/', 'dir/hello'])
tree.add(['dir', 'dir/hello'])
- tree.set_conflicts(ConflictList([TextConflict('dir/hello')]))
- resolve(tree, ['dir'], recursive=False, ignore_misses=True)
- self.assertEqual(ConflictList([TextConflict('dir/hello')]),
- tree.conflicts())
- resolve(tree, ['dir'], recursive=True, ignore_misses=True)
- self.assertEqual(ConflictList([]),
- tree.conflicts())
-
-
-class TestConflictStanzas(TestCase):
+
+ dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
+ tree.set_conflicts(dirhello)
+
+ conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
+ self.assertEqual(dirhello, tree.conflicts())
+
+ conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
+ self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
+
+
+class TestConflictStanzas(tests.TestCase):
def test_stanza_roundtrip(self):
# write and read our example stanza.
stanza_iter = example_conflicts.to_stanzas()
- processed = ConflictList.from_stanzas(stanza_iter)
+ processed = conflicts.ConflictList.from_stanzas(stanza_iter)
for o, p in zip(processed, example_conflicts):
self.assertEqual(o, p)
@@ -171,3 +172,4 @@
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
if 'conflict_file_id' in stanza:
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
+
More information about the bazaar-commits
mailing list