bee_python 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +202 -0
- data/build/README +23 -0
- data/egg/egg/build.yml +70 -0
- data/egg/egg/ez_setup.py +280 -0
- data/egg/egg/script.py +12 -0
- data/egg/egg/setup.erb +11 -0
- data/egg/egg/suite.py +37 -0
- data/egg/egg/test.py +31 -0
- data/egg/egg.yml +69 -0
- data/egg/http/build.erb +53 -0
- data/egg/http/server.py +34 -0
- data/egg/http.yml +50 -0
- data/egg/mysql/mysql.py +43 -0
- data/egg/mysql.yml +44 -0
- data/egg/project/build.erb +77 -0
- data/egg/project/script.py +42 -0
- data/egg/project/test.py +31 -0
- data/egg/project.yml +59 -0
- data/egg/script/build.erb +35 -0
- data/egg/script/script.py +42 -0
- data/egg/script.yml +50 -0
- data/egg/soap/build.erb +52 -0
- data/egg/soap/client.py +18 -0
- data/egg/soap/server.py +30 -0
- data/egg/soap.yml +58 -0
- data/egg/source/source.py +42 -0
- data/egg/source.yml +47 -0
- data/egg/test/test.py +28 -0
- data/egg/test.yml +44 -0
- data/egg/xmlrpc/build.erb +52 -0
- data/egg/xmlrpc/client.py +22 -0
- data/egg/xmlrpc/server.py +24 -0
- data/egg/xmlrpc.yml +51 -0
- data/lib/bee_task_python.rb +390 -0
- data/test/build.yml +16 -0
- data/test/tc_bee_task_python.rb +27 -0
- data/test/test_build.rb +26 -0
- data/test/test_build_listener.rb +62 -0
- data/test/ts_bee_python.rb +26 -0
- data/tools/common/__init__.py +5 -0
- data/tools/common/common/__init__.py +140 -0
- data/tools/common/common/__pkginfo__.py +43 -0
- data/tools/common/common/adbh.py +35 -0
- data/tools/common/common/cache.py +114 -0
- data/tools/common/common/changelog.py +234 -0
- data/tools/common/common/clcommands.py +181 -0
- data/tools/common/common/cli.py +212 -0
- data/tools/common/common/compat.py +328 -0
- data/tools/common/common/configuration.py +1087 -0
- data/tools/common/common/contexts.py +58 -0
- data/tools/common/common/corbautils.py +117 -0
- data/tools/common/common/daemon.py +171 -0
- data/tools/common/common/date.py +279 -0
- data/tools/common/common/db.py +49 -0
- data/tools/common/common/dbf.py +229 -0
- data/tools/common/common/debugger.py +208 -0
- data/tools/common/common/decorators.py +190 -0
- data/tools/common/common/deprecation.py +118 -0
- data/tools/common/common/fileutils.py +409 -0
- data/tools/common/common/graph.py +259 -0
- data/tools/common/common/html.py +142 -0
- data/tools/common/common/interface.py +76 -0
- data/tools/common/common/logging_ext.py +166 -0
- data/tools/common/common/modutils.py +670 -0
- data/tools/common/common/optik_ext.py +383 -0
- data/tools/common/common/optparser.py +92 -0
- data/tools/common/common/pdf_ext.py +111 -0
- data/tools/common/common/proc.py +276 -0
- data/tools/common/common/pyro_ext.py +146 -0
- data/tools/common/common/pytest.py +754 -0
- data/tools/common/common/shellutils.py +383 -0
- data/tools/common/common/sphinx_ext.py +87 -0
- data/tools/common/common/sphinxutils.py +122 -0
- data/tools/common/common/sqlgen.py +31 -0
- data/tools/common/common/table.py +930 -0
- data/tools/common/common/tasksqueue.py +97 -0
- data/tools/common/common/test/__init__.py +1 -0
- data/tools/common/common/test/data/ChangeLog +184 -0
- data/tools/common/common/test/data/MyPyPa-0.1.0-py2.5.egg +0 -0
- data/tools/common/common/test/data/__init__.py +1 -0
- data/tools/common/common/test/data/content_differ_dir/NOTHING +0 -0
- data/tools/common/common/test/data/content_differ_dir/README +1 -0
- data/tools/common/common/test/data/content_differ_dir/subdir/coin +1 -0
- data/tools/common/common/test/data/content_differ_dir/subdir/toto.txt +53 -0
- data/tools/common/common/test/data/file_differ_dir/NOTHING +0 -0
- data/tools/common/common/test/data/file_differ_dir/README +1 -0
- data/tools/common/common/test/data/file_differ_dir/subdir/toto.txt +53 -0
- data/tools/common/common/test/data/file_differ_dir/subdirtwo/Hello +0 -0
- data/tools/common/common/test/data/find_test/__init__.py +0 -0
- data/tools/common/common/test/data/find_test/foo.txt +0 -0
- data/tools/common/common/test/data/find_test/module.py +0 -0
- data/tools/common/common/test/data/find_test/module2.py +0 -0
- data/tools/common/common/test/data/find_test/newlines.txt +0 -0
- data/tools/common/common/test/data/find_test/noendingnewline.py +0 -0
- data/tools/common/common/test/data/find_test/nonregr.py +0 -0
- data/tools/common/common/test/data/find_test/normal_file.txt +0 -0
- data/tools/common/common/test/data/find_test/spam.txt +0 -0
- data/tools/common/common/test/data/find_test/sub/doc.txt +0 -0
- data/tools/common/common/test/data/find_test/sub/momo.py +0 -0
- data/tools/common/common/test/data/find_test/test.ini +0 -0
- data/tools/common/common/test/data/find_test/test1.msg +0 -0
- data/tools/common/common/test/data/find_test/test2.msg +0 -0
- data/tools/common/common/test/data/find_test/write_protected_file.txt +0 -0
- data/tools/common/common/test/data/foo.txt +9 -0
- data/tools/common/common/test/data/module.py +88 -0
- data/tools/common/common/test/data/module2.py +77 -0
- data/tools/common/common/test/data/newlines.txt +3 -0
- data/tools/common/common/test/data/noendingnewline.py +36 -0
- data/tools/common/common/test/data/nonregr.py +14 -0
- data/tools/common/common/test/data/normal_file.txt +0 -0
- data/tools/common/common/test/data/reference_dir/NOTHING +0 -0
- data/tools/common/common/test/data/reference_dir/README +1 -0
- data/tools/common/common/test/data/reference_dir/subdir/coin +1 -0
- data/tools/common/common/test/data/reference_dir/subdir/toto.txt +53 -0
- data/tools/common/common/test/data/same_dir/NOTHING +0 -0
- data/tools/common/common/test/data/same_dir/README +1 -0
- data/tools/common/common/test/data/same_dir/subdir/coin +1 -0
- data/tools/common/common/test/data/same_dir/subdir/toto.txt +53 -0
- data/tools/common/common/test/data/spam.txt +9 -0
- data/tools/common/common/test/data/sub/doc.txt +1 -0
- data/tools/common/common/test/data/sub/momo.py +1 -0
- data/tools/common/common/test/data/subdir_differ_dir/NOTHING +0 -0
- data/tools/common/common/test/data/subdir_differ_dir/README +1 -0
- data/tools/common/common/test/data/subdir_differ_dir/subdir/coin +1 -0
- data/tools/common/common/test/data/subdir_differ_dir/subdir/toto.txt +53 -0
- data/tools/common/common/test/data/test.ini +20 -0
- data/tools/common/common/test/data/test1.msg +30 -0
- data/tools/common/common/test/data/test2.msg +42 -0
- data/tools/common/common/test/data/write_protected_file.txt +0 -0
- data/tools/common/common/test/foomod.py +17 -0
- data/tools/common/common/test/unittest_cache.py +129 -0
- data/tools/common/common/test/unittest_changelog.py +37 -0
- data/tools/common/common/test/unittest_compat.py +239 -0
- data/tools/common/common/test/unittest_configuration.py +348 -0
- data/tools/common/common/test/unittest_date.py +154 -0
- data/tools/common/common/test/unittest_decorators.py +62 -0
- data/tools/common/common/test/unittest_deprecation.py +76 -0
- data/tools/common/common/test/unittest_fileutils.py +133 -0
- data/tools/common/common/test/unittest_graph.py +50 -0
- data/tools/common/common/test/unittest_html.py +76 -0
- data/tools/common/common/test/unittest_interface.py +87 -0
- data/tools/common/common/test/unittest_modutils.py +244 -0
- data/tools/common/common/test/unittest_pytest.py +50 -0
- data/tools/common/common/test/unittest_shellutils.py +248 -0
- data/tools/common/common/test/unittest_table.py +448 -0
- data/tools/common/common/test/unittest_taskqueue.py +71 -0
- data/tools/common/common/test/unittest_testlib.py +956 -0
- data/tools/common/common/test/unittest_textutils.py +247 -0
- data/tools/common/common/test/unittest_tree.py +248 -0
- data/tools/common/common/test/unittest_umessage.py +55 -0
- data/tools/common/common/test/unittest_ureports_html.py +64 -0
- data/tools/common/common/test/unittest_ureports_text.py +105 -0
- data/tools/common/common/test/unittest_xmlutils.py +75 -0
- data/tools/common/common/test/utils.py +87 -0
- data/tools/common/common/testlib.py +1927 -0
- data/tools/common/common/textutils.py +476 -0
- data/tools/common/common/tree.py +372 -0
- data/tools/common/common/umessage.py +161 -0
- data/tools/common/common/ureports/__init__.py +174 -0
- data/tools/common/common/ureports/docbook_writer.py +139 -0
- data/tools/common/common/ureports/html_writer.py +131 -0
- data/tools/common/common/ureports/nodes.py +201 -0
- data/tools/common/common/ureports/text_writer.py +140 -0
- data/tools/common/common/vcgutils.py +216 -0
- data/tools/common/common/visitor.py +107 -0
- data/tools/common/common/xmlrpcutils.py +136 -0
- data/tools/common/common/xmlutils.py +61 -0
- data/tools/compile/compile.py +16 -0
- data/tools/coverage/coverage.py +602 -0
- data/tools/epydoc/__init__.py +227 -0
- data/tools/epydoc/__init__.pyc +0 -0
- data/tools/epydoc/apidoc.py +2203 -0
- data/tools/epydoc/apidoc.pyc +0 -0
- data/tools/epydoc/checker.py +349 -0
- data/tools/epydoc/checker.pyc +0 -0
- data/tools/epydoc/cli.py +1470 -0
- data/tools/epydoc/cli.pyc +0 -0
- data/tools/epydoc/compat.py +250 -0
- data/tools/epydoc/compat.pyc +0 -0
- data/tools/epydoc/docbuilder.py +1358 -0
- data/tools/epydoc/docbuilder.pyc +0 -0
- data/tools/epydoc/docintrospecter.py +1056 -0
- data/tools/epydoc/docintrospecter.pyc +0 -0
- data/tools/epydoc/docparser.py +2113 -0
- data/tools/epydoc/docparser.pyc +0 -0
- data/tools/epydoc/docstringparser.py +1111 -0
- data/tools/epydoc/docstringparser.pyc +0 -0
- data/tools/epydoc/docwriter/__init__.py +12 -0
- data/tools/epydoc/docwriter/__init__.pyc +0 -0
- data/tools/epydoc/docwriter/dotgraph.py +1351 -0
- data/tools/epydoc/docwriter/dotgraph.pyc +0 -0
- data/tools/epydoc/docwriter/html.py +3491 -0
- data/tools/epydoc/docwriter/html.pyc +0 -0
- data/tools/epydoc/docwriter/html_colorize.py +909 -0
- data/tools/epydoc/docwriter/html_colorize.pyc +0 -0
- data/tools/epydoc/docwriter/html_css.py +550 -0
- data/tools/epydoc/docwriter/html_css.pyc +0 -0
- data/tools/epydoc/docwriter/html_help.py +190 -0
- data/tools/epydoc/docwriter/html_help.pyc +0 -0
- data/tools/epydoc/docwriter/latex.py +1187 -0
- data/tools/epydoc/docwriter/latex.pyc +0 -0
- data/tools/epydoc/docwriter/plaintext.py +276 -0
- data/tools/epydoc/docwriter/plaintext.pyc +0 -0
- data/tools/epydoc/docwriter/xlink.py +505 -0
- data/tools/epydoc/docwriter/xlink.pyc +0 -0
- data/tools/epydoc/gui.py +1148 -0
- data/tools/epydoc/gui.pyc +0 -0
- data/tools/epydoc/log.py +204 -0
- data/tools/epydoc/log.pyc +0 -0
- data/tools/epydoc/markup/__init__.py +623 -0
- data/tools/epydoc/markup/__init__.pyc +0 -0
- data/tools/epydoc/markup/doctest.py +311 -0
- data/tools/epydoc/markup/doctest.pyc +0 -0
- data/tools/epydoc/markup/epytext.py +2116 -0
- data/tools/epydoc/markup/epytext.pyc +0 -0
- data/tools/epydoc/markup/javadoc.py +250 -0
- data/tools/epydoc/markup/javadoc.pyc +0 -0
- data/tools/epydoc/markup/plaintext.py +78 -0
- data/tools/epydoc/markup/plaintext.pyc +0 -0
- data/tools/epydoc/markup/pyval_repr.py +532 -0
- data/tools/epydoc/markup/pyval_repr.pyc +0 -0
- data/tools/epydoc/markup/restructuredtext.py +906 -0
- data/tools/epydoc/markup/restructuredtext.pyc +0 -0
- data/tools/epydoc/test/__init__.py +97 -0
- data/tools/epydoc/test/__init__.pyc +0 -0
- data/tools/epydoc/test/util.py +226 -0
- data/tools/epydoc/test/util.pyc +0 -0
- data/tools/epydoc/util.py +289 -0
- data/tools/epydoc/util.pyc +0 -0
- data/tools/logilab/logilab/__init__.py +5 -0
- data/tools/logilab/logilab/astng/__init__.py +82 -0
- data/tools/logilab/logilab/astng/__pkginfo__.py +76 -0
- data/tools/logilab/logilab/astng/_exceptions.py +64 -0
- data/tools/logilab/logilab/astng/_nodes_ast.py +667 -0
- data/tools/logilab/logilab/astng/_nodes_compiler.py +758 -0
- data/tools/logilab/logilab/astng/bases.py +608 -0
- data/tools/logilab/logilab/astng/builder.py +239 -0
- data/tools/logilab/logilab/astng/inference.py +426 -0
- data/tools/logilab/logilab/astng/inspector.py +289 -0
- data/tools/logilab/logilab/astng/manager.py +421 -0
- data/tools/logilab/logilab/astng/mixins.py +165 -0
- data/tools/logilab/logilab/astng/node_classes.py +848 -0
- data/tools/logilab/logilab/astng/nodes.py +85 -0
- data/tools/logilab/logilab/astng/nodes_as_string.py +389 -0
- data/tools/logilab/logilab/astng/patchcomptransformer.py +159 -0
- data/tools/logilab/logilab/astng/protocols.py +333 -0
- data/tools/logilab/logilab/astng/raw_building.py +212 -0
- data/tools/logilab/logilab/astng/rebuilder.py +307 -0
- data/tools/logilab/logilab/astng/scoped_nodes.py +951 -0
- data/tools/logilab/logilab/astng/test/__init__.py +19 -0
- data/tools/logilab/logilab/astng/test/data/MyPyPa-0.1.0-py2.5.egg +0 -0
- data/tools/logilab/logilab/astng/test/data/MyPyPa-0.1.0-py2.5.zip +0 -0
- data/tools/logilab/logilab/astng/test/data/SSL1/Connection1.py +33 -0
- data/tools/logilab/logilab/astng/test/data/SSL1/__init__.py +20 -0
- data/tools/logilab/logilab/astng/test/data/__init__.py +20 -0
- data/tools/logilab/logilab/astng/test/data/all.py +29 -0
- data/tools/logilab/logilab/astng/test/data/appl/__init__.py +23 -0
- data/tools/logilab/logilab/astng/test/data/appl/myConnection.py +30 -0
- data/tools/logilab/logilab/astng/test/data/format.py +34 -0
- data/tools/logilab/logilab/astng/test/data/module.py +90 -0
- data/tools/logilab/logilab/astng/test/data/module2.py +112 -0
- data/tools/logilab/logilab/astng/test/data/noendingnewline.py +57 -0
- data/tools/logilab/logilab/astng/test/data/nonregr.py +76 -0
- data/tools/logilab/logilab/astng/test/data/notall.py +28 -0
- data/tools/logilab/logilab/astng/test/data2/__init__.py +20 -0
- data/tools/logilab/logilab/astng/test/data2/clientmodule_test.py +51 -0
- data/tools/logilab/logilab/astng/test/data2/suppliermodule_test.py +32 -0
- data/tools/logilab/logilab/astng/test/regrtest.py +135 -0
- data/tools/logilab/logilab/astng/test/regrtest_data/absimport.py +22 -0
- data/tools/logilab/logilab/astng/test/regrtest_data/descriptor_crash.py +31 -0
- data/tools/logilab/logilab/astng/test/regrtest_data/import_package_subpackage_module.py +68 -0
- data/tools/logilab/logilab/astng/test/regrtest_data/package/__init__.py +24 -0
- data/tools/logilab/logilab/astng/test/regrtest_data/package/subpackage/__init__.py +20 -0
- data/tools/logilab/logilab/astng/test/regrtest_data/package/subpackage/module.py +20 -0
- data/tools/logilab/logilab/astng/test/unittest_builder.py +684 -0
- data/tools/logilab/logilab/astng/test/unittest_inference.py +1112 -0
- data/tools/logilab/logilab/astng/test/unittest_inspector.py +105 -0
- data/tools/logilab/logilab/astng/test/unittest_lookup.py +302 -0
- data/tools/logilab/logilab/astng/test/unittest_manager.py +98 -0
- data/tools/logilab/logilab/astng/test/unittest_nodes.py +302 -0
- data/tools/logilab/logilab/astng/test/unittest_scoped_nodes.py +501 -0
- data/tools/logilab/logilab/astng/test/unittest_utils.py +104 -0
- data/tools/logilab/logilab/astng/utils.py +342 -0
- data/tools/logilab/logilab/common/__init__.py +140 -0
- data/tools/logilab/logilab/common/__pkginfo__.py +43 -0
- data/tools/logilab/logilab/common/adbh.py +35 -0
- data/tools/logilab/logilab/common/cache.py +114 -0
- data/tools/logilab/logilab/common/changelog.py +234 -0
- data/tools/logilab/logilab/common/clcommands.py +181 -0
- data/tools/logilab/logilab/common/cli.py +212 -0
- data/tools/logilab/logilab/common/compat.py +328 -0
- data/tools/logilab/logilab/common/configuration.py +1087 -0
- data/tools/logilab/logilab/common/contexts.py +58 -0
- data/tools/logilab/logilab/common/corbautils.py +117 -0
- data/tools/logilab/logilab/common/daemon.py +171 -0
- data/tools/logilab/logilab/common/date.py +279 -0
- data/tools/logilab/logilab/common/db.py +49 -0
- data/tools/logilab/logilab/common/dbf.py +229 -0
- data/tools/logilab/logilab/common/debugger.py +208 -0
- data/tools/logilab/logilab/common/decorators.py +190 -0
- data/tools/logilab/logilab/common/deprecation.py +118 -0
- data/tools/logilab/logilab/common/fileutils.py +409 -0
- data/tools/logilab/logilab/common/graph.py +259 -0
- data/tools/logilab/logilab/common/html.py +142 -0
- data/tools/logilab/logilab/common/interface.py +76 -0
- data/tools/logilab/logilab/common/logging_ext.py +166 -0
- data/tools/logilab/logilab/common/modutils.py +670 -0
- data/tools/logilab/logilab/common/optik_ext.py +383 -0
- data/tools/logilab/logilab/common/optparser.py +92 -0
- data/tools/logilab/logilab/common/pdf_ext.py +111 -0
- data/tools/logilab/logilab/common/proc.py +276 -0
- data/tools/logilab/logilab/common/pyro_ext.py +146 -0
- data/tools/logilab/logilab/common/pytest.py +754 -0
- data/tools/logilab/logilab/common/shellutils.py +383 -0
- data/tools/logilab/logilab/common/sphinx_ext.py +87 -0
- data/tools/logilab/logilab/common/sphinxutils.py +122 -0
- data/tools/logilab/logilab/common/sqlgen.py +31 -0
- data/tools/logilab/logilab/common/table.py +930 -0
- data/tools/logilab/logilab/common/tasksqueue.py +97 -0
- data/tools/logilab/logilab/common/test/__init__.py +1 -0
- data/tools/logilab/logilab/common/test/data/ChangeLog +184 -0
- data/tools/logilab/logilab/common/test/data/MyPyPa-0.1.0-py2.5.egg +0 -0
- data/tools/logilab/logilab/common/test/data/__init__.py +1 -0
- data/tools/logilab/logilab/common/test/data/content_differ_dir/NOTHING +0 -0
- data/tools/logilab/logilab/common/test/data/content_differ_dir/README +1 -0
- data/tools/logilab/logilab/common/test/data/content_differ_dir/subdir/coin +1 -0
- data/tools/logilab/logilab/common/test/data/content_differ_dir/subdir/toto.txt +53 -0
- data/tools/logilab/logilab/common/test/data/file_differ_dir/NOTHING +0 -0
- data/tools/logilab/logilab/common/test/data/file_differ_dir/README +1 -0
- data/tools/logilab/logilab/common/test/data/file_differ_dir/subdir/toto.txt +53 -0
- data/tools/logilab/logilab/common/test/data/file_differ_dir/subdirtwo/Hello +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/__init__.py +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/foo.txt +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/module.py +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/module2.py +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/newlines.txt +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/noendingnewline.py +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/nonregr.py +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/normal_file.txt +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/spam.txt +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/sub/doc.txt +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/sub/momo.py +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/test.ini +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/test1.msg +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/test2.msg +0 -0
- data/tools/logilab/logilab/common/test/data/find_test/write_protected_file.txt +0 -0
- data/tools/logilab/logilab/common/test/data/foo.txt +9 -0
- data/tools/logilab/logilab/common/test/data/module.py +88 -0
- data/tools/logilab/logilab/common/test/data/module2.py +77 -0
- data/tools/logilab/logilab/common/test/data/newlines.txt +3 -0
- data/tools/logilab/logilab/common/test/data/noendingnewline.py +36 -0
- data/tools/logilab/logilab/common/test/data/nonregr.py +14 -0
- data/tools/logilab/logilab/common/test/data/normal_file.txt +0 -0
- data/tools/logilab/logilab/common/test/data/reference_dir/NOTHING +0 -0
- data/tools/logilab/logilab/common/test/data/reference_dir/README +1 -0
- data/tools/logilab/logilab/common/test/data/reference_dir/subdir/coin +1 -0
- data/tools/logilab/logilab/common/test/data/reference_dir/subdir/toto.txt +53 -0
- data/tools/logilab/logilab/common/test/data/same_dir/NOTHING +0 -0
- data/tools/logilab/logilab/common/test/data/same_dir/README +1 -0
- data/tools/logilab/logilab/common/test/data/same_dir/subdir/coin +1 -0
- data/tools/logilab/logilab/common/test/data/same_dir/subdir/toto.txt +53 -0
- data/tools/logilab/logilab/common/test/data/spam.txt +9 -0
- data/tools/logilab/logilab/common/test/data/sub/doc.txt +1 -0
- data/tools/logilab/logilab/common/test/data/sub/momo.py +1 -0
- data/tools/logilab/logilab/common/test/data/subdir_differ_dir/NOTHING +0 -0
- data/tools/logilab/logilab/common/test/data/subdir_differ_dir/README +1 -0
- data/tools/logilab/logilab/common/test/data/subdir_differ_dir/subdir/coin +1 -0
- data/tools/logilab/logilab/common/test/data/subdir_differ_dir/subdir/toto.txt +53 -0
- data/tools/logilab/logilab/common/test/data/test.ini +20 -0
- data/tools/logilab/logilab/common/test/data/test1.msg +30 -0
- data/tools/logilab/logilab/common/test/data/test2.msg +42 -0
- data/tools/logilab/logilab/common/test/data/write_protected_file.txt +0 -0
- data/tools/logilab/logilab/common/test/foomod.py +17 -0
- data/tools/logilab/logilab/common/test/unittest_cache.py +129 -0
- data/tools/logilab/logilab/common/test/unittest_changelog.py +37 -0
- data/tools/logilab/logilab/common/test/unittest_compat.py +239 -0
- data/tools/logilab/logilab/common/test/unittest_configuration.py +348 -0
- data/tools/logilab/logilab/common/test/unittest_date.py +154 -0
- data/tools/logilab/logilab/common/test/unittest_decorators.py +62 -0
- data/tools/logilab/logilab/common/test/unittest_deprecation.py +76 -0
- data/tools/logilab/logilab/common/test/unittest_fileutils.py +133 -0
- data/tools/logilab/logilab/common/test/unittest_graph.py +50 -0
- data/tools/logilab/logilab/common/test/unittest_html.py +76 -0
- data/tools/logilab/logilab/common/test/unittest_interface.py +87 -0
- data/tools/logilab/logilab/common/test/unittest_modutils.py +244 -0
- data/tools/logilab/logilab/common/test/unittest_pytest.py +50 -0
- data/tools/logilab/logilab/common/test/unittest_shellutils.py +248 -0
- data/tools/logilab/logilab/common/test/unittest_table.py +448 -0
- data/tools/logilab/logilab/common/test/unittest_taskqueue.py +71 -0
- data/tools/logilab/logilab/common/test/unittest_testlib.py +956 -0
- data/tools/logilab/logilab/common/test/unittest_textutils.py +247 -0
- data/tools/logilab/logilab/common/test/unittest_tree.py +248 -0
- data/tools/logilab/logilab/common/test/unittest_umessage.py +55 -0
- data/tools/logilab/logilab/common/test/unittest_ureports_html.py +64 -0
- data/tools/logilab/logilab/common/test/unittest_ureports_text.py +105 -0
- data/tools/logilab/logilab/common/test/unittest_xmlutils.py +75 -0
- data/tools/logilab/logilab/common/test/utils.py +87 -0
- data/tools/logilab/logilab/common/testlib.py +1927 -0
- data/tools/logilab/logilab/common/textutils.py +476 -0
- data/tools/logilab/logilab/common/tree.py +372 -0
- data/tools/logilab/logilab/common/umessage.py +161 -0
- data/tools/logilab/logilab/common/ureports/__init__.py +174 -0
- data/tools/logilab/logilab/common/ureports/docbook_writer.py +139 -0
- data/tools/logilab/logilab/common/ureports/html_writer.py +131 -0
- data/tools/logilab/logilab/common/ureports/nodes.py +201 -0
- data/tools/logilab/logilab/common/ureports/text_writer.py +140 -0
- data/tools/logilab/logilab/common/vcgutils.py +216 -0
- data/tools/logilab/logilab/common/visitor.py +107 -0
- data/tools/logilab/logilab/common/xmlrpcutils.py +136 -0
- data/tools/logilab/logilab/common/xmlutils.py +61 -0
- data/tools/pychecker/COPYRIGHT +31 -0
- data/tools/pychecker/ChangeLog +349 -0
- data/tools/pychecker/CodeChecks.py +1969 -0
- data/tools/pychecker/CodeChecks.pyc +0 -0
- data/tools/pychecker/CodeChecks.pyo +0 -0
- data/tools/pychecker/Config.py +475 -0
- data/tools/pychecker/Config.pyc +0 -0
- data/tools/pychecker/Config.pyo +0 -0
- data/tools/pychecker/KNOWN_BUGS +100 -0
- data/tools/pychecker/MAINTAINERS +81 -0
- data/tools/pychecker/NEWS +406 -0
- data/tools/pychecker/OP.py +131 -0
- data/tools/pychecker/OP.pyc +0 -0
- data/tools/pychecker/OP.pyo +0 -0
- data/tools/pychecker/OptionTypes.py +117 -0
- data/tools/pychecker/OptionTypes.pyc +0 -0
- data/tools/pychecker/OptionTypes.pyo +0 -0
- data/tools/pychecker/README +152 -0
- data/tools/pychecker/Stack.py +115 -0
- data/tools/pychecker/Stack.pyc +0 -0
- data/tools/pychecker/Stack.pyo +0 -0
- data/tools/pychecker/TODO +101 -0
- data/tools/pychecker/VERSION +1 -0
- data/tools/pychecker/Warning.py +50 -0
- data/tools/pychecker/Warning.pyc +0 -0
- data/tools/pychecker/Warning.pyo +0 -0
- data/tools/pychecker/__init__.py +17 -0
- data/tools/pychecker/__init__.pyc +0 -0
- data/tools/pychecker/__init__.pyo +0 -0
- data/tools/pychecker/checker.py +961 -0
- data/tools/pychecker/checker.pyc +0 -0
- data/tools/pychecker/checker.pyo +0 -0
- data/tools/pychecker/function.py +159 -0
- data/tools/pychecker/function.pyc +0 -0
- data/tools/pychecker/function.pyo +0 -0
- data/tools/pychecker/msgs.py +175 -0
- data/tools/pychecker/msgs.pyc +0 -0
- data/tools/pychecker/msgs.pyo +0 -0
- data/tools/pychecker/options.py +275 -0
- data/tools/pychecker/options.pyc +0 -0
- data/tools/pychecker/options.pyo +0 -0
- data/tools/pychecker/pcmodules.py +19 -0
- data/tools/pychecker/pcmodules.pyc +0 -0
- data/tools/pychecker/pcmodules.pyo +0 -0
- data/tools/pychecker/printer.py +47 -0
- data/tools/pychecker/printer.pyc +0 -0
- data/tools/pychecker/printer.pyo +0 -0
- data/tools/pychecker/python.py +427 -0
- data/tools/pychecker/python.pyc +0 -0
- data/tools/pychecker/python.pyo +0 -0
- data/tools/pychecker/utils.py +102 -0
- data/tools/pychecker/utils.pyc +0 -0
- data/tools/pychecker/utils.pyo +0 -0
- data/tools/pychecker/warn.py +778 -0
- data/tools/pychecker/warn.pyc +0 -0
- data/tools/pychecker/warn.pyo +0 -0
- data/tools/pylint2/pylint/__init__.py +16 -0
- data/tools/pylint2/pylint/__pkginfo__.py +67 -0
- data/tools/pylint2/pylint/checkers/__init__.py +155 -0
- data/tools/pylint2/pylint/checkers/base.py +749 -0
- data/tools/pylint2/pylint/checkers/classes.py +527 -0
- data/tools/pylint2/pylint/checkers/design_analysis.py +344 -0
- data/tools/pylint2/pylint/checkers/exceptions.py +183 -0
- data/tools/pylint2/pylint/checkers/format.py +367 -0
- data/tools/pylint2/pylint/checkers/imports.py +379 -0
- data/tools/pylint2/pylint/checkers/logging.py +98 -0
- data/tools/pylint2/pylint/checkers/misc.py +128 -0
- data/tools/pylint2/pylint/checkers/newstyle.py +107 -0
- data/tools/pylint2/pylint/checkers/raw_metrics.py +125 -0
- data/tools/pylint2/pylint/checkers/similar.py +333 -0
- data/tools/pylint2/pylint/checkers/string_format.py +239 -0
- data/tools/pylint2/pylint/checkers/typecheck.py +364 -0
- data/tools/pylint2/pylint/checkers/utils.py +208 -0
- data/tools/pylint2/pylint/checkers/variables.py +498 -0
- data/tools/pylint2/pylint/config.py +149 -0
- data/tools/pylint2/pylint/epylint.py +149 -0
- data/tools/pylint2/pylint/gui.py +433 -0
- data/tools/pylint2/pylint/interfaces.py +98 -0
- data/tools/pylint2/pylint/lint.py +914 -0
- data/tools/pylint2/pylint/pyreverse/__init__.py +5 -0
- data/tools/pylint2/pylint/pyreverse/diadefslib.py +229 -0
- data/tools/pylint2/pylint/pyreverse/diagrams.py +247 -0
- data/tools/pylint2/pylint/pyreverse/main.py +123 -0
- data/tools/pylint2/pylint/pyreverse/utils.py +131 -0
- data/tools/pylint2/pylint/pyreverse/writer.py +196 -0
- data/tools/pylint2/pylint/reporters/__init__.py +67 -0
- data/tools/pylint2/pylint/reporters/guireporter.py +36 -0
- data/tools/pylint2/pylint/reporters/html.py +69 -0
- data/tools/pylint2/pylint/reporters/text.py +156 -0
- data/tools/pylint2/pylint/utils.py +518 -0
- data/tools/pylint2/pylint.py +16 -0
- data/tools/test/suite.py +35 -0
- metadata +566 -0
@@ -0,0 +1,1112 @@
|
|
1
|
+
# This program is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the GNU Lesser General Public License as published by the Free Software
|
3
|
+
# Foundation; either version 2 of the License, or (at your option) any later
|
4
|
+
# version.
|
5
|
+
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
|
6
|
+
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
|
7
|
+
# copyright 2003-2010 Sylvain Thenault, all rights reserved.
|
8
|
+
# contact mailto:thenault@gmail.com
|
9
|
+
#
|
10
|
+
# This file is part of logilab-astng.
|
11
|
+
#
|
12
|
+
# logilab-astng is free software: you can redistribute it and/or modify it
|
13
|
+
# under the terms of the GNU Lesser General Public License as published by the
|
14
|
+
# Free Software Foundation, either version 2.1 of the License, or (at your
|
15
|
+
# option) any later version.
|
16
|
+
#
|
17
|
+
# logilab-astng is distributed in the hope that it will be useful, but
|
18
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
20
|
+
# for more details.
|
21
|
+
#
|
22
|
+
# You should have received a copy of the GNU Lesser General Public License along
|
23
|
+
# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
|
24
|
+
|
25
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
26
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
27
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
28
|
+
|
29
|
+
# You should have received a copy of the GNU Lesser General Public License along with
|
30
|
+
# this program; if not, write to the Free Software Foundation, Inc.,
|
31
|
+
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
32
|
+
"""tests for the astng inference capabilities
|
33
|
+
"""
|
34
|
+
from os.path import join
|
35
|
+
import sys
|
36
|
+
from StringIO import StringIO
|
37
|
+
from logilab.common.testlib import TestCase, unittest_main
|
38
|
+
|
39
|
+
from logilab.astng import InferenceError, builder, nodes, inference
|
40
|
+
from logilab.astng.bases import YES, Instance, BoundMethod, UnboundMethod, path_wrapper
|
41
|
+
|
42
|
+
def get_name_node(start_from, name, index=0):
|
43
|
+
return [n for n in start_from.nodes_of_class(nodes.Name) if n.name == name][index]
|
44
|
+
|
45
|
+
def get_node_of_class(start_from, klass):
|
46
|
+
return start_from.nodes_of_class(klass).next()
|
47
|
+
|
48
|
+
builder = builder.ASTNGBuilder()
|
49
|
+
|
50
|
+
class InferenceUtilsTC(TestCase):
|
51
|
+
|
52
|
+
def test_path_wrapper(self):
|
53
|
+
def infer_default(self, *args):
|
54
|
+
raise InferenceError
|
55
|
+
infer_default = path_wrapper(infer_default)
|
56
|
+
infer_end = path_wrapper(inference.infer_end)
|
57
|
+
self.failUnlessRaises(InferenceError,
|
58
|
+
infer_default(1).next)
|
59
|
+
self.failUnlessEqual(infer_end(1).next(), 1)
|
60
|
+
|
61
|
+
class InferenceTC(TestCase):
|
62
|
+
|
63
|
+
CODE = '''
|
64
|
+
import exceptions
|
65
|
+
|
66
|
+
class C(object):
|
67
|
+
"new style"
|
68
|
+
attr = 4
|
69
|
+
|
70
|
+
def meth1(self, arg1, optarg=0):
|
71
|
+
var = object()
|
72
|
+
print "yo", arg1, optarg
|
73
|
+
self.iattr = "hop"
|
74
|
+
return var
|
75
|
+
|
76
|
+
def meth2(self):
|
77
|
+
self.meth1(*self.meth3)
|
78
|
+
|
79
|
+
def meth3(self, d=attr):
|
80
|
+
b = self.attr
|
81
|
+
c = self.iattr
|
82
|
+
return b, c
|
83
|
+
|
84
|
+
ex = exceptions.Exception("msg")
|
85
|
+
v = C().meth1(1)
|
86
|
+
m_unbound = C.meth1
|
87
|
+
m_bound = C().meth1
|
88
|
+
a, b, c = ex, 1, "bonjour"
|
89
|
+
[d, e, f] = [ex, 1.0, ("bonjour", v)]
|
90
|
+
g, h = f
|
91
|
+
i, (j, k) = u"glup", f
|
92
|
+
|
93
|
+
a, b= b, a # Gasp !
|
94
|
+
'''
|
95
|
+
|
96
|
+
def setUp(self):
|
97
|
+
self.astng = builder.string_build(self.CODE, __name__, __file__)
|
98
|
+
|
99
|
+
def test_module_inference(self):
|
100
|
+
infered = self.astng.infer()
|
101
|
+
obj = infered.next()
|
102
|
+
self.failUnlessEqual(obj.name, __name__)
|
103
|
+
self.failUnlessEqual(obj.root().name, __name__)
|
104
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
105
|
+
|
106
|
+
def test_class_inference(self):
|
107
|
+
infered = self.astng['C'].infer()
|
108
|
+
obj = infered.next()
|
109
|
+
self.failUnlessEqual(obj.name, 'C')
|
110
|
+
self.failUnlessEqual(obj.root().name, __name__)
|
111
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
112
|
+
|
113
|
+
def test_function_inference(self):
|
114
|
+
infered = self.astng['C']['meth1'].infer()
|
115
|
+
obj = infered.next()
|
116
|
+
self.failUnlessEqual(obj.name, 'meth1')
|
117
|
+
self.failUnlessEqual(obj.root().name, __name__)
|
118
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
119
|
+
|
120
|
+
def test_builtin_name_inference(self):
|
121
|
+
infered = self.astng['C']['meth1']['var'].infer()
|
122
|
+
var = infered.next()
|
123
|
+
self.failUnlessEqual(var.name, 'object')
|
124
|
+
self.failUnlessEqual(var.root().name, '__builtin__')
|
125
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
126
|
+
|
127
|
+
def test_tupleassign_name_inference(self):
|
128
|
+
infered = self.astng['a'].infer()
|
129
|
+
exc = infered.next()
|
130
|
+
self.assertIsInstance(exc, Instance)
|
131
|
+
self.failUnlessEqual(exc.name, 'Exception')
|
132
|
+
self.failUnlessEqual(exc.root().name, 'exceptions')
|
133
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
134
|
+
infered = self.astng['b'].infer()
|
135
|
+
const = infered.next()
|
136
|
+
self.assertIsInstance(const, nodes.Const)
|
137
|
+
self.failUnlessEqual(const.value, 1)
|
138
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
139
|
+
infered = self.astng['c'].infer()
|
140
|
+
const = infered.next()
|
141
|
+
self.assertIsInstance(const, nodes.Const)
|
142
|
+
self.failUnlessEqual(const.value, "bonjour")
|
143
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
144
|
+
|
145
|
+
def test_listassign_name_inference(self):
|
146
|
+
infered = self.astng['d'].infer()
|
147
|
+
exc = infered.next()
|
148
|
+
self.assertIsInstance(exc, Instance)
|
149
|
+
self.failUnlessEqual(exc.name, 'Exception')
|
150
|
+
self.failUnlessEqual(exc.root().name, 'exceptions')
|
151
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
152
|
+
infered = self.astng['e'].infer()
|
153
|
+
const = infered.next()
|
154
|
+
self.assertIsInstance(const, nodes.Const)
|
155
|
+
self.failUnlessEqual(const.value, 1.0)
|
156
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
157
|
+
infered = self.astng['f'].infer()
|
158
|
+
const = infered.next()
|
159
|
+
self.assertIsInstance(const, nodes.Tuple)
|
160
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
161
|
+
|
162
|
+
def test_advanced_tupleassign_name_inference1(self):
|
163
|
+
infered = self.astng['g'].infer()
|
164
|
+
const = infered.next()
|
165
|
+
self.assertIsInstance(const, nodes.Const)
|
166
|
+
self.failUnlessEqual(const.value, "bonjour")
|
167
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
168
|
+
infered = self.astng['h'].infer()
|
169
|
+
var = infered.next()
|
170
|
+
self.failUnlessEqual(var.name, 'object')
|
171
|
+
self.failUnlessEqual(var.root().name, '__builtin__')
|
172
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
173
|
+
|
174
|
+
def test_advanced_tupleassign_name_inference2(self):
|
175
|
+
infered = self.astng['i'].infer()
|
176
|
+
const = infered.next()
|
177
|
+
self.assertIsInstance(const, nodes.Const)
|
178
|
+
self.failUnlessEqual(const.value, u"glup")
|
179
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
180
|
+
infered = self.astng['j'].infer()
|
181
|
+
const = infered.next()
|
182
|
+
self.assertIsInstance(const, nodes.Const)
|
183
|
+
self.failUnlessEqual(const.value, "bonjour")
|
184
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
185
|
+
infered = self.astng['k'].infer()
|
186
|
+
var = infered.next()
|
187
|
+
self.failUnlessEqual(var.name, 'object')
|
188
|
+
self.failUnlessEqual(var.root().name, '__builtin__')
|
189
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
190
|
+
|
191
|
+
def test_swap_assign_inference(self):
|
192
|
+
infered = self.astng.locals['a'][1].infer()
|
193
|
+
const = infered.next()
|
194
|
+
self.assertIsInstance(const, nodes.Const)
|
195
|
+
self.failUnlessEqual(const.value, 1)
|
196
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
197
|
+
infered = self.astng.locals['b'][1].infer()
|
198
|
+
exc = infered.next()
|
199
|
+
self.assertIsInstance(exc, Instance)
|
200
|
+
self.failUnlessEqual(exc.name, 'Exception')
|
201
|
+
self.failUnlessEqual(exc.root().name, 'exceptions')
|
202
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
203
|
+
|
204
|
+
def test_getattr_inference1(self):
|
205
|
+
infered = self.astng['ex'].infer()
|
206
|
+
exc = infered.next()
|
207
|
+
self.assertIsInstance(exc, Instance)
|
208
|
+
self.failUnlessEqual(exc.name, 'Exception')
|
209
|
+
self.failUnlessEqual(exc.root().name, 'exceptions')
|
210
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
211
|
+
|
212
|
+
def test_getattr_inference2(self):
|
213
|
+
infered = get_node_of_class(self.astng['C']['meth2'], nodes.Getattr).infer()
|
214
|
+
meth1 = infered.next()
|
215
|
+
self.failUnlessEqual(meth1.name, 'meth1')
|
216
|
+
self.failUnlessEqual(meth1.root().name, __name__)
|
217
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
218
|
+
|
219
|
+
def test_getattr_inference3(self):
|
220
|
+
infered = self.astng['C']['meth3']['b'].infer()
|
221
|
+
const = infered.next()
|
222
|
+
self.assertIsInstance(const, nodes.Const)
|
223
|
+
self.failUnlessEqual(const.value, 4)
|
224
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
225
|
+
|
226
|
+
def test_getattr_inference4(self):
|
227
|
+
infered = self.astng['C']['meth3']['c'].infer()
|
228
|
+
const = infered.next()
|
229
|
+
self.assertIsInstance(const, nodes.Const)
|
230
|
+
self.failUnlessEqual(const.value, "hop")
|
231
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
232
|
+
|
233
|
+
def test_callfunc_inference(self):
|
234
|
+
infered = self.astng['v'].infer()
|
235
|
+
meth1 = infered.next()
|
236
|
+
self.assertIsInstance(meth1, Instance)
|
237
|
+
self.failUnlessEqual(meth1.name, 'object')
|
238
|
+
self.failUnlessEqual(meth1.root().name, '__builtin__')
|
239
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
240
|
+
|
241
|
+
def test_unbound_method_inference(self):
|
242
|
+
infered = self.astng['m_unbound'].infer()
|
243
|
+
meth1 = infered.next()
|
244
|
+
self.assertIsInstance(meth1, UnboundMethod)
|
245
|
+
self.failUnlessEqual(meth1.name, 'meth1')
|
246
|
+
self.failUnlessEqual(meth1.parent.frame().name, 'C')
|
247
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
248
|
+
|
249
|
+
def test_bound_method_inference(self):
|
250
|
+
infered = self.astng['m_bound'].infer()
|
251
|
+
meth1 = infered.next()
|
252
|
+
self.assertIsInstance(meth1, BoundMethod)
|
253
|
+
self.failUnlessEqual(meth1.name, 'meth1')
|
254
|
+
self.failUnlessEqual(meth1.parent.frame().name, 'C')
|
255
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
256
|
+
|
257
|
+
def test_args_default_inference1(self):
|
258
|
+
optarg = get_name_node(self.astng['C']['meth1'], 'optarg')
|
259
|
+
infered = optarg.infer()
|
260
|
+
obj1 = infered.next()
|
261
|
+
self.assertIsInstance(obj1, nodes.Const)
|
262
|
+
self.failUnlessEqual(obj1.value, 0)
|
263
|
+
obj1 = infered.next()
|
264
|
+
self.assertIs(obj1, YES, obj1)
|
265
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
266
|
+
|
267
|
+
def test_args_default_inference2(self):
|
268
|
+
infered = self.astng['C']['meth3'].ilookup('d')
|
269
|
+
obj1 = infered.next()
|
270
|
+
self.assertIsInstance(obj1, nodes.Const)
|
271
|
+
self.failUnlessEqual(obj1.value, 4)
|
272
|
+
obj1 = infered.next()
|
273
|
+
self.assertIs(obj1, YES, obj1)
|
274
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
275
|
+
|
276
|
+
def test_inference_restrictions(self):
|
277
|
+
infered = get_name_node(self.astng['C']['meth1'], 'arg1').infer()
|
278
|
+
obj1 = infered.next()
|
279
|
+
self.assertIs(obj1, YES, obj1)
|
280
|
+
self.failUnlessRaises(StopIteration, infered.next)
|
281
|
+
|
282
|
+
def test_ancestors_inference(self):
|
283
|
+
code = '''
|
284
|
+
class A:
|
285
|
+
pass
|
286
|
+
|
287
|
+
class A(A):
|
288
|
+
pass
|
289
|
+
'''
|
290
|
+
astng = builder.string_build(code, __name__, __file__)
|
291
|
+
a1 = astng.locals['A'][0]
|
292
|
+
a2 = astng.locals['A'][1]
|
293
|
+
a2_ancestors = list(a2.ancestors())
|
294
|
+
self.failUnlessEqual(len(a2_ancestors), 1)
|
295
|
+
self.failUnless(a2_ancestors[0] is a1)
|
296
|
+
|
297
|
+
def test_ancestors_inference2(self):
|
298
|
+
code = '''
|
299
|
+
class A:
|
300
|
+
pass
|
301
|
+
|
302
|
+
class B(A): pass
|
303
|
+
|
304
|
+
class A(B):
|
305
|
+
pass
|
306
|
+
'''
|
307
|
+
astng = builder.string_build(code, __name__, __file__)
|
308
|
+
a1 = astng.locals['A'][0]
|
309
|
+
a2 = astng.locals['A'][1]
|
310
|
+
a2_ancestors = list(a2.ancestors())
|
311
|
+
self.failUnlessEqual(len(a2_ancestors), 2)
|
312
|
+
self.failUnless(a2_ancestors[0] is astng.locals['B'][0])
|
313
|
+
self.failUnless(a2_ancestors[1] is a1, a2_ancestors[1])
|
314
|
+
|
315
|
+
|
316
|
+
def test_f_arg_f(self):
|
317
|
+
code = '''
|
318
|
+
def f(f=1):
|
319
|
+
return f
|
320
|
+
|
321
|
+
a = f()
|
322
|
+
'''
|
323
|
+
astng = builder.string_build(code, __name__, __file__)
|
324
|
+
a = astng['a']
|
325
|
+
a_infer = a.infer()
|
326
|
+
self.failUnlessEqual(a_infer.next().value, 1)
|
327
|
+
self.failUnlessRaises(StopIteration, a_infer.next)
|
328
|
+
|
329
|
+
def test_exc_ancestors(self):
|
330
|
+
code = '''
|
331
|
+
def f():
|
332
|
+
raise NotImplementedError
|
333
|
+
'''
|
334
|
+
astng = builder.string_build(code, __name__, __file__)
|
335
|
+
names = astng.nodes_of_class(nodes.Name)
|
336
|
+
nie = names.next().infer().next()
|
337
|
+
self.assertIsInstance(nie, nodes.Class)
|
338
|
+
nie_ancestors = [c.name for c in nie.ancestors()]
|
339
|
+
if sys.version_info < (2, 5):
|
340
|
+
self.failUnlessEqual(nie_ancestors, ['RuntimeError', 'StandardError', 'Exception'])
|
341
|
+
else:
|
342
|
+
self.failUnlessEqual(nie_ancestors, ['RuntimeError', 'StandardError', 'Exception', 'BaseException', 'object'])
|
343
|
+
|
344
|
+
def test_except_inference(self):
|
345
|
+
code = '''
|
346
|
+
try:
|
347
|
+
print hop
|
348
|
+
except NameError, ex:
|
349
|
+
ex1 = ex
|
350
|
+
except Exception, ex:
|
351
|
+
ex2 = ex
|
352
|
+
raise
|
353
|
+
'''
|
354
|
+
astng = builder.string_build(code, __name__, __file__)
|
355
|
+
ex1 = astng['ex1']
|
356
|
+
ex1_infer = ex1.infer()
|
357
|
+
ex1 = ex1_infer.next()
|
358
|
+
self.assertIsInstance(ex1, Instance)
|
359
|
+
self.failUnlessEqual(ex1.name, 'NameError')
|
360
|
+
self.failUnlessRaises(StopIteration, ex1_infer.next)
|
361
|
+
ex2 = astng['ex2']
|
362
|
+
ex2_infer = ex2.infer()
|
363
|
+
ex2 = ex2_infer.next()
|
364
|
+
self.assertIsInstance(ex2, Instance)
|
365
|
+
self.failUnlessEqual(ex2.name, 'Exception')
|
366
|
+
self.failUnlessRaises(StopIteration, ex2_infer.next)
|
367
|
+
|
368
|
+
def test_del1(self):
|
369
|
+
code = '''
|
370
|
+
del undefined_attr
|
371
|
+
'''
|
372
|
+
delete = builder.string_build(code, __name__, __file__).body[0]
|
373
|
+
self.failUnlessRaises(InferenceError, delete.infer)
|
374
|
+
|
375
|
+
def test_del2(self):
|
376
|
+
code = '''
|
377
|
+
a = 1
|
378
|
+
b = a
|
379
|
+
del a
|
380
|
+
c = a
|
381
|
+
a = 2
|
382
|
+
d = a
|
383
|
+
'''
|
384
|
+
astng = builder.string_build(code, __name__, __file__)
|
385
|
+
n = astng['b']
|
386
|
+
n_infer = n.infer()
|
387
|
+
infered = n_infer.next()
|
388
|
+
self.assertIsInstance(infered, nodes.Const)
|
389
|
+
self.failUnlessEqual(infered.value, 1)
|
390
|
+
self.failUnlessRaises(StopIteration, n_infer.next)
|
391
|
+
n = astng['c']
|
392
|
+
n_infer = n.infer()
|
393
|
+
self.failUnlessRaises(InferenceError, n_infer.next)
|
394
|
+
n = astng['d']
|
395
|
+
n_infer = n.infer()
|
396
|
+
infered = n_infer.next()
|
397
|
+
self.assertIsInstance(infered, nodes.Const)
|
398
|
+
self.failUnlessEqual(infered.value, 2)
|
399
|
+
self.failUnlessRaises(StopIteration, n_infer.next)
|
400
|
+
|
401
|
+
def test_builtin_types(self):
|
402
|
+
code = '''
|
403
|
+
l = [1]
|
404
|
+
t = (2,)
|
405
|
+
d = {}
|
406
|
+
s = ''
|
407
|
+
u = u''
|
408
|
+
'''
|
409
|
+
astng = builder.string_build(code, __name__, __file__)
|
410
|
+
n = astng['l']
|
411
|
+
infered = n.infer().next()
|
412
|
+
self.assertIsInstance(infered, nodes.List)
|
413
|
+
self.assertIsInstance(infered, Instance)
|
414
|
+
self.failUnlessEqual(infered.getitem(0).value, 1)
|
415
|
+
self.assertIsInstance(infered._proxied, nodes.Class)
|
416
|
+
self.failUnlessEqual(infered._proxied.name, 'list')
|
417
|
+
self.failUnless('append' in infered._proxied.locals)
|
418
|
+
n = astng['t']
|
419
|
+
infered = n.infer().next()
|
420
|
+
self.assertIsInstance(infered, nodes.Tuple)
|
421
|
+
self.assertIsInstance(infered, Instance)
|
422
|
+
self.failUnlessEqual(infered.getitem(0).value, 2)
|
423
|
+
self.assertIsInstance(infered._proxied, nodes.Class)
|
424
|
+
self.failUnlessEqual(infered._proxied.name, 'tuple')
|
425
|
+
n = astng['d']
|
426
|
+
infered = n.infer().next()
|
427
|
+
self.assertIsInstance(infered, nodes.Dict)
|
428
|
+
self.assertIsInstance(infered, Instance)
|
429
|
+
self.assertIsInstance(infered._proxied, nodes.Class)
|
430
|
+
self.failUnlessEqual(infered._proxied.name, 'dict')
|
431
|
+
self.failUnless('get' in infered._proxied.locals)
|
432
|
+
n = astng['s']
|
433
|
+
infered = n.infer().next()
|
434
|
+
self.assertIsInstance(infered, nodes.Const)
|
435
|
+
self.assertIsInstance(infered, Instance)
|
436
|
+
self.failUnlessEqual(infered.name, 'str')
|
437
|
+
self.failUnless('lower' in infered._proxied.locals)
|
438
|
+
n = astng['u']
|
439
|
+
infered = n.infer().next()
|
440
|
+
self.assertIsInstance(infered, nodes.Const)
|
441
|
+
self.assertIsInstance(infered, Instance)
|
442
|
+
self.failUnlessEqual(infered.name, 'unicode')
|
443
|
+
self.failUnless('lower' in infered._proxied.locals)
|
444
|
+
|
445
|
+
def test_descriptor_are_callable(self):
|
446
|
+
code = '''
|
447
|
+
class A:
|
448
|
+
statm = staticmethod(open)
|
449
|
+
clsm = classmethod('whatever')
|
450
|
+
'''
|
451
|
+
astng = builder.string_build(code, __name__, __file__)
|
452
|
+
statm = astng['A'].igetattr('statm').next()
|
453
|
+
self.failUnless(statm.callable())
|
454
|
+
clsm = astng['A'].igetattr('clsm').next()
|
455
|
+
self.failUnless(clsm.callable())
|
456
|
+
|
457
|
+
def test_bt_ancestor_crash(self):
|
458
|
+
code = '''
|
459
|
+
class Warning(Warning):
|
460
|
+
pass
|
461
|
+
'''
|
462
|
+
astng = builder.string_build(code, __name__, __file__)
|
463
|
+
w = astng['Warning']
|
464
|
+
ancestors = w.ancestors()
|
465
|
+
ancestor = ancestors.next()
|
466
|
+
self.failUnlessEqual(ancestor.name, 'Warning')
|
467
|
+
self.failUnlessEqual(ancestor.root().name, 'exceptions')
|
468
|
+
ancestor = ancestors.next()
|
469
|
+
self.failUnlessEqual(ancestor.name, 'Exception')
|
470
|
+
self.failUnlessEqual(ancestor.root().name, 'exceptions')
|
471
|
+
if sys.version_info >= (2, 5):
|
472
|
+
ancestor = ancestors.next()
|
473
|
+
self.failUnlessEqual(ancestor.name, 'BaseException')
|
474
|
+
self.failUnlessEqual(ancestor.root().name, 'exceptions')
|
475
|
+
ancestor = ancestors.next()
|
476
|
+
self.failUnlessEqual(ancestor.name, 'object')
|
477
|
+
self.failUnlessEqual(ancestor.root().name, '__builtin__')
|
478
|
+
self.failUnlessRaises(StopIteration, ancestors.next)
|
479
|
+
|
480
|
+
def test_qqch(self):
|
481
|
+
code = '''
|
482
|
+
from logilab.common.modutils import load_module_from_name
|
483
|
+
xxx = load_module_from_name('__pkginfo__')
|
484
|
+
'''
|
485
|
+
astng = builder.string_build(code, __name__, __file__)
|
486
|
+
xxx = astng['xxx']
|
487
|
+
infered = list(xxx.infer())
|
488
|
+
self.failUnlessEqual(sorted([n.__class__ for n in infered]),
|
489
|
+
sorted([nodes.Const, YES.__class__]))
|
490
|
+
|
491
|
+
def test_method_argument(self):
|
492
|
+
code = '''
|
493
|
+
class ErudiEntitySchema:
|
494
|
+
"""a entity has a type, a set of subject and or object relations"""
|
495
|
+
def __init__(self, e_type, **kwargs):
|
496
|
+
kwargs['e_type'] = e_type.capitalize().encode()
|
497
|
+
|
498
|
+
def meth(self, e_type, *args, **kwargs):
|
499
|
+
kwargs['e_type'] = e_type.capitalize().encode()
|
500
|
+
print args
|
501
|
+
'''
|
502
|
+
astng = builder.string_build(code, __name__, __file__)
|
503
|
+
arg = get_name_node(astng['ErudiEntitySchema']['__init__'], 'e_type')
|
504
|
+
self.failUnlessEqual([n.__class__ for n in arg.infer()],
|
505
|
+
[YES.__class__])
|
506
|
+
arg = get_name_node(astng['ErudiEntitySchema']['__init__'], 'kwargs')
|
507
|
+
self.failUnlessEqual([n.__class__ for n in arg.infer()],
|
508
|
+
[nodes.Dict])
|
509
|
+
arg = get_name_node(astng['ErudiEntitySchema']['meth'], 'e_type')
|
510
|
+
self.failUnlessEqual([n.__class__ for n in arg.infer()],
|
511
|
+
[YES.__class__])
|
512
|
+
arg = get_name_node(astng['ErudiEntitySchema']['meth'], 'args')
|
513
|
+
self.failUnlessEqual([n.__class__ for n in arg.infer()],
|
514
|
+
[nodes.Tuple])
|
515
|
+
arg = get_name_node(astng['ErudiEntitySchema']['meth'], 'kwargs')
|
516
|
+
self.failUnlessEqual([n.__class__ for n in arg.infer()],
|
517
|
+
[nodes.Dict])
|
518
|
+
|
519
|
+
|
520
|
+
def test_tuple_then_list(self):
|
521
|
+
code = '''
|
522
|
+
def test_view(rql, vid, tags=()):
|
523
|
+
tags = list(tags)
|
524
|
+
tags.append(vid)
|
525
|
+
'''
|
526
|
+
astng = builder.string_build(code, __name__, __file__)
|
527
|
+
name = get_name_node(astng['test_view'], 'tags', -1)
|
528
|
+
it = name.infer()
|
529
|
+
tags = it.next()
|
530
|
+
self.failUnlessEqual(tags.__class__, Instance)
|
531
|
+
self.failUnlessEqual(tags._proxied.name, 'list')
|
532
|
+
self.failUnlessRaises(StopIteration, it.next)
|
533
|
+
|
534
|
+
|
535
|
+
|
536
|
+
def test_mulassign_inference(self):
|
537
|
+
code = '''
|
538
|
+
|
539
|
+
def first_word(line):
|
540
|
+
"""Return the first word of a line"""
|
541
|
+
|
542
|
+
return line.split()[0]
|
543
|
+
|
544
|
+
def last_word(line):
|
545
|
+
"""Return last word of a line"""
|
546
|
+
|
547
|
+
return line.split()[-1]
|
548
|
+
|
549
|
+
def process_line(word_pos):
|
550
|
+
"""Silly function: returns (ok, callable) based on argument.
|
551
|
+
|
552
|
+
For test purpose only.
|
553
|
+
"""
|
554
|
+
|
555
|
+
if word_pos > 0:
|
556
|
+
return (True, first_word)
|
557
|
+
elif word_pos < 0:
|
558
|
+
return (True, last_word)
|
559
|
+
else:
|
560
|
+
return (False, None)
|
561
|
+
|
562
|
+
if __name__ == '__main__':
|
563
|
+
|
564
|
+
line_number = 0
|
565
|
+
for a_line in file('test_callable.py'):
|
566
|
+
tupletest = process_line(line_number)
|
567
|
+
(ok, fct) = process_line(line_number)
|
568
|
+
if ok:
|
569
|
+
fct(a_line)
|
570
|
+
'''
|
571
|
+
astng = builder.string_build(code, __name__, __file__)
|
572
|
+
self.failUnlessEqual(len(list(astng['process_line'].infer_call_result(
|
573
|
+
None))), 3)
|
574
|
+
self.failUnlessEqual(len(list(astng['tupletest'].infer())), 3)
|
575
|
+
values = ['Function(first_word)', 'Function(last_word)', 'Const(NoneType)']
|
576
|
+
self.failUnlessEqual([str(infered)
|
577
|
+
for infered in astng['fct'].infer()], values)
|
578
|
+
|
579
|
+
def test_float_complex_ambiguity(self):
|
580
|
+
code = '''
|
581
|
+
def no_conjugate_member(magic_flag):
|
582
|
+
"""should not raise E1101 on something.conjugate"""
|
583
|
+
if magic_flag:
|
584
|
+
something = 1.0
|
585
|
+
else:
|
586
|
+
something = 1.0j
|
587
|
+
if isinstance(something, float):
|
588
|
+
return something
|
589
|
+
return something.conjugate()
|
590
|
+
'''
|
591
|
+
astng = builder.string_build(code, __name__, __file__)
|
592
|
+
self.failUnlessEqual([i.value for i in
|
593
|
+
astng['no_conjugate_member'].ilookup('something')], [1.0, 1.0j])
|
594
|
+
self.failUnlessEqual([i.value for i in
|
595
|
+
get_name_node(astng, 'something', -1).infer()], [1.0, 1.0j])
|
596
|
+
|
597
|
+
def test_lookup_cond_branches(self):
|
598
|
+
code = '''
|
599
|
+
def no_conjugate_member(magic_flag):
|
600
|
+
"""should not raise E1101 on something.conjugate"""
|
601
|
+
something = 1.0
|
602
|
+
if magic_flag:
|
603
|
+
something = 1.0j
|
604
|
+
return something.conjugate()
|
605
|
+
'''
|
606
|
+
astng = builder.string_build(code, __name__, __file__)
|
607
|
+
self.failUnlessEqual([i.value for i in
|
608
|
+
get_name_node(astng, 'something', -1).infer()], [1.0, 1.0j])
|
609
|
+
|
610
|
+
|
611
|
+
def test_simple_subscript(self):
|
612
|
+
code = '''
|
613
|
+
a = [1, 2, 3][0]
|
614
|
+
b = (1, 2, 3)[1]
|
615
|
+
c = (1, 2, 3)[-1]
|
616
|
+
d = a + b + c
|
617
|
+
print d
|
618
|
+
'''
|
619
|
+
astng = builder.string_build(code, __name__, __file__)
|
620
|
+
self.failUnlessEqual([i.value for i in
|
621
|
+
get_name_node(astng, 'a', -1).infer()], [1])
|
622
|
+
self.failUnlessEqual([i.value for i in
|
623
|
+
get_name_node(astng, 'b', -1).infer()], [2])
|
624
|
+
self.failUnlessEqual([i.value for i in
|
625
|
+
get_name_node(astng, 'c', -1).infer()], [3])
|
626
|
+
self.failUnlessEqual([i.value for i in
|
627
|
+
get_name_node(astng, 'd', -1).infer()], [6])
|
628
|
+
|
629
|
+
#def test_simple_tuple(self):
|
630
|
+
#"""test case for a simple tuple value"""
|
631
|
+
## XXX tuple inference is not implemented ...
|
632
|
+
#code = """
|
633
|
+
#a = (1,)
|
634
|
+
#b = (22,)
|
635
|
+
#some = a + b
|
636
|
+
#"""
|
637
|
+
#astng = builder.string_build(code, __name__, __file__)
|
638
|
+
#self.failUnlessEqual(astng['some'].infer.next().as_string(), "(1, 22)")
|
639
|
+
|
640
|
+
def test_simple_for(self):
|
641
|
+
code = '''
|
642
|
+
for a in [1, 2, 3]:
|
643
|
+
print a
|
644
|
+
for b,c in [(1,2), (3,4)]:
|
645
|
+
print b
|
646
|
+
print c
|
647
|
+
|
648
|
+
print [(d,e) for e,d in ([1,2], [3,4])]
|
649
|
+
'''
|
650
|
+
astng = builder.string_build(code, __name__, __file__)
|
651
|
+
self.failUnlessEqual([i.value for i in
|
652
|
+
get_name_node(astng, 'a', -1).infer()], [1, 2, 3])
|
653
|
+
self.failUnlessEqual([i.value for i in
|
654
|
+
get_name_node(astng, 'b', -1).infer()], [1, 3])
|
655
|
+
self.failUnlessEqual([i.value for i in
|
656
|
+
get_name_node(astng, 'c', -1).infer()], [2, 4])
|
657
|
+
self.failUnlessEqual([i.value for i in
|
658
|
+
get_name_node(astng, 'd', -1).infer()], [2, 4])
|
659
|
+
self.failUnlessEqual([i.value for i in
|
660
|
+
get_name_node(astng, 'e', -1).infer()], [1, 3])
|
661
|
+
|
662
|
+
|
663
|
+
def test_simple_for_genexpr(self):
|
664
|
+
if sys.version_info < (2, 4):
|
665
|
+
return
|
666
|
+
code = '''
|
667
|
+
print ((d,e) for e,d in ([1,2], [3,4]))
|
668
|
+
'''
|
669
|
+
astng = builder.string_build(code, __name__, __file__)
|
670
|
+
self.failUnlessEqual([i.value for i in
|
671
|
+
get_name_node(astng, 'd', -1).infer()], [2, 4])
|
672
|
+
self.failUnlessEqual([i.value for i in
|
673
|
+
get_name_node(astng, 'e', -1).infer()], [1, 3])
|
674
|
+
|
675
|
+
|
676
|
+
def test_builtin_help(self):
|
677
|
+
code = '''
|
678
|
+
help()
|
679
|
+
'''
|
680
|
+
# XXX failing with python > 2.3 since __builtin__.help assignment has
|
681
|
+
# been moved into a function...
|
682
|
+
astng = builder.string_build(code, __name__, __file__)
|
683
|
+
node = get_name_node(astng, 'help', -1)
|
684
|
+
infered = list(node.infer())
|
685
|
+
self.failUnlessEqual(len(infered), 1, infered)
|
686
|
+
self.assertIsInstance(infered[0], Instance)
|
687
|
+
self.failUnlessEqual(str(infered[0]),
|
688
|
+
'Instance of site._Helper')
|
689
|
+
|
690
|
+
def test_builtin_open(self):
|
691
|
+
code = '''
|
692
|
+
open("toto.txt")
|
693
|
+
'''
|
694
|
+
astng = builder.string_build(code, __name__, __file__)
|
695
|
+
node = get_name_node(astng, 'open', -1)
|
696
|
+
infered = list(node.infer())
|
697
|
+
self.failUnlessEqual(len(infered), 1)
|
698
|
+
if open is file:
|
699
|
+
# On python < 2.5 open and file are the same thing.
|
700
|
+
self.assertIsInstance(infered[0], nodes.Class)
|
701
|
+
self.failUnlessEqual(infered[0].name, 'file')
|
702
|
+
else:
|
703
|
+
# On python >= 2.5 open is a builtin function.
|
704
|
+
self.assertIsInstance(infered[0], nodes.Function)
|
705
|
+
self.failUnlessEqual(infered[0].name, 'open')
|
706
|
+
|
707
|
+
def test_callfunc_context_func(self):
|
708
|
+
code = '''
|
709
|
+
def mirror(arg=None):
|
710
|
+
return arg
|
711
|
+
|
712
|
+
un = mirror(1)
|
713
|
+
'''
|
714
|
+
astng = builder.string_build(code, __name__, __file__)
|
715
|
+
infered = list(astng.igetattr('un'))
|
716
|
+
self.failUnlessEqual(len(infered), 1)
|
717
|
+
self.assertIsInstance(infered[0], nodes.Const)
|
718
|
+
self.failUnlessEqual(infered[0].value, 1)
|
719
|
+
|
720
|
+
def test_callfunc_context_lambda(self):
|
721
|
+
code = '''
|
722
|
+
mirror = lambda x=None: x
|
723
|
+
|
724
|
+
un = mirror(1)
|
725
|
+
'''
|
726
|
+
astng = builder.string_build(code, __name__, __file__)
|
727
|
+
infered = list(astng.igetattr('mirror'))
|
728
|
+
self.failUnlessEqual(len(infered), 1)
|
729
|
+
self.assertIsInstance(infered[0], nodes.Lambda)
|
730
|
+
infered = list(astng.igetattr('un'))
|
731
|
+
self.failUnlessEqual(len(infered), 1)
|
732
|
+
self.assertIsInstance(infered[0], nodes.Const)
|
733
|
+
self.failUnlessEqual(infered[0].value, 1)
|
734
|
+
|
735
|
+
def test_factory_method(self):
|
736
|
+
if sys.version_info < (2, 4):
|
737
|
+
self.skip('this test require python >= 2.4')
|
738
|
+
code = '''
|
739
|
+
class Super(object):
|
740
|
+
@classmethod
|
741
|
+
def instance(cls):
|
742
|
+
return cls()
|
743
|
+
|
744
|
+
class Sub(Super):
|
745
|
+
def method(self):
|
746
|
+
print 'method called'
|
747
|
+
|
748
|
+
sub = Sub.instance()
|
749
|
+
'''
|
750
|
+
astng = builder.string_build(code, __name__, __file__)
|
751
|
+
infered = list(astng.igetattr('sub'))
|
752
|
+
self.failUnlessEqual(len(infered), 1)
|
753
|
+
self.assertIsInstance(infered[0], Instance)
|
754
|
+
self.failUnlessEqual(infered[0]._proxied.name, 'Sub')
|
755
|
+
|
756
|
+
|
757
|
+
def test_import_as(self):
|
758
|
+
code = '''
|
759
|
+
import os.path as osp
|
760
|
+
print osp.dirname(__file__)
|
761
|
+
|
762
|
+
from os.path import exists as e
|
763
|
+
assert e(__file__)
|
764
|
+
|
765
|
+
from new import code as make_code
|
766
|
+
print make_code
|
767
|
+
'''
|
768
|
+
astng = builder.string_build(code, __name__, __file__)
|
769
|
+
infered = list(astng.igetattr('osp'))
|
770
|
+
self.failUnlessEqual(len(infered), 1)
|
771
|
+
self.assertIsInstance(infered[0], nodes.Module)
|
772
|
+
self.failUnlessEqual(infered[0].name, 'os.path')
|
773
|
+
infered = list(astng.igetattr('e'))
|
774
|
+
self.failUnlessEqual(len(infered), 1)
|
775
|
+
self.assertIsInstance(infered[0], nodes.Function)
|
776
|
+
self.failUnlessEqual(infered[0].name, 'exists')
|
777
|
+
infered = list(astng.igetattr('make_code'))
|
778
|
+
self.failUnlessEqual(len(infered), 1)
|
779
|
+
self.assertIsInstance(infered[0], Instance)
|
780
|
+
self.failUnlessEqual(str(infered[0]), 'Instance of __builtin__.type')
|
781
|
+
|
782
|
+
def _test_const_infered(self, node, value):
|
783
|
+
infered = list(node.infer())
|
784
|
+
self.failUnlessEqual(len(infered), 1)
|
785
|
+
self.assertIsInstance(infered[0], nodes.Const)
|
786
|
+
self.failUnlessEqual(infered[0].value, value)
|
787
|
+
|
788
|
+
def test_unary_not(self):
|
789
|
+
for code in ('a = not (1,); b = not ()',
|
790
|
+
'a = not {1:2}; b = not {}'):
|
791
|
+
astng = builder.string_build(code, __name__, __file__)
|
792
|
+
self._test_const_infered(astng['a'], False)
|
793
|
+
self._test_const_infered(astng['b'], True)
|
794
|
+
|
795
|
+
def test_binary_op_int_add(self):
|
796
|
+
astng = builder.string_build('a = 1 + 2', __name__, __file__)
|
797
|
+
self._test_const_infered(astng['a'], 3)
|
798
|
+
|
799
|
+
def test_binary_op_int_sub(self):
|
800
|
+
astng = builder.string_build('a = 1 - 2', __name__, __file__)
|
801
|
+
self._test_const_infered(astng['a'], -1)
|
802
|
+
|
803
|
+
def test_binary_op_float_div(self):
|
804
|
+
astng = builder.string_build('a = 1 / 2.', __name__, __file__)
|
805
|
+
self._test_const_infered(astng['a'], 1 / 2.)
|
806
|
+
|
807
|
+
def test_binary_op_str_mul(self):
|
808
|
+
astng = builder.string_build('a = "*" * 40', __name__, __file__)
|
809
|
+
self._test_const_infered(astng['a'], "*" * 40)
|
810
|
+
|
811
|
+
def test_binary_op_bitand(self):
|
812
|
+
astng = builder.string_build('a = 23&20', __name__, __file__)
|
813
|
+
self._test_const_infered(astng['a'], 23&20)
|
814
|
+
|
815
|
+
def test_binary_op_bitor(self):
|
816
|
+
astng = builder.string_build('a = 23|8', __name__, __file__)
|
817
|
+
self._test_const_infered(astng['a'], 23|8)
|
818
|
+
|
819
|
+
def test_binary_op_bitxor(self):
|
820
|
+
astng = builder.string_build('a = 23^9', __name__, __file__)
|
821
|
+
self._test_const_infered(astng['a'], 23^9)
|
822
|
+
|
823
|
+
def test_binary_op_shiftright(self):
|
824
|
+
astng = builder.string_build('a = 23 >>1', __name__, __file__)
|
825
|
+
self._test_const_infered(astng['a'], 23>>1)
|
826
|
+
|
827
|
+
def test_binary_op_shiftleft(self):
|
828
|
+
astng = builder.string_build('a = 23 <<1', __name__, __file__)
|
829
|
+
self._test_const_infered(astng['a'], 23<<1)
|
830
|
+
|
831
|
+
|
832
|
+
def test_binary_op_list_mul(self):
|
833
|
+
for code in ('a = [[]] * 2', 'a = 2 * [[]]'):
|
834
|
+
astng = builder.string_build(code, __name__, __file__)
|
835
|
+
infered = list(astng['a'].infer())
|
836
|
+
self.failUnlessEqual(len(infered), 1)
|
837
|
+
self.assertIsInstance(infered[0], nodes.List)
|
838
|
+
self.failUnlessEqual(len(infered[0].elts), 2)
|
839
|
+
self.assertIsInstance(infered[0].elts[0], nodes.List)
|
840
|
+
self.assertIsInstance(infered[0].elts[1], nodes.List)
|
841
|
+
|
842
|
+
def test_binary_op_tuple_add(self):
|
843
|
+
astng = builder.string_build('a = (1,) + (2,)', __name__, __file__)
|
844
|
+
infered = list(astng['a'].infer())
|
845
|
+
self.failUnlessEqual(len(infered), 1)
|
846
|
+
self.assertIsInstance(infered[0], nodes.Tuple)
|
847
|
+
self.failUnlessEqual(len(infered[0].elts), 2)
|
848
|
+
self.failUnlessEqual(infered[0].elts[0].value, 1)
|
849
|
+
self.failUnlessEqual(infered[0].elts[1].value, 2)
|
850
|
+
|
851
|
+
def test_binary_op_custom_class(self):
|
852
|
+
code = '''
|
853
|
+
class myarray:
|
854
|
+
def __init__(self, array):
|
855
|
+
self.array = array
|
856
|
+
def __mul__(self, x):
|
857
|
+
return myarray([2,4,6])
|
858
|
+
def astype(self):
|
859
|
+
return "ASTYPE"
|
860
|
+
|
861
|
+
def randint(maximum):
|
862
|
+
if maximum is not None:
|
863
|
+
return myarray([1,2,3]) * 2
|
864
|
+
else:
|
865
|
+
return int(5)
|
866
|
+
|
867
|
+
x = randint(1)
|
868
|
+
'''
|
869
|
+
astng = builder.string_build(code, __name__, __file__)
|
870
|
+
infered = list(astng.igetattr('x'))
|
871
|
+
self.failUnlessEqual(len(infered), 2)
|
872
|
+
value = [str(v) for v in infered]
|
873
|
+
# The __name__ trick here makes it work when invoked directly
|
874
|
+
# (__name__ == '__main__') and through pytest (__name__ ==
|
875
|
+
# 'unittest_inference')
|
876
|
+
self.assertEquals(value, ['Instance of %s.myarray' % (__name__,),
|
877
|
+
'Instance of __builtin__.int'])
|
878
|
+
|
879
|
+
def test_nonregr_lambda_arg(self):
|
880
|
+
code = '''
|
881
|
+
def f(g = lambda: None):
|
882
|
+
g().x
|
883
|
+
'''
|
884
|
+
astng = builder.string_build(code, __name__, __file__)
|
885
|
+
callfuncnode = astng['f'].body[0].value.expr
|
886
|
+
infered = list(callfuncnode.infer())
|
887
|
+
self.failUnlessEqual(len(infered), 2, infered)
|
888
|
+
infered.remove(YES)
|
889
|
+
self.assertIsInstance(infered[0], nodes.Const)
|
890
|
+
self.failUnlessEqual(infered[0].value, None)
|
891
|
+
|
892
|
+
def test_nonregr_getitem_empty_tuple(self):
|
893
|
+
code = '''
|
894
|
+
def f(x):
|
895
|
+
a = ()[x]
|
896
|
+
'''
|
897
|
+
astng = builder.string_build(code, __name__, __file__)
|
898
|
+
infered = list(astng['f'].ilookup('a'))
|
899
|
+
self.failUnlessEqual(len(infered), 1)
|
900
|
+
self.failUnlessEqual(infered[0], YES)
|
901
|
+
|
902
|
+
def test_python25_generator_exit(self):
|
903
|
+
sys.stderr = StringIO()
|
904
|
+
data = "b = {}[str(0)+''].a"
|
905
|
+
astng = builder.string_build(data, __name__, __file__)
|
906
|
+
list(astng['b'].infer())
|
907
|
+
output = sys.stderr.getvalue()
|
908
|
+
# I have no idea how to test for this in another way...
|
909
|
+
self.failIf("RuntimeError" in output, "Exception exceptions.RuntimeError: 'generator ignored GeneratorExit' in <generator object> ignored")
|
910
|
+
sys.stderr = sys.__stderr__
|
911
|
+
|
912
|
+
def test_python25_relative_import(self):
|
913
|
+
if sys.version_info < (2, 5):
|
914
|
+
self.skip('require py >= 2.5')
|
915
|
+
data = "from ...common import date; print date"
|
916
|
+
astng = builder.string_build(data, 'logilab.astng.test.unittest_inference', __file__)
|
917
|
+
infered = get_name_node(astng, 'date').infer().next()
|
918
|
+
self.assertIsInstance(infered, nodes.Module)
|
919
|
+
self.assertEquals(infered.name, 'logilab.common.date')
|
920
|
+
|
921
|
+
def test_python25_no_relative_import(self):
|
922
|
+
if sys.version_info < (2, 5):
|
923
|
+
self.skip('require py >= 2.5')
|
924
|
+
# data = 'import unittest_lookup; print unittest_lookup'
|
925
|
+
# astng = builder.string_build(data, 'logilab.astng.test.unittest_inference', __file__)
|
926
|
+
# self.failIf(astng.absolute_import_activated())
|
927
|
+
# infered = get_name_node(astng, 'unittest_lookup').infer().next()
|
928
|
+
# self.assertIsInstance(infered, nodes.Module)
|
929
|
+
data = 'from __future__ import absolute_import; import unittest_lookup; print unittest_lookup'
|
930
|
+
astng = builder.file_build(join('regrtest_data', 'absimport.py'), 'absimport')
|
931
|
+
self.failUnless(astng.absolute_import_activated(), True)
|
932
|
+
infered = get_name_node(astng, 'import_package_subpackage_module').infer().next()
|
933
|
+
# failed to import since absolute_import is activated
|
934
|
+
self.failUnless(infered is YES)
|
935
|
+
|
936
|
+
# def test_mechanize_open(self):
|
937
|
+
# try:
|
938
|
+
# import mechanize
|
939
|
+
# except ImportError:
|
940
|
+
# self.skip('require mechanize installed')
|
941
|
+
# data = '''from mechanize import Browser
|
942
|
+
# print Browser
|
943
|
+
# b = Browser()
|
944
|
+
# print b
|
945
|
+
# '''
|
946
|
+
# astng = builder.string_build(data, __name__, __file__)
|
947
|
+
# browser = get_name_node(astng, 'Browser').infer().next()
|
948
|
+
# self.assertIsInstance(browser, nodes.Class)
|
949
|
+
# print '*'*80
|
950
|
+
# bopen = list(browser.igetattr('open'))
|
951
|
+
# self.assertEquals(len(bopen), 1)
|
952
|
+
# self.assertIsInstance(bopen[0], nodes.Function)
|
953
|
+
# self.failUnless(bopen[0].callable())
|
954
|
+
# print '*'*80
|
955
|
+
# b = get_name_node(astng, 'b').infer().next()
|
956
|
+
# self.assertIsInstance(b, Instance)
|
957
|
+
# bopen = list(b.igetattr('open'))
|
958
|
+
# self.assertEquals(len(bopen), 1)
|
959
|
+
# self.assertIsInstance(bopen[0], BoundMethod)
|
960
|
+
# self.failUnless(bopen[0].callable())
|
961
|
+
|
962
|
+
def test_property(self):
|
963
|
+
code = '''
|
964
|
+
from smtplib import SMTP
|
965
|
+
class SendMailController(object):
|
966
|
+
|
967
|
+
@property
|
968
|
+
def smtp(self):
|
969
|
+
return SMTP(mailhost, port)
|
970
|
+
|
971
|
+
@property
|
972
|
+
def me(self):
|
973
|
+
return self
|
974
|
+
|
975
|
+
print SendMailController().smtp
|
976
|
+
print SendMailController().me
|
977
|
+
'''
|
978
|
+
astng = builder.string_build(code, __name__, __file__)
|
979
|
+
self.assertEquals(astng['SendMailController']['smtp'].decoratornames(),
|
980
|
+
set(('__builtin__.property',)))
|
981
|
+
propinfered = list(astng.body[2].values[0].infer())
|
982
|
+
self.assertEquals(len(propinfered), 1)
|
983
|
+
propinfered = propinfered[0]
|
984
|
+
self.assertIsInstance(propinfered, Instance)
|
985
|
+
self.assertEquals(propinfered.name, 'SMTP')
|
986
|
+
self.assertEquals(propinfered.root().name, 'smtplib')
|
987
|
+
self.assertEquals(astng['SendMailController']['me'].decoratornames(),
|
988
|
+
set(('__builtin__.property',)))
|
989
|
+
propinfered = list(astng.body[3].values[0].infer())
|
990
|
+
self.assertEquals(len(propinfered), 1)
|
991
|
+
propinfered = propinfered[0]
|
992
|
+
self.assertIsInstance(propinfered, Instance)
|
993
|
+
self.assertEquals(propinfered.name, 'SendMailController')
|
994
|
+
self.assertEquals(propinfered.root().name, __name__)
|
995
|
+
|
996
|
+
|
997
|
+
def test_im_func_unwrap(self):
|
998
|
+
code = '''
|
999
|
+
class EnvBasedTC:
|
1000
|
+
def pactions(self):
|
1001
|
+
print "hop"
|
1002
|
+
pactions = EnvBasedTC.pactions.im_func
|
1003
|
+
print pactions
|
1004
|
+
|
1005
|
+
class EnvBasedTC2:
|
1006
|
+
pactions = EnvBasedTC.pactions.im_func
|
1007
|
+
print pactions
|
1008
|
+
|
1009
|
+
'''
|
1010
|
+
astng = builder.string_build(code, __name__, __file__)
|
1011
|
+
pactions = get_name_node(astng, 'pactions')
|
1012
|
+
infered = list(pactions.infer())
|
1013
|
+
self.assertEquals(len(infered), 1)
|
1014
|
+
self.assertIsInstance(infered[0], nodes.Function)
|
1015
|
+
pactions = get_name_node(astng['EnvBasedTC2'], 'pactions')
|
1016
|
+
infered = list(pactions.infer())
|
1017
|
+
self.assertEquals(len(infered), 1)
|
1018
|
+
self.assertIsInstance(infered[0], nodes.Function)
|
1019
|
+
|
1020
|
+
def test_augassign(self):
|
1021
|
+
code = '''
|
1022
|
+
a = 1
|
1023
|
+
a += 2
|
1024
|
+
print a
|
1025
|
+
'''
|
1026
|
+
astng = builder.string_build(code, __name__, __file__)
|
1027
|
+
infered = list(get_name_node(astng, 'a').infer())
|
1028
|
+
|
1029
|
+
self.assertEquals(len(infered), 1)
|
1030
|
+
self.assertIsInstance(infered[0], nodes.Const)
|
1031
|
+
self.assertEquals(infered[0].value, 3)
|
1032
|
+
|
1033
|
+
def test_nonregr_func_arg(self):
|
1034
|
+
code = '''
|
1035
|
+
def foo(self, bar):
|
1036
|
+
def baz():
|
1037
|
+
pass
|
1038
|
+
def qux():
|
1039
|
+
return baz
|
1040
|
+
spam = bar(None, qux)
|
1041
|
+
print spam
|
1042
|
+
'''
|
1043
|
+
astng = builder.string_build(code, __name__, __file__)
|
1044
|
+
infered = list(get_name_node(astng['foo'], 'spam').infer())
|
1045
|
+
self.assertEquals(len(infered), 1)
|
1046
|
+
self.assertIs(infered[0], YES)
|
1047
|
+
|
1048
|
+
def test_nonregr_func_global(self):
|
1049
|
+
code = '''
|
1050
|
+
active_application = None
|
1051
|
+
|
1052
|
+
def get_active_application():
|
1053
|
+
global active_application
|
1054
|
+
return active_application
|
1055
|
+
|
1056
|
+
class Application(object):
|
1057
|
+
def __init__(self):
|
1058
|
+
global active_application
|
1059
|
+
active_application = self
|
1060
|
+
|
1061
|
+
class DataManager(object):
|
1062
|
+
def __init__(self, app=None):
|
1063
|
+
self.app = get_active_application()
|
1064
|
+
def test(self):
|
1065
|
+
p = self.app
|
1066
|
+
print p
|
1067
|
+
'''
|
1068
|
+
astng = builder.string_build(code, __name__, __file__)
|
1069
|
+
infered = list(Instance(astng['DataManager']).igetattr('app'))
|
1070
|
+
self.assertEquals(len(infered), 2, infered) # None / Instance(Application)
|
1071
|
+
infered = list(get_name_node(astng['DataManager']['test'], 'p').infer())
|
1072
|
+
self.assertEquals(len(infered), 2, infered)
|
1073
|
+
for node in infered:
|
1074
|
+
if isinstance(node, Instance) and node.name == 'Application':
|
1075
|
+
break
|
1076
|
+
else:
|
1077
|
+
self.fail('expected to find an instance of Application in %s' % infered)
|
1078
|
+
|
1079
|
+
def test_list_inference(self):
|
1080
|
+
"""#20464"""
|
1081
|
+
code = '''
|
1082
|
+
import optparse
|
1083
|
+
|
1084
|
+
A = []
|
1085
|
+
B = []
|
1086
|
+
|
1087
|
+
def test():
|
1088
|
+
xyz = [
|
1089
|
+
"foobar=%s" % options.ca,
|
1090
|
+
] + A + B
|
1091
|
+
|
1092
|
+
if options.bind is not None:
|
1093
|
+
xyz.append("bind=%s" % options.bind)
|
1094
|
+
return xyz
|
1095
|
+
|
1096
|
+
def main():
|
1097
|
+
global options
|
1098
|
+
|
1099
|
+
parser = optparse.OptionParser()
|
1100
|
+
(options, args) = parser.parse_args()
|
1101
|
+
|
1102
|
+
Z = test()
|
1103
|
+
'''
|
1104
|
+
astng = builder.string_build(code, __name__, __file__)
|
1105
|
+
infered = list(astng['Z'].infer())
|
1106
|
+
self.assertEquals(len(infered), 1, infered)
|
1107
|
+
self.assertIsInstance(infered[0], Instance)
|
1108
|
+
self.assertIsInstance(infered[0]._proxied, nodes.Class)
|
1109
|
+
self.assertEquals(infered[0]._proxied.name, 'list')
|
1110
|
+
|
1111
|
+
if __name__ == '__main__':
|
1112
|
+
unittest_main()
|