Pythoscope, the unit test generator

r196 fails to create pickle

Reported by Kent Tenney on 2008-09-28
6
Affects Status Importance Assigned to Milestone
Pythoscope
Medium
Michal Kwiatkowski

Bug Description

r196 worked on an old pickle, but failed to create a new one.

Traceback (most recent call last):
  File "/usr/bin/pythoscope", line 8, in <module>
    load_entry_point('pythoscope==0.3', 'console_scripts', 'pythoscope')()
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/__init__.py", line 155, in main
    generate_tests(args, force, template)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/__init__.py", line 94, in generate_tests
    inspect_project(project)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/inspector/__init__.py", line 10, in inspect_project
    updates = add_and_update_modules(project) + add_and_update_points_of_entry(project)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/inspector/__init__.py", line 34, in add_and_update_modules
    static.inspect_module(project, modpath)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/inspector/static.py", line 111, in inspect_module
    return inspect_code(project, path, read_file_contents(path))
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/inspector/static.py", line 118, in inspect_code
    visitor = descend(tree, ModuleVisitor)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 55, in descend
    visitor.visit(tree)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 227, in visit
    self.visit_node(tree)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 241, in visit_node
    getattr(self, method)(results)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 263, in _visit_all
    self.visit(results['nodes'])
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 230, in visit
    self.visit(subtree)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 227, in visit
    self.visit_node(tree)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 241, in visit_node
    getattr(self, method)(results)
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/astvisitor.py", line 273, in _visit_function
    body=results['body'])
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/inspector/static.py", line 80, in visit_function
    if is_generator_definition(body):
  File "/usr/lib/python2.5/site-packages/pythoscope-0.3-py2.5.egg/pythoscope/inspector/static.py", line 56, in is_generator_definition
    return compile(unindent(str(code)), '', 'single').co_consts[0].co_flags & 0x20 != 0

Related branches

Michal Kwiatkowski (ruby) wrote :

Sorry for that, I'm in the middle of implementing generators support. I'll get that fixed soon.

Changed in pythoscope:
assignee: nobody → ruby
importance: Undecided → Medium
milestone: none → 0.3.1-dynamic-analysis-fixes
status: New → Confirmed
Michal Kwiatkowski (ruby) wrote :

I have a problem reproducing this bug. I tried both Python 2.5.1 and 2.5.2 on different modules, with functions with comments, docstrings, or without docstrings and still can't get Pythoscope to fail. Could you narrow the problem down for me? To debug the problem please add the following line:

    print ">>>%r<<<" % unindent(str(code))

Into is_generator_defintion() function in pythoscope/inspector/static.py, right after the try keyword, and before the return line with compile. Then run pythoscope and report the last line of output before the exception. If the code is confidential, please strip it from anything you feel is irrelevant to the issue.

Thank you!

Download full text (17.8 KiB)

Michal,

The traceback details have changed with r198.
The traceback follows the print you suggested.

This results from running
$ pythoscope gnome/gnutility.py
from the root of

$ bzr branch lp:~ktenney/+junk/docubi
(r56)

============================================================

>>>"def grab(args):\n #logging.debug('entering grab()')\n grabber = Grabber(args)\n #logging.debug('we have grabber')\n grabber.run()\n #logging.debug('leaving grab()')\n getim(args[1])\n\n"<<<
>>>'def getim(subtext):\n """Wrapper for Grabber.do_getim():\n copies ReST directives for last grab to the clipboard\n\n >>> from docubi.image import grabber; sssh = reload(grabber)\n >>> grabber.getim(\'hello\')\n >>>\n\n If you now paste, you should see domething like:\n\n.. |subtext| image:: /home/ktenney/work/docubi/chunks/image/8b13a8de-80f7-11dd-b3bf-001d92bbeeeb.png\n :align: middle\n\n """\n\n from docubi.image import grabber\n from gtk import Clipboard\n\n grabber = grabber.Grabber([\'grab\'])\n fname = grabber.get_ordered_files(1)[0]\n grabber.from_file(fname)\n text = grabber.do_getim(subtext)\n cb = Clipboard()\n cb.set_text(text)\n cb.store()\n\n'<<<
>>>'def rename_data(directory, extension, newname):\n """Utility to change the name of the data dictionary in a set of pngs.\n\n >>> from docubi.image.grabber import rename_data\n >>> rename_data(\'/home/ktenney/work/docubi/images/grab\', \'png\', \'\')\n >>>\n """\n\n import os\n import annotate\n\n fnames = os.listdir(directory)\n print fnames\n for fname in fnames:\n if fname.endswith(extension):\n try:\n pngdata = annotate.get_tEXt(fname)\n print pngdata\n\n except:\n pass\n\n'<<<
>>>'\ndef frames1():\n photo = \'test.jpg\'\n miter = imageframe.ImageFrame(001\n , width=50\n , size=(700,550)\n , outsidecolor=\'#ffffff\' #"#cc6633"\n , insidecolor="#546c1b"\n , cornerstyle="miter"\n , style="pattern"\n , savepath=\'.\'\n , content=photo\n )\n\n # round = ImageFrame(insidecolor = \'#99cccc\', outsidecolor=\'#ffccff\', cornerstyle = \'round\', style = \'pattern\')\n\n miter.save()\n\n bevel = imageframe.ImageFrame(002\n , width=50\n , size=(700,550)\n , outsidecolor="#eb2a61"\n , insidecolor="#181717"\n , cornerstyle="bevel"\n , style="pattern"\n , savepath=\'.\'\n , content=photo\n )\n bevel.save()\n\n'<<<
>>>"\ndef annograb(command, filename):\n\n # run the command, then call 'convert x:' to initiate a screen grab\n subprocess.call(command)\n cmdline = ['convert', 'x:', filename]\n subprocess.call(cmdline)\n # subprocess.Popen(cmdline)\n # simple command lines tend to be strings, more complex are list...

Michal Kwiatkowski (ruby) wrote :

The problem was with functions that had an argument with a default value. Fixed in r202. Thanks for help in catching this bug!

Changed in pythoscope:
status: Confirmed → Fix Committed
Michal Kwiatkowski (ruby) wrote :

Fix released in 0.3.1.

Changed in pythoscope:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers