File: code_browser_test_case.py

package info (click to toggle)
python-envisageplugins 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,616 kB
  • ctags: 1,970
  • sloc: python: 7,047; makefile: 11; sh: 11; lisp: 1
file content (103 lines) | stat: -rw-r--r-- 3,228 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
""" Tests for the Enthought code browser. """

# Standard library imports.
import os.path
import logging

# Log to stidout (for now!).
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)


# Standard library imports.
import inspect, unittest

# Enthought library imports.
from enthought.util.resource import get_path

from enthought.envisage.developer.code_browser.api import CodeBrowser



class CodeBrowserTestCase(unittest.TestCase):
    """ Tests for the Enthought code browser. """

    ###########################################################################
    # 'TestCase' interface.
    ###########################################################################

    def setUp(self):
        """ Prepares the test fixture before each test method is called. """

        self.code_browser = CodeBrowser()
        
        return

    def tearDown(self):
        """ Called immediately after each test method has been called. """

        return
    
    ###########################################################################
    # Tests.
    ###########################################################################

    def test_browse_this_module(self):
        """ browse this module """

        # We don't use '__file__' as the filename here as it could refer to the
        # '.pyc' file (we could just strip the 'c' of course, but inspect just
        # seems more intentional ;^).
        filename = inspect.getsourcefile(CodeBrowserTestCase)
        module = self.code_browser.read_file(filename)

        # Check the module name and documentation.
        self.assertEqual('code_browser_test_case', module.name)
        self.assertEqual(" Tests for the Enthought code browser. ", module.doc)

        # Check that the module contains this class!
        klass = module.klasses['CodeBrowserTestCase']
        self.assertEqual(" Tests for the Enthought code browser. ", klass.doc)

        # And that the class contains this method.
        method = klass.methods['test_browse_this_module']
        self.assertEqual(" browse this module ", method.doc)

        return

    def test_has_traits(self):
        """ has traits """

        module = self.code_browser.read_file(
                     os.path.join(
                         get_path(CodeBrowserTestCase),
                         'example_1.py'))

        # Check the module name and documentation.
        self.assertEqual('example_1', module.name)

        # Check that the module contains the specified class.
        klass = module.klasses.get('Base')
        self.assertNotEqual(None, klass)

        # Check the class' base class.
        self.assertEqual(['HasTraits'], klass.bases)
        
        # Check that the class has the appropriate traits and methods.
        self.assertEqual(2, len(klass.traits))
        x = klass.traits['x']
        y = klass.traits['y']

        self.assertEqual(2, len(klass.methods))
        foo = klass.methods['foo']
        bar = klass.methods['bar']
        
        return


# Entry point for stand-alone testing.
if __name__ == '__main__':
    unittest.main()

#### EOF ######################################################################