• Stars
    star
    147
  • Rank 249,871 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 14 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python auto testing tool.

Overview

sniffer is a autotest tool for Python using the nosetest library.

NEW: sniffer can now be customize to run anything, see 'Advanced Usage'.

Sniffer will automatically re-run tests if your code changes. And with another third-party library (see below), the CPU usage of file system monitoring is reduced in comparison to pure-python solutions. However, sniffer will still work without any of those libraries.

Looking for maintainers

I (@jeffh) am looking for a new maintainer to carry on this project to new heights. I'm currently leaving this project on maintance mode (respond to issues, merge pull requests), but I'm not dedicating most of my free time towards this project.

Contact me on twitter (@jeffhui) or via email if you're interested in taking over the helm of this project.

Usage

To install:

pip install sniffer

Simply run sniffer in your project directory.

You can use sniffer --help for options And like autonose, you can pass the nose arguments with -x prefix: -x--with-doctest or -x--config.

The problem with autonose, is that the autodetect can be slow to detect changes. This is due to the pure python implementation - manually walking through the file system to see what's changed [1]. Although the default install of sniffer shares the same problem, installing a third-party library can help fix the problem. The library is dependent on your operating system:

  • If you use Linux, you'll need to install pyinotify.
  • If you use Windows, you'll need to install pywin32.
  • If you use Mac OS X 10.5+ (Leopard), you'll need to install MacFSEvents.

If you want support for other notification systems, you can install:

[1]This has been resolved in subsequent autonose versions, using watchdog.

Advanced Usage

Don't want to run nose? You can do whatever you really want. Create a scent.py file in your current working directory. Here's an example of what you can do so far:

from sniffer.api import * # import the really small API
import os, termstyle

# you can customize the pass/fail colors like this
pass_fg_color = termstyle.green
pass_bg_color = termstyle.bg_default
fail_fg_color = termstyle.red
fail_bg_color = termstyle.bg_default

# All lists in this variable will be under surveillance for changes.
watch_paths = ['.', 'tests/']

# this gets invoked on every file that gets changed in the directory. Return
# True to invoke any runnable functions, False otherwise.
#
# This fires runnables only if files ending with .py extension and not prefixed
# with a period.
@file_validator
def py_files(filename):
    return filename.endswith('.py') and not os.path.basename(filename).startswith('.')

# This gets invoked for verification. This is ideal for running tests of some sort.
# For anything you want to get constantly reloaded, do an import in the function.
#
# sys.argv[0] and any arguments passed via -x prefix will be sent to this function as
# it's arguments. The function should return logically True if the validation passed
# and logicially False if it fails.
#
# This example simply runs nose.
@runnable
def execute_nose(*args):
    import nose
    return nose.run(argv=list(args))

And that's the basic case. Nothing too fancy shmanshe. You can have multiple file_validator and runnable decorators if you want.

There is also support for selecting a runnable function by file validator. Useful if you want to run nose for Python files, mocha for JavaScript files, and csslint for CSS. Or any other combination you can come up with. For example:

# Here we instruct the 'python_tests' runnable to be kicked off
# when a .py file is changed
@select_runnable('python_tests')
@file_validator
def py_files(filename):
    return filename.endswith('.py') and not os.path.basename(filename).startswith('.')


# Here we instruct the 'javascript_tests' runnable to be kicked off
# when a .js file is changed
@select_runnable('javascript_tests')
@file_validator
def js_files(filename):
    return filename.endswith('.js') and not os.path.basename(filename).startswith('.')


@runnable
def python_tests(*args):
    import nose
    return nose.run(argv=list(args))


@runnable
def javascript_tests(*args):
    command = "mocha tests/js-tests.js"
    return call(command, shell=True) == 0

This will run the nose for modifications to Python files and mocha when JavaScript files are changed.

Other Uses

Running with Other Test Frameworks

If you want to run another unit testing framework, you can do so by overriding sniffer.Sniffer, which is the class that handles running tests, or whatever you want. Specifically, you'll want to override the run, method to configure what you need to be done.

The property, test_args, are arguments gathered through --config=blah and -x.* configuration options. You should perform you imports inside the function instead of outside, to let the class reload the test framework (and reduce possibilities of multiple-run bugs).

After subclassing, set sniffer_instance parameter to your custom class when calling run or main.

Current Issues

For linux, there is an exception that is sometimes thrown when terminating.

Currently the program only looks for changes in the current working directory. This isn't the best solution: it doesn't understand how changes to your source code affects it.

More Repositories

1

Fox

Property Based Testing Library for Objective-C and Swift. QuickCheck for Apple's Platforms.
Objective-C
624
star
2

CV-Image-Quality-Analysis

CompVis Final Project (In 2-weeks) to try and identify high-quality images
Python
86
star
3

TestingInSwift

A sample project of tests in Swift
Swift
70
star
4

YACS

The useable online course scheduler.
Python
25
star
5

Hydrant

A simple data mapper / object serializer for objective-c
Objective-C
18
star
6

JKVValue

A simple Value Object implementation.
Objective-C
17
star
7

describe

An experimental Python BDD tool.
Python
14
star
8

Seafood

A salt deployment project. Used for YACS and OSX deployments.
Scheme
11
star
9

Robot

[Expired] An experimental reliable, fast UIKit test driver
9
star
10

SnorlaxSamples

Example projects that integrate with Snorlax. Supplementary material for the supplementary material
Swift
7
star
11

Tailor

BDD in Swift - Alpha
Swift
6
star
12

clj-blog

A simple blog application built on top of the compojure framework.
Clojure
5
star
13

rpi-bakery

A simple raspberry-pi fabric-based setup script.
Python
5
star
14

QNATs

Quick & Nimble Acceptance Tests
Swift
4
star
15

check.statem

Facilities for generating test programs using state machines.
Clojure
4
star
16

jquery.blank

Provides a default text for input boxes like me.com.
JavaScript
3
star
17

pyconstraints

A simple constraints satisfaction problem solver. Used for YACS.
Python
3
star
18

dotfiles

Configuration files for unix-like software.
Vim Script
3
star
19

ParsingJSON

Source Code to the Blog Series
C++
3
star
20

clj-mongodb

A light-weight wrapper to the MongoDB java driver.
Clojure
3
star
21

InspectorGadget

An easy wrapper around the objective-c runtime to do class reflection.
Objective-C
3
star
22

workflow

Data Machines
Clojure
2
star
23

python-fever

A simple python wrapper to the fever API.
Python
2
star
24

jquery-write

A simple WYSIWYG editor in jQuery.
JavaScript
2
star
25

dataflow

Clojure
2
star
26

mc

A simple minecraft client written in google go.
Go
2
star
27

MapLauncher

A very simple OSX Map Launcher for StarCraft II. (Just to learn cocoa & xcode 4).
Objective-C
1
star
28

jQuery.DataVizChallenge

A jQuery library that supports fetching data for datavizchallenge.org.
JavaScript
1
star
29

djangoticket-sample

The source code to the screencast. Updated for Django 1.2+
Python
1
star
30

blog

This person on the internet, he made a blog.
Go
1
star
31

mith

Exploration: Clojurescript bindings to Mithril.js
Clojure
1
star
32

rpi_courses

RPI Course Parsing Library. Extracted from YACS.
Python
1
star