Next / Previous / Contents / Shipman's homepage

22.3. treetest: Test driver for BirdNoteTree

This script exercises the BirdNoteTree class, including retrieving notes limited by date and season. The root directory for the notes tree is specified as a command line option.

treetest
#!/usr/bin/env python
#================================================================
# treetest:  Exercise class BirdNoteTree
#----------------------------------------------------------------
# Command line options:
#   treetest ROOTDIR
# where ROOTDIR is the directory containing the notes tree.
#----------------------------------------------------------------

#================================================================
# Imports
#----------------------------------------------------------------

import sys
import datetime
from txny import Txny
from birdnotes import *

#================================================================
# Manifest constants
#----------------------------------------------------------------

#================================================================
# Functions and classes
#----------------------------------------------------------------


# - - -   m a i n

def main():
    """
    """
    argList = sys.argv[1:]
    if len(argList) != 1:
        print >>sys.stderr, "*** Usage: %s NOTESDIR" % sys.argv[0]
        raise SystemExit
    txny = Txny()
    tree = BirdNoteTree(txny, argList[0])

    print "=== Limited year test"
    start = datetime.date(1977, 8, 1)
    end = datetime.date(1978,2,28)
    for monthSet in tree.genMonths(start, end):
        report(monthSet)

    print "\n\n=== Spring season test"
    start = datetime.date(1900, 3, 31)
    end = datetime.date(1886, 5, 1)
    for monthSet in tree.genMonths(startSeason=start, endSeason=end):
        report(monthSet)

    print "\n\n=== All months"
    for monthSet in tree.genMonths():
        report(monthSet)
    print

def report(monthSet):
    '''Show something from the monthSet
    '''
    print monthSet.period,
    sys.stdout.flush()

#================================================================
# Epilogue
#----------------------------------------------------------------

if __name__ == "__main__":
    main()