Commits

Anonymous committed fbadf66

PyName.get_attributes and PyName.get_type

Comments (0)

Files changed (5)

+======================
 rope, A python IDE ...
+======================
 
 Overview
---------
+========
   'rope' is a Python IDE. Its main goal is to provide features like
 auto-completion, refactorings, content assists and outlines. It is 
 written in python and uses the Tkinter library.
 
 
 Version Overview
-----------------
+================
 Features added in this release:
 
-* Auto-complete local variable names
-* Proposing templates in code-assist proposals
-* Auto-complete from-import imported objects
-* Not proposing variables which are not defined yet
-* Proposing function parameters in functions
-* Auto-completion ignores current statement errors
-* Next/prev word stops at underlines and capitals
-* Ignoring string and comment contents while indenting
-
-Rope is moving on. By 0.2 release, rope's auto-completion will be
-almost perfect.
+*
 
 
 Keybinding
-----------
+==========
   The keybinding will be customizable in future. 
 Some of these bindings are choosen from emacs and some from eclipse.
 
 
 
 Description
------------
+===========
   This program, rope, is a python IDE. It tries to give users lots of things
 that are not available in python IDEs yet.
 
 
 
 Project Road Map
-----------------
+================
   The main motive for starting this project was the lack of good
 refactoring tools for python language. Refactoring programs like "bicycle repair man"
 aren't reliable due to type inferencing problems discussed earlier and they
 
 
 Get Involved!
--------------
+=============
   Rope has just started. Right now rope's design changes rapidly and it's not
 yet ready for code contributions. I hope in soon future, somewhere about version
 0.5 or 0.6, rope would be mature enough for being extended easily.
 
 
 Bug Reports
------------
+===========
   Send your bug reports and feature requests to rope's sourceforge.net
 project page at http://sf.net/projects/rope.
 
 
 License
--------
+=======
   This program is under the terms of GPL(GNU General Public License). Have a
 look at copying file for more information.
+

docs/workingon.txt

-Auto-completing "self."s @ 2
+Auto-completing "self."s @ 4
 ============================
 
 - Better attributes names in pycore classes
 - What if the element does not exist
 - Making modules from strings
 - Imports and pycore
+- PyName.get_attributes() and PyName.get_type()
 
+* Making scopes using PyNames
 * Better names for making the distinction between PyName and PyObject
 * Add to runtests
 ? PyObject might have additional information based on their types; visitor
   * Function types should have args, defaults, keywords attributes
-* Making scopes using PyNames
 ? PyObject equality check; Value objects
 ? Getting children only when necessary, invalidating
 ? Classes and functions defined in functions
 * More builtin templates; hash, eq
 * Enhancing highlighting
 * Profiling to find the bottlenecks
-? Ready for announcing at Cheese Shop
+* Document features added since release 0.1
 
 
 
         result.is_package = False
         return result
 
+    def get_string_scope(self, module_content):
+        return Scope()
+
     def _create(self, resource):
         if resource.is_folder():
             attributes = {}
     def __init__(self, object_=None):
         self.object = object_
 
+    def get_attributes(self):
+        return self.object.attributes
+    
+    def get_type(self):
+        return self.object.type
+
+
+class Scope(object):
+    def get_names(self):
+        return {'sample_func': None}
+
 
 class _GlobalVisitor(object):
 

ropetest/pycoretest.py

         self.assertEquals(PyType.get_type('Module'), package.type)
         self.assertEquals(1, len(package.attributes))
         module = package.attributes['mod']
-        self.assertEquals(PyType.get_type('Module'), module.object.type)
+        self.assertEquals(PyType.get_type('Module'), module.get_type())
 
     def test_package(self):
         pkg = self.project.create_package(self.project.get_root_folder(), 'pkg')
         mod.write('class SampleClass(object):\n    pass\n')
         mod_element = self.pycore.get_module('mod')
         result = mod_element.attributes['SampleClass']
-        self.assertEquals(PyType.get_type('Type'), result.object.type)
+        self.assertEquals(PyType.get_type('Type'), result.get_type())
 
     def test_simple_function(self):
         mod = self.project.create_module(self.project.get_root_folder(), 'mod')
         mod.write('def sample_function():\n    pass\n')
         mod_element = self.pycore.get_module('mod')
         result = mod_element.attributes['sample_function']
-        self.assertEquals(PyType.get_type('Function'), result.object.type)
+        self.assertEquals(PyType.get_type('Function'), result.get_type())
 
     def test_class_methods(self):
         mod = self.project.create_module(self.project.get_root_folder(), 'mod')
         mod.write('class SampleClass(object):\n    def sample_method(self):\n        pass\n')
         mod_element = self.pycore.get_module('mod')
         sample_class = mod_element.attributes['SampleClass']
-        self.assertEquals(1, len(sample_class.object.attributes))
-        method = sample_class.object.attributes['sample_method']
-                
+        self.assertEquals(1, len(sample_class.get_attributes()))
+        method = sample_class.get_attributes()['sample_method']
+        self.assertEquals(PyType.get_type('Function'), method.get_type())
+
     def test_global_variables(self):
         mod = self.project.create_module(self.project.get_root_folder(), 'mod')
         mod.write('var = 10')
         mod.write('class SampleClass(object):\n    var = 10\n')
         mod_element = self.pycore.get_module('mod')
         sample_class = mod_element.attributes['SampleClass']
-        var = sample_class.object.attributes['var']
+        var = sample_class.get_attributes()['var']
         
     def test_class_attributes_set_in_init(self):
         mod = self.project.create_module(self.project.get_root_folder(), 'mod')
         mod.write('class SampleClass(object):\n    def __init__(self):\n        self.var = 20\n')
         mod_element = self.pycore.get_module('mod')
         sample_class = mod_element.attributes['SampleClass']
-        var = sample_class.object.attributes['var']
+        var = sample_class.get_attributes()['var']
         
     def test_classes_inside_other_classes(self):
         mod = self.project.create_module(self.project.get_root_folder(), 'mod')
         mod.write('class SampleClass(object):\n    class InnerClass(object):\n        pass\n\n')
         mod_element = self.pycore.get_module('mod')
         sample_class = mod_element.attributes['SampleClass']
-        var = sample_class.object.attributes['InnerClass']
-        self.assertEquals(PyType.get_type('Type'), var.object.type)
+        var = sample_class.get_attributes()['InnerClass']
+        self.assertEquals(PyType.get_type('Type'), var.get_type())
 
     def test_non_existant_module(self):
         try:
         mod.write('import mod1\n')
         module = self.pycore.get_module('mod2')
         imported_sys = module.attributes['mod1']
-        self.assertEquals(PyType.get_type('Module'), imported_sys.object.type)
+        self.assertEquals(PyType.get_type('Module'), imported_sys.get_type())
 
     def test_importing_out_of_project_names(self):
         mod = self.project.create_module(self.project.get_root_folder(), 'mod')
         mod.write('import sys\n')
         module = self.pycore.get_module('mod')
         imported_sys = module.attributes['sys']
-        self.assertEquals(PyType.get_type('Module'), imported_sys.object.type)
+        self.assertEquals(PyType.get_type('Module'), imported_sys.get_type())
 
     def test_imported_as_names(self):
         self.project.create_module(self.project.get_root_folder(), 'mod1')
         mod.write('import mod1 as my_import\n')
         module = self.pycore.get_module('mod2')
         imported_mod = module.attributes['my_import']
-        self.assertEquals(PyType.get_type('Module'), imported_mod.object.type)
+        self.assertEquals(PyType.get_type('Module'), imported_mod.get_type())
 
     def test_get_string_module(self):
         mod = self.pycore.get_string_module('class Sample(object):\n    pass\n')
         sample_class = mod.attributes['Sample']
-        self.assertEquals(PyType.get_type('Type'), sample_class.object.type)
+        self.assertEquals(PyType.get_type('Type'), sample_class.get_type())
 
 
 class PyCoreInProjectsTest(unittest.TestCase):
     def test_simple_import(self):
         mod = self.pycore.get_string_module('import samplemod\n')
         samplemod = mod.attributes['samplemod']
-        self.assertEquals(PyType.get_type('Module'), samplemod.object.type)
+        self.assertEquals(PyType.get_type('Module'), samplemod.get_type())
 
     def test_from_import_class(self):
         mod = self.pycore.get_string_module('from samplemod import SampleClass\n')
         result = mod.attributes['SampleClass']
-        self.assertEquals(PyType.get_type('Type'), result.object.type)
+        self.assertEquals(PyType.get_type('Type'), result.get_type())
         self.assertTrue('sample_func' not in mod.attributes)
 
     def test_from_import_star(self):
         mod = self.pycore.get_string_module('from samplemod import *\n')
-        self.assertEquals(PyType.get_type('Type'), mod.attributes['SampleClass'].object.type)
-        self.assertEquals(PyType.get_type('Function'), mod.attributes['sample_func'].object.type)
+        self.assertEquals(PyType.get_type('Type'), mod.attributes['SampleClass'].get_type())
+        self.assertEquals(PyType.get_type('Function'), mod.attributes['sample_func'].get_type())
         self.assertTrue(mod.attributes['sample_var'] is not None)
 
     def test_from_import_star_not_imporing_underlined(self):
 
     def test_from_package_import_mod(self):
         mod = self.pycore.get_string_module('from package import nestedmod\n')
-        self.assertEquals(PyType.get_type('Module'), mod.attributes['nestedmod'].object.type)
+        self.assertEquals(PyType.get_type('Module'), mod.attributes['nestedmod'].get_type())
 
     def test_from_package_import_star(self):
         mod = self.pycore.get_string_module('from package import *\nnest')
         mod = self.pycore.get_string_module('from doesnotexist import nestedmod\n')
         self.assertTrue('nestedmod' in mod.attributes)
 
+
+class PyCoreScopesTest(unittest.TestCase):
+
+    def setUp(self):
+        super(PyCoreScopesTest, self).setUp()
+        self.project_root = 'sample_project'
+        testutils.remove_recursively(self.project_root)
+        self.project = Project(self.project_root)
+        self.pycore = PyCore(self.project)
+
+    def tearDown(self):
+        testutils.remove_recursively(self.project_root)
+        super(PyCoreScopesTest, self).tearDown()
+
+    def test_simple_scope(self):
+        scope = self.pycore.get_string_scope('def sample_func():\n    pass\n')
+        self.assertTrue('sample_func' in scope.get_names())
+
     # TODO: These are related to scopes
     def xxx_test_from_import_function(self):
         code = 'from samplemod import sample_func\nsample'
         self.assert_completion_in_result('SampleClass', 'class', result)
 
 
+def suite():
+    result = unittest.TestSuite()
+    result.addTests(unittest.makeSuite(PyElementHierarchyTest))
+    result.addTests(unittest.makeSuite(PyCoreInProjectsTest))
+    result.addTests(unittest.makeSuite(PyCoreScopesTest))
+    return result
 
 if __name__ == '__main__':
     unittest.main()
     result.addTests(ropetest.codeassisttest.suite())
     result.addTests(unittest.makeSuite(ropetest.statusbartest.StatusBarTest))
     result.addTests(unittest.makeSuite(ropetest.codeanalyzetest.StatementRangeFinderTest))
-    result.addTests(unittest.makeSuite(ropetest.pycoretest.PyElementHierarchyTest))
+    result.addTests(ropetest.pycoretest.suite())
     runner = unittest.TextTestRunner()
     runner.run(result)