Setting up agile development with Python/Komodo (part 1)

This will be a series of tutorials showing how to set up for agile development in the Komodo Edit environment. By the end of the series, we will have our Komodo project set up with the following:

  • Automated unit testing via hot key
  • Automated build cycle, that:
    1. Runs unit tests (nose)
    2. Builds an executable (py2exe)
    3. Builds an installer (Inno Setup)
    4. Automatically installs the application (pywinauto)
    5. Runs function tests (pywinauto)
    6. Builds API documentation (epydoc)
    7. Commits all changes to our source control management system (Mercurial)

The tutorials assume use of Komodo Edit on Windows, but some of the components (nose/epydoc/Mercurial) could be used on any platform. The final code after completing the tutorial can be found here.

In part 1, we're going to set up our project to perform automated unit testing, add another convenience command ("run current script"), and get our automated build cycle started, with just the unit tests for now.

OK, let's get started. I'll assume you've already installed Komodo Edit and nose. Make sure that your PATH environment variable has "c:\python2x\scripts\" in it so you can run nosetests from the command line.

First, create a new command in the toolbox to automatically run your unit tests. Set it up as follows:

Also give it an appropriate key binding. I prefer F7 (yeah, I'm a fallback from Visual Studio).

Now we'll create a little project to test this out. Create a project in a new folder, and add a file named test_module.py:

Here's the file code:

#coding: UTF8
"""
Unit test the module
"
""

def test_module():
    assert False

Run your unit tests using F7 (or whatever shortcut you picked), and make sure you get a failed test. Next, change the code as follows:

#coding: UTF8
"""
Unit test the module
"
""

from nose.tools import raises

@raises(AssertionError)
def test_module():
    assert False

Run it, and make sure you get 1 test, passed.

.
———————————————————————-
Ran 1 test in 0.000s

OK

OK, we're in business! Now let's just get our automated build script started. Add another file to your project, build.py, as follows:

#coding: UTF8
"""
Automated build for project
"
""

import os
import subprocess

def run_command(command):
    """Runs the command line, asserts success"""

    proc = subprocess.Popen(command,
                            shell=True,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE
                           )

    for line in proc.stdout:
        print line.strip()

    for line in proc.stderr:
        print line.strip()

    assert not proc.returncode

def build():
    """Performs the automated build"""

    curr_dir = os.path.dirname(__file__)
    os.chdir(curr_dir)

    # Unit tests
    run_command('nosetests -w "%s"' % curr_dir)

if __name__ == "__main__":
    build()

Create another command in the toolbox, this time to run the current file. Set the command to python "%F" (I like setting the key binding to F5…). Run it, and make sure it works. Note that our build process is set to bail if any link in the chain fails (by asserting the return code).

This concludes the first part of the series. In the next part, we'll set up the automatic build of our executable and setup file.

3 comments to Setting up agile development with Python/Komodo (part 1)

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>