[peppers@gmail.com: [twill] Capturing Error Output/Nicely]

1 view
Skip to first unread message

C. Titus Brown

unread,
Mar 30, 2009, 4:07:38 PM3/30/09
to twill-dev
----- Forwarded message from Terry Peppers <pep...@gmail.com> -----

X-Original-To: ti...@caltech.edu
Date: Thu, 27 Apr 2006 09:58:18 -0500
From: Terry Peppers <pep...@gmail.com>
To: tw...@lists.idyll.org
Subject: [twill] Capturing Error Output/Nicely

I think Titus knows that I really enjoy using Twill. And things are heating
up here @ work so that we'll end up using it more. But I think one of my
personal hangups with it is trying to track down errors that occur in our
application using Twill's 'show' command. I don't know about anyone else,
but my eyes just glaze over when I look @ HTML in a terminal. So I got to
thinking, isn't there a better way to do this?

Couldn't I write something in my Python scripts that could take a failed
assert, output Twill's 'show', Tidy it up and then pass it to Element Tree
or some other parser and output things that might be relevant to me? Maybe
the page title or some blocks of text or maybe error messages are passed in
a <div> block that has a name of 'error.'

Just thinking out loud, and something I'd like to see if others in the Twill
community are already doing.

_______________________________________________
twill mailing list
tw...@lists.idyll.org
http://lists.idyll.org/listinfo/twill


----- End forwarded message -----

--
C. Titus Brown, c...@msu.edu

C. Titus Brown

unread,
Mar 30, 2009, 4:07:46 PM3/30/09
to twill-dev
----- Forwarded message from Stephen Thorne <ste...@netboxblue.com> -----

X-Original-To: ti...@caltech.edu
Date: Fri, 28 Apr 2006 08:12:45 +1000
From: Stephen Thorne <ste...@netboxblue.com>
To: Terry Peppers <pep...@gmail.com>, tw...@lists.idyll.org
Subject: Re: [twill] Capturing Error Output/Nicely

Terry Peppers wrote:
> I think Titus knows that I really enjoy using Twill. And things are
> heating up here @ work so that we'll end up using it more. But I think
> one of my personal hangups with it is trying to track down errors that
> occur in our application using Twill's 'show' command. I don't know
> about anyone else, but my eyes just glaze over when I look @ HTML in a
> terminal. So I got to thinking, isn't there a better way to do this?
>
> Couldn't I write something in my Python scripts that could take a failed
> assert, output Twill's 'show', Tidy it up and then pass it to Element
> Tree or some other parser and output things that might be relevant to
> me? Maybe the page title or some blocks of text or maybe error messages
> are passed in a <div> block that has a name of 'error.'
>
> Just thinking out loud, and something I'd like to see if others in the
> Twill community are already doing.

Interesting. Hows this?

test_showstuff.twill:

extend_with showstuff
go http://shiny.thorne.id.au/shiny/
tag title
tag_by_id div footer
tags_by_class div post

showstuff.py:

from twill.commands import get_browser
from BeautifulSoup import BeautifulSoup

def textify(node, pre=0):
if isinstance(node, (str, unicode)):
if pre:
return node.strip() + '\n'
else:
return node.strip()

strs = []

for n in node:
strs.append(textify(n, pre=(pre or node.name == 'pre')))

if node.name in ('br', 'p', 'div'):
return ' '.join(strs).strip() + '\n'
else:
return ' '.join(strs).strip()

def get_soup():
return BeautifulSoup(get_browser().get_html())

def tag_by_id(tag, xmlid):
soup = get_soup()
print textify(soup.first('div',{'id':xmlid}))

def tags_by_class(tag, name):
soup = get_soup()
for tag in soup(tag, {'class':name}):
print textify(tag)

def tag(tag):
soup = get_soup()
print textify(soup.first(tag))

__all__ = ['tags_by_class', 'tag_by_id', 'tag']


--
Regards,
Stephen Thorne
Development Engineer

Scanned by the NetBox from NetBox Blue
(http://netboxblue.com/)

Reply all
Reply to author
Forward
0 new messages