def test_to_context_suite(self):
        def add_test(node, val):
            node.add_test(ArbitraryTest(str(val)))

        tree = Node(None)
        add_test(tree, 1)
        add_test(tree, 2)
        for i in range(3):
            name = 'a' + str(i)
            n = tree.add_context([name], name)
            add_test(n, name)
        level3 = tree.add_context(['a1', 'c'], 'c')
        add_test(level3, 'l3')
        csuite = tree.to_context_suite()

        def collapse_csuite(csuite):
            result = []
            for thing in csuite:
                if isinstance(thing, ContextSuite):
                    item = (thing.context, collapse_csuite(thing))
                else:
                    item = thing.id().split('.')[-1]
                result.append(item)
            return result

        result = collapse_csuite(csuite)
        expected = [('a0', ['a0']), ('a1', [('c', ['l3']), 'a1']),
                    ('a2', ['a2']), '1', '2']
        self.assertEqual(result, expected)
    def test_to_context_suite(self):
        def add_test(node, val):
            node.add_test(ArbitraryTest(str(val)))

        tree = Node(None)
        add_test(tree, 1)
        add_test(tree, 2)
        for i in range(3):
            name = 'a' + str(i)
            n = tree.add_context([name], name)
            add_test(n, name)
        level3 = tree.add_context(['a1', 'c'], 'c')
        add_test(level3, 'l3')
        csuite = tree.to_context_suite()

        def collapse_csuite(csuite):
            result = []
            for thing in csuite:
                if isinstance(thing, ContextSuite):
                    item = (thing.context, collapse_csuite(thing))
                else:
                    item = thing.id().split('.')[-1]
                result.append(item)
            return result
        result = collapse_csuite(csuite)
        expected = [
            ('a0', ['a0']),
            ('a1', [
                ('c', ['l3']),
                'a1'
            ]),
            ('a2', ['a2']),
            '1',
            '2']
        self.assertEqual(result, expected)
 def test_add_context_finds_right_position(self):
     n1 = Node('parent')
     n2 = n1.add_context(['path'], 'child')
     n3 = n1.add_context(['path', 'to'], 'grandchild')
     self.assertEqual(n2.children, {'to': n3})
     self.assertEqual(n3.context, 'grandchild')
 def test_add_context_returns_existing(self):
     n1 = Node('parent')
     n2 = n1.add_context(['path'], 'child')
     n3 = n1.add_context(['path'], 'whatever')
     self.assertEqual(n3, n2)
 def test_add_context_adds_child(self):
     n1 = Node('parent')
     n2 = n1.add_context(['path'], 'child')
     self.assertEqual(n1.children['path'], n2)
     self.assertEqual(n2.context, 'child')
 def test_add_context_no_path(self):
     n = Node(None)
     self.assertEqual(n.add_context([], None), n)
 def test_add_context_finds_right_position(self):
     n1 = Node('parent')
     n2 = n1.add_context(['path'], 'child')
     n3 = n1.add_context(['path','to'], 'grandchild')
     self.assertEqual(n2.children, {'to': n3})
     self.assertEqual(n3.context, 'grandchild')
 def test_add_context_returns_existing(self):
     n1 = Node('parent')
     n2 = n1.add_context(['path'], 'child')
     n3 = n1.add_context(['path'], 'whatever')
     self.assertEqual(n3, n2)
 def test_add_context_adds_child(self):
     n1 = Node('parent')
     n2 = n1.add_context(['path'], 'child')
     self.assertEqual(n1.children['path'], n2)
     self.assertEqual(n2.context, 'child')
 def test_add_context_no_path(self):
     n = Node(None)
     self.assertEqual(n.add_context([], None), n)