~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-17 09:12:11 UTC
  • mfrom: (5430.1.2 merge-2.2-into-devel)
  • Revision ID: pqm@pqm.ubuntu.com-20100917091211-1e9h9nf6bsdjr6bd
(spiv) Merge lp:bzr/2.2, including fixes for #625574, #636930,
        #254278.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import warnings
28
28
 
29
29
from testtools import MultiTestResult
 
30
from testtools.content import Content
30
31
from testtools.content_type import ContentType
31
32
from testtools.matchers import (
32
33
    DocTestMatches,
43
44
    lockdir,
44
45
    memorytree,
45
46
    osutils,
46
 
    progress,
47
47
    remote,
48
48
    repository,
49
49
    symbol_versioning,
326
326
        from bzrlib.tests.per_interrepository import make_scenarios
327
327
        server1 = "a"
328
328
        server2 = "b"
329
 
        formats = [("C0", "C1", "C2"), ("D0", "D1", "D2")]
 
329
        formats = [("C0", "C1", "C2", "C3"), ("D0", "D1", "D2", "D3")]
330
330
        scenarios = make_scenarios(server1, server2, formats)
331
331
        self.assertEqual([
332
332
            ('C0,str,str',
333
333
             {'repository_format': 'C1',
334
334
              'repository_format_to': 'C2',
335
335
              'transport_readonly_server': 'b',
336
 
              'transport_server': 'a'}),
 
336
              'transport_server': 'a',
 
337
              'extra_setup': 'C3'}),
337
338
            ('D0,str,str',
338
339
             {'repository_format': 'D1',
339
340
              'repository_format_to': 'D2',
340
341
              'transport_readonly_server': 'b',
341
 
              'transport_server': 'a'})],
 
342
              'transport_server': 'a',
 
343
              'extra_setup': 'D3'})],
342
344
            scenarios)
343
345
 
344
346
 
1676
1678
        self.assertEqual('original', obj.test_attr)
1677
1679
 
1678
1680
 
 
1681
class TestTestCloning(tests.TestCase):
 
1682
    """Tests that test cloning of TestCases (as used by multiply_tests)."""
 
1683
 
 
1684
    def test_cloned_testcase_does_not_share_details(self):
 
1685
        """A TestCase cloned with clone_test does not share mutable attributes
 
1686
        such as details or cleanups.
 
1687
        """
 
1688
        class Test(tests.TestCase):
 
1689
            def test_foo(self):
 
1690
                self.addDetail('foo', Content('text/plain', lambda: 'foo'))
 
1691
        orig_test = Test('test_foo')
 
1692
        cloned_test = tests.clone_test(orig_test, orig_test.id() + '(cloned)')
 
1693
        orig_test.run(unittest.TestResult())
 
1694
        self.assertEqual('foo', orig_test.getDetails()['foo'].iter_bytes())
 
1695
        self.assertEqual(None, cloned_test.getDetails().get('foo'))
 
1696
 
 
1697
    def test_double_apply_scenario_preserves_first_scenario(self):
 
1698
        """Applying two levels of scenarios to a test preserves the attributes
 
1699
        added by both scenarios.
 
1700
        """
 
1701
        class Test(tests.TestCase):
 
1702
            def test_foo(self):
 
1703
                pass
 
1704
        test = Test('test_foo')
 
1705
        scenarios_x = [('x=1', {'x': 1}), ('x=2', {'x': 2})]
 
1706
        scenarios_y = [('y=1', {'y': 1}), ('y=2', {'y': 2})]
 
1707
        suite = tests.multiply_tests(test, scenarios_x, unittest.TestSuite())
 
1708
        suite = tests.multiply_tests(suite, scenarios_y, unittest.TestSuite())
 
1709
        all_tests = list(tests.iter_suite_tests(suite))
 
1710
        self.assertLength(4, all_tests)
 
1711
        all_xys = sorted((t.x, t.y) for t in all_tests)
 
1712
        self.assertEqual([(1, 1), (1, 2), (2, 1), (2, 2)], all_xys)
 
1713
 
 
1714
 
1679
1715
# NB: Don't delete this; it's not actually from 0.11!
1680
1716
@deprecated_function(deprecated_in((0, 11, 0)))
1681
1717
def sample_deprecated_function():