Ramblings

March 8, 2008

Interactive web2py testing

Filed under: behavior driven development, dev, python, test driven development, web2py — michaelangela @ 11:00 am

web2py is a great web development app. It’s under heavy development and the creator answers tons of questions making many updates to the core code in very short order.

In the quest for TDD, now BDD, I wanted to be able to get an interactive session going in iPython. There are some things I had to do to the iPython ipythonrc file, like adding the web2py to the sys.path variable, but it seems to be working.

There are some gotchas. When you import something with iPython, it runs it, or so it seems. I’m still a newbie at this though so I am most likely wrong!

But, this works for my particular setup. In an iPython session:

In [62]: %doctest_mode
*** Pasting of code with “>>>” or “…” has been enabled.
Exception reporting mode: Plain
Doctest mode is: ON

>>> from gluon.globals import Request
>>> from applications.cookbook.models import db
>>> r=Request()
>>> cb=db.Cookbook(r)
>>> cb.ge #auto completion in the shell
cb.getcategory cb.getrecipe
>>> cb.getcategory(1)['name']
‘dinner’
>>>

So I now have interactive access to the database which is what I want for testing. And I can get doctests straight away as well. That’s pretty cool. This gives shell experimentation similar to Django’s shell app admin. As you can see there is some auto completion going on there as well. Neat!

Oh yes. In my ipythonrc.ini I have the standard

import_mod sys os

and added

execute sys.path.append(‘C:\\path\\to\\web2py’)

and in that session I also did a

os.chdir(‘C:\\path\\to\\web2py’)

Perhaps I can/will make different profiles for different tests but this is the main thing I’ll be testing. I’ll just put those things into the ipythonrc file. I thought I wouldn’t need the sys.path.append AND the os.chdir but both are needed. sys.path.append allows the import, and os.chdir allows autocompletion in the shell.

ScribeFire seems to be causing trouble with the code prompts though. :-( Trying an edit in Zoundry’s Raven now… and it worked! :-)

Behavior Driven Programming (BDD) can be done in TDD setups

Filed under: dev — michaelangela @ 10:27 am

OK. So. Basically you can do BDD within TDD, but the language is quite different. For many languages that’s really true. Doctests in python are not so bad as this page describes:

Behavior Driven Programming

And then there is the reference to py.test which is the TDD system I’d actually like to use.

So the trick is to think differently. It’s true what they say: the language changes how you think. Ask anyone bilingual enough who is honest… at least it’s true for me. English and Chinese changes how you approach communication.

And from the following we have a good point

Behaviour-Driven Development Explored – Maugrim The Reaper’s Blog

Language is the big barrier. Though one can perform BDD in a testing-centric UT library, it requires an amount of skill to translate between the test oriented language and organisation of Unit Testing to the purely behaviour driven language required by BDD. It’s like viewing something in Dutch, and needing to constantly translate it into English (unless you are a native speaker already). It’s difficult. So difficult, that TDD is itself by relation difficult to fully grasp and perform well.

As close to test driven development as I want to get…?

Filed under: dev — michaelangela @ 9:52 am

This seems, so far, to be what I have been looking for. I don’t want to write tests for every little thing without knowing why I am doing it. I can do it because “I am supposed to”, but actually having an approach to this will be very helpful.

On a side note, ScribeFire allows you to begin a post and if you want to quote something from the page you are blogging, it’ll just add it to the current post you are working on. I think older versions (i.e. more than a year ago!) would blow away the post you had already typed up. This is good. It feels faster, too.

DanNorth.net » Introducing BDD

I had a problem. While using and teaching agile practices like test-driven development (TDD) on projects in different environments, I kept coming across the same confusion and misunderstandings. Programmers wanted to know where to start, what to test and what not to test, how much to test in one go, what to call their tests, and how to understand why a test fails.

Instead of TDD, BDD

Filed under: dev — michaelangela @ 9:49 am

I want to do test driven development. I have been hitting walls since I have started looking into it and asking questions. This is starting to answer it though…

Behavior Driven Development – Wikipedia, the free encyclopedia

Performancing now Scribfire

Filed under: Uncategorized — michaelangela @ 9:48 am

So I am getting back into blogging. It’s been a while. A long while. Partially because it’s been a major learning session for say… oh… the last year. :-) But my notes and bits and pieces really can only be best tracked on the web. But I had a problem. I used to use Performancing for blogging, and then Zoundry. There was always the “Blog This Page” feature. Working with Zoundry’s new Raven I missed that ability. Of course I forgot I had a toolbar already in Firefox that I disabled. Maybe it’ll work. Anyway, I reinstalled ScribeFire and all my previous settings were here so, there will be more posts a comin’ as there is definitely a lof learnin’.

ScribeFire :: Firefox Add-ons

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 25 other followers