Giter Club home page Giter Club logo

sniffer's Introduction

Overview

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

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.

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: -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. 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.

As a word of warning, Windows and OSX libraries are untested as of now. This is because I haven't gotten around to testing in Windows, and I don't have a Mac :(.

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_cls parameter to your custom class when calling run or main.

Using the FileSystem monitoring code

If you simply want to use the file system monitor code, import sniffer.Scanner. Behind the scenes, the library will figure out what libraries are available to use and which monitor technique to use.

Right now, this is lacking some documentation, but here's a small example.

Creating the scanner is simple:

from sniffer import Scanner

paths = ('/path/to/watch/', '/another/path')
scanner = Scanner(paths)

Here we pass a tuple of paths to monitor. Now we need to get notification when events occur:

# when file is created
scanner.observe('created', lambda path: print "Created", path)

# when file is modified
scanner.observe('modified', lambda path: print "Modified", path)

# when file is deleted
scanner.observe('deleted', lambda path: print "Deleted", path)

# when scanner.loop() is called
scanner.observe('init',    lambda: print "Scanner started listening.")

In addition, we can use the same function to listen to multiple events:

# listen to multiple events
scanner.observe(('created', 'modified', 'deleted'), lambda path: "Triggered:", path)

Finally, we start our blocking loop:

# blocks
scanner.loop()

Current Issues

Being relatively new, there are bound to be bugs. Most notable is third-party libraries. Only the Linux install was tested (being in Ubuntu), so Windows & OSX implementations were done without testing. Patches are welcomed though :)

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.

sniffer's People

Stargazers

Stuart Grimshaw avatar

Watchers

Stuart Grimshaw avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.