def main(argv):
    """ Do it! """

    if len(argv) != 2:
        print('Usage: python example.py module_name')
        print
        print('e.g., python example.py traits')

    else:
        # Create a code browser.
        code_browser = CodeBrowser(filename='data.pickle')

        # Parse the specified package.
        start = time.time()
        contents = code_browser.read_package(sys.argv[1])
        stop = time.time()

        print('Time taken to parse', sys.argv[1], 'was', stop - start, 'secs')

        # Save the cache.
        code_browser.save('data.pickle')

    return
Exemplo n.º 2
0
def main(argv):
    """ Do it! """

    if len(argv) != 2:
        print('Usage: python example.py module_name')
        print
        print('e.g., python example.py traits')

    else:
        # Create a code browser.
        code_browser = CodeBrowser(filename='data.pickle')

        # Parse the specified package.
        start = time.time()
        contents = code_browser.read_package(sys.argv[1])
        stop = time.time()

        print('Time taken to parse', sys.argv[1], 'was', stop - start, 'secs')

        # Save the cache.
        code_browser.save('data.pickle')

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

        self.code_browser = CodeBrowser()

        return
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