I have implemented a tree in Python. However, due to my lack of experience with Python, I am not able to judge the overall quality of my code.import unittestfrom datetime import *from gc import *RET_NO = 0RET_YES = 1RET_MAYBE = 0.5 # haha :)class Tree(object):        Mutable abstract data type for arbitrary data with O(N) access on elements.        def __init__(self):        super(Tree, self).__init__()        self.root = None    def insert(self, element):        if self.root:            self.root.insert(element)        else:            self.root = Node(element)    def contains(self, element):        if self.root is None:            print 'WARN: Contains() called before elements were inserted!!'            raise Exception()        return self.root.contains(element) if self.root else RET_NO    def size(self):        return self.root.size() if self.root else 0    def bulk_insert(self, elements=[]):        while len(elements):            self.insert(element[0])            elements = elements[1:]class Node(object):        Node class to be used in Tree instances.        def __init__(self, element):        super(Node, self).__init__()        self.element = element        self.left = None        self.right = None    def insert(self, element):        if self.element == element:            return        if element < self.element:            if self.left:                self.left.insert(element)            else:                self.left = Node(element)        else:            if self.right:                self.right.insert(element)            else:                self.right = Node(element)        raise Exception('Should never reach this line!')    def contains(self, element):        if self.element == element:            return RET_YES        if element < self.element:            if self.left:                return self.left.contains(element)            else:                return RET_NO        else:            if self.right:                return self.right.contains(element)            else:                return RET_NO        raise Exception('Should never reach this line!')    def size(self):                Return size                left_size = self.left.size() if self.left else 0        right_size = self.right.size() if self.right else 0        return left_size + right_size + 1class TreeTest(unittest.TestCase):    def setUp(self):        # no setup required yet        pass    def tearDown(self):        # leave memory in a clean state        gc.collect()    def test_1(self):        #tree = Tree()        #self.assertEqual(tree.size(), 0)        #tree.insert(10)        #self.assertEqual(tree.size(), 10)        self.assertTrue(True)    def test_2(self):        start = datetime.now()        elements = []        for i in range(1000000):            elements += [i]        tree = Tree()        # tree should be empty        for i in elements:            self.assertEqual(tree.contains(i), RET_NO)        # fill tree        for i in elements:            tree.insert(i)        # tree should be full        for i in elements:            self.assertEqual(tree.contains(i), RET_YES)        end = datetime.now()        elapsed = end - start        # must not take longer than a minute        self.assertTrue(elasped.total_seconds() < 60)    def test_3(self):        tree = Tree()        try:            tree.contains(1)            # should have thrown an exception -> test failed            self.assertTrue(False)        except Exception, ValueError:            # expected to raise an Exception -> test should pass            self.assertTrue(True)
Python beginner's tree with unit tests
python;beginner;python 2.7;unit testing;tree