<commit_before># Author: <NAME>
# License: BSD style
# Copyright (c) 2004, Enthought, Inc.

"""Tests class_tree.py.  Uses the vtk module to test the code.  Also
tests if the tree generation works for the __builtin__ module.

"""

import unittest
from enthought.tvtk import class_tree

import vtk
import __builtin__

# This computation can be expensive, so we cache it.
_cache = class_tree.ClassTree(vtk)
_cache.create()


def get_level(klass):
    """Gets the inheritance level of a given class."""
    if not klass.__bases__:
        return 0
    else:
        return max([get_level(b) for b in klass.__bases__]) + 1


class TestClassTree(unittest.TestCase):
    def setUp(self):
        self.t = _cache
    
    def test_basic_vtk(self):
        """Basic tests for the VTK module."""
        t = self.t
        self.assertEqual(t.get_node('vtkObject').name, 'vtkObject')
        self.assertEqual(t.get_node('vtkObject').parents[0].name,
                         'vtkObjectBase')
        self.assertEqual(len(t.tree[0]), 1)
        self.assertEqual(t.tree[0][0].name, 'vtkObjectBase')

    def test_ancestors(self):
        """Check if get_ancestors is OK."""

        # The parent child information is already tested so this test
        # needs to ensure that the method works for a few known
        # examples.

        # Simple VTK test.
        t = self.t
        n = t.get_node('vtkDataArray')
        if hasattr(vtk, 'vtkAbstractArray'):
            self.assertEqual([x.name for x in n.get_ancestors()],
                             ['vtkAbstractArray', 'vtkObject', 'vtkObjectBase'])
        else:
            self.assertEqual([x.name for x in n.get_ancestors()],
                             ['vtkObject', 'vtkObjectBase'])

        # Simple __builtin__ test.
        t = class_tree.ClassTree(__builtin__)
        t.create()
        n = t.get_node('TabError')
        bases = ['IndentationError', 'SyntaxError',
                 'StandardError', 'Exception']
        if len(Exception.__bases__) > 0:
            bases.extend(['BaseException', 'object'])
        self.assertEqual([x.name for x in n.get_ancestors()],
                         bases)

    def test_parent_child(self):
        """Check if the node's parent and children are correct."""
        t = self.t
<commit_msg>BUG: Fixed test error by dynamically computing the class hierarchy to test against.<commit_after># Author: <NAME>
# License: BSD style
# Copyright (c) 2004, Enthought, Inc.

"""Tests class_tree.py.  Uses the vtk module to test the code.  Also
tests if the tree generation works for the __builtin__ module.

"""

import unittest
from enthought.tvtk import class_tree

import vtk
import __builtin__

# This computation can be expensive, so we cache it.
_cache = class_tree.ClassTree(vtk)
_cache.create()


def get_level(klass):
    """Gets the inheritance level of a given class."""
    if not klass.__bases__:
        return 0
    else:
        return max([get_level(b) for b in klass.__bases__]) + 1


class TestClassTree(unittest.TestCase):
    def setUp(self):
        self.t = _cache
    
    def test_basic_vtk(self):
        """Basic tests for the VTK module."""
        t = self.t
        self.assertEqual(t.get_node('vtkObject').name, 'vtkObject')
        self.assertEqual(t.get_node('vtkObject').parents[0].name,
                         'vtkObjectBase')
        self.assertEqual(len(t.tree[0]), 1)
        self.assertEqual(t.tree[0][0].name, 'vtkObjectBase')

    def test_ancestors(self):
        """Check if get_ancestors is OK."""

        # The parent child information is already tested so this test
        # needs to ensure that the method works for a few known
        # examples.

        # Simple VTK test.
        t = self.t
        n = t.get_node('vtkDataArray')
        x = vtk.vtkDataArray
        ancestors = []
        while x.__name__ != 'vtkObjectBase':
            x = x.__bases__[0]
            ancestors.append(x.__name__)
        self.assertEqual([x.name for x in n.get_ancestors()], ancestors)

        # Simple __builtin__ test.
        t = class_tree.ClassTree(__builtin__)
        t.create()
        n = t.get_node('TabError')
        bases = ['IndentationError', 'SyntaxError',
                 'StandardError', 'Exception']
        if len(Exception.__bases__) > 0:
            bases.extend(['BaseException', 'object'])
        self.assertEqual([x.name for x in n.get_ancestors()],
                         bases)

    def test_parent_child(self):
        """Check if the node's parent and children are correct."""
        t = self.t

{'fraction_non_alphanumeric': 0.11159833369875027, 'fraction_numerical': 0.005481254110940584, 'mean_word_length': 2.3717664449371765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5436471', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1367, 'n_words': 394}