diff --git a/Makefile.pyrex b/Makefile.pyrex index bcdab76..5b91051 100644 --- a/Makefile.pyrex +++ b/Makefile.pyrex @@ -35,10 +35,15 @@ PYTHON_INCLUDES=-I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION) LINK_FLAGS=-fPIC -Llib -ltstools -lm -lpython$(PYTHON_VERSION) -.PHONY: all -all: +.PHONY: all setup test +all: setup test + +setup: python Setup.py build_ext --inplace +test: setup + ./rundoctest.py + # I've never been able to figure out how to stop this grumbling about # a circular dependency. Yet it seems to do the right thing. ##%.pyx.c: %.pyx diff --git a/rundoctest.py b/rundoctest.py new file mode 100755 index 0000000..2e2a6b7 --- /dev/null +++ b/rundoctest.py @@ -0,0 +1,53 @@ +#! /usr/bin/env python +"""Run the doctest on a text file + + Usage: doctext.py [file] + +[file] defaults to ``test.txt`` +""" + +import sys +import doctest + +def main(): + args = sys.argv[1:] + filename = None + verbose = False + + for word in args: + if word in ("-v", "-verbose"): + verbose = True + elif word in ("-h", "-help", "/?", "/help", "--help"): + print __doc__ + return + else: + if filename: + print "Filename '%s' already specified"%filename + return + else: + filename = word + + if not filename: + filename = "test.txt" + + try: + (failures,tests) = doctest.testfile(filename,verbose=verbose) + if failures > 0: + print doctest.DIVIDER + except: + # e.g., Python 2.2 + tester = doctest.Tester(globs={},verbose=verbose) + f = open(filename) + (failures,tests) = tester.runstring(f.read(),filename) + f.close() + if failures > 0: + print "*"*65 + + testword = "test" + if tests != 1: testword = "tests" + failword = "failure" + if failures != 1: failword = "failures" + print "File %s: %d %s, %d %s"%(filename,tests,testword,failures,failword) + +if __name__ == "__main__": + main() diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..51845b7 --- /dev/null +++ b/test.txt @@ -0,0 +1,26 @@ +Some tests for the Python binding of the TS tools +================================================= + +It's difficult to find example data files that are generally available. For +the moment, I'm going to use a file I have locally, and unfortunately others +will have to manage without. This is still better than no testing... + + >>> test_es_file = '/Users/tibs/sw/tstools/data/aladdin.es' + +First, check we've got the basics working: + + >>> from tstools import ESStream + >>> stream = ESStream(test_es_file) + +The filename is available as a "readonly" value: + + >>> stream.filename + '/Users/tibs/sw/tstools/data/aladdin.es' + + +// Local Variables: +// tab-width: 8 +// indent-tabs-mode: nil +// c-basic-offset: 2 +// End: +// vim: set filetype=rst tabstop=8 shiftwidth=2 expandtab: diff --git a/tstools.pyx b/tstools.pyx index d443915..0bd3c33 100644 --- a/tstools.pyx +++ b/tstools.pyx @@ -68,8 +68,6 @@ cdef class ESStream: # try the recommended route def __cinit__(self,filename,*args,**kwargs): retval = open_elementary_stream(filename,&self.stream) - print 'retval',retval - print 'stream %d'%self.stream if retval != 0: raise TSToolsException,'Error opening ES file %s'%filename