preprocess-1.1.0+ds.orig/0000755000000000000000000000000011573617731013750 5ustar rootrootpreprocess-1.1.0+ds.orig/PKG-INFO0000644000000000000000000000300111130451342015016 0ustar rootrootMetadata-Version: 1.0 Name: preprocess Version: 1.1.0 Summary: preprocess: a multi-language preprocessor Home-page: http://code.google.com/p/preprocess/ Author: Trent Mick Author-email: trentm@gmail.com License: http://www.opensource.org/licenses/mit-license.php Description: There are millions of templating systems out there (most of them developed for the web). This isn't one of those, though it does share some basics: a markup syntax for templates that are processed to give resultant text output. The main difference with `preprocess.py` is that its syntax is hidden in comments (whatever the syntax for comments maybe in the target filetype) so that the file can still have valid syntax. A comparison with the C preprocessor is more apt. `preprocess.py` is targetted at build systems that deal with many types of files. Languages for which it works include: C++, Python, Perl, Tcl, XML, JavaScript, CSS, IDL, TeX, Fortran, PHP, Java, Shell scripts (Bash, CSH, etc.) and C#. Preprocess is usable both as a command line app and as a Python module. Platform: any Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Operating System :: OS Independent Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Text Processing :: Filters preprocess-1.1.0+ds.orig/BUGS.txt0000644000000000000000000000114711120666004015235 0ustar rootroot- Id: 1 Status: Fixed Title: Nested #if-blocks will not be properly handled. Test-Case: test_nested_bug1.py Description: In the following code: #if 0 #if 1 foo #endif #endif the "foo" line _will_ get printed, even though it should not. - Id: 2 Status: Open Title: Substitution (when turned on via -s) will substitute into program strings Test-Case: test_subst_bug2.py Description: That is not the ideal behaviour (ideal being defined by (1) what I would expect in my program, and (2) what the C preprocessor does). preprocess-1.1.0+ds.orig/LICENSE.txt0000644000000000000000000000205311120666004015554 0ustar rootrootCopyright (c) 2002-2005 ActiveState Corp. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. preprocess-1.1.0+ds.orig/MANIFEST0000644000000000000000000000346711130451342015072 0ustar rootrootBUGS.txt CONTRIBUTORS.txt LICENSE.txt MANIFEST MANIFEST.in Makefile.py README.txt TODO.txt setup.py bin/preprocess bin/preprocess.exe lib/preprocess.py src/exe/Makefile.win src/exe/launcher.cpp test/test.py test/test_preprocess.py test/test_preprocess_inputs.py test/testlib.py test/testsupport.py test/inputs/define_types.py test/inputs/define_undef.py test/inputs/defined.py test/inputs/elif.py test/inputs/else.py test/inputs/else_expr.py test/inputs/empty.py test/inputs/error.py test/inputs/exc1.py test/inputs/exc2.py test/inputs/exc3.py test/inputs/exc4.py test/inputs/exc5.py test/inputs/file_and_line.py test/inputs/if.py test/inputs/ifdef.py test/inputs/ifndef.py test/inputs/ignore_error.py test/inputs/keep_lines_bugs.py test/inputs/keep_lines_bugs.py.opts test/inputs/nested.py test/inputs/nested_bug1.py test/inputs/recursive_include_a.py test/inputs/recursive_include_b.py test/inputs/sample.tex test/inputs/sphere.f test/inputs/subst_bug2.py test/inputs/subst_bug2.py.opts test/inputs/subst_bug2.py.tags test/inputs/substitution.py test/inputs/substitution.py.opts test/inputs/undefined.py test/outputs/define_types.py test/outputs/define_undef.py test/outputs/defined.py test/outputs/elif.py test/outputs/else.py test/outputs/else_expr.py test/outputs/empty.py test/outputs/error.py.err test/outputs/exc1.py.err test/outputs/exc2.py.err test/outputs/exc3.py.err test/outputs/exc4.py.err test/outputs/exc5.py.err test/outputs/file_and_line.py test/outputs/if.py test/outputs/ifdef.py test/outputs/ifndef.py test/outputs/ignore_error.py test/outputs/keep_lines_bugs.py test/outputs/nested.py test/outputs/nested_bug1.py test/outputs/recursive_include_a.py.err test/outputs/recursive_include_b.py.err test/outputs/sample.tex test/outputs/sphere.f test/outputs/subst_bug2.py test/outputs/substitution.py test/outputs/undefined.py.err preprocess-1.1.0+ds.orig/setup.py0000644000000000000000000000430711130423510015441 0ustar rootroot#!/usr/bin/env python # Copyright (c) 2002-2005 ActiveState Software Ltd. """preprocess: a multi-language preprocessor There are millions of templating systems out there (most of them developed for the web). This isn't one of those, though it does share some basics: a markup syntax for templates that are processed to give resultant text output. The main difference with `preprocess.py` is that its syntax is hidden in comments (whatever the syntax for comments maybe in the target filetype) so that the file can still have valid syntax. A comparison with the C preprocessor is more apt. `preprocess.py` is targetted at build systems that deal with many types of files. Languages for which it works include: C++, Python, Perl, Tcl, XML, JavaScript, CSS, IDL, TeX, Fortran, PHP, Java, Shell scripts (Bash, CSH, etc.) and C#. Preprocess is usable both as a command line app and as a Python module. """ import os import sys import distutils from distutils.core import setup sys.path.insert(0, os.path.join(os.path.dirname(__file__), "lib")) try: import preprocess finally: del sys.path[0] classifiers = """\ Development Status :: 5 - Production/Stable Intended Audience :: Developers License :: OSI Approved :: MIT License Programming Language :: Python Operating System :: OS Independent Topic :: Software Development :: Libraries :: Python Modules Topic :: Text Processing :: Filters """ if sys.version_info < (2, 3): # Distutils before Python 2.3 doesn't accept classifiers. _setup = setup def setup(**kwargs): if kwargs.has_key("classifiers"): del kwargs["classifiers"] _setup(**kwargs) doclines = __doc__.split("\n") script = (sys.platform == "win32" and "bin\\preprocess.exe" or "bin/preprocess") setup( name="preprocess", version=preprocess.__version__, maintainer="Trent Mick", maintainer_email="trentm@gmail.com", url="http://code.google.com/p/preprocess/", license="http://www.opensource.org/licenses/mit-license.php", platforms=["any"], py_modules=["preprocess"], package_dir={"": "lib"}, scripts=[script], description=doclines[0], classifiers=filter(None, classifiers.split("\n")), long_description="\n".join(doclines[2:]), ) preprocess-1.1.0+ds.orig/TODO.txt0000644000000000000000000000474611130450764015257 0ustar rootroot# High Priority - hans.txt: googlecode release pypi release trentm.com update - move BUGS.txt to issues on code site - move to 1.0.x branch and start preprocess 2: if can justify the change for: - string inter syntax that doesn't suffer from accidents (though that creates a prob for maintain syntax validity in the document) - stricter syntax to avoid accidental ##if - bug: bin/preprocess.exe doesn't work now - add issues for everything important here - test/testsupport.py:64: DeprecationWarning: The popen2 module is deprecated. Use the subprocess module. import popen2 - add issue from Mike Bauer: Yes, that is a problem that I occassionally ran into, but mostly just hacked around because I didn't think it would be that common. To "fix" this, I think I want to get strict about the preprocess.py directive by requiring no space between the second "#" and the directive name: # #if ... (this works) ## if ... (this is not treated as a preprocess.py directive) - add logging_patch_from_alfred.patch (Alfred Lorber) - use path_from_path_patterns recipe to provide a simple facility for recursively preprocessing a bunch of files, a dir, etc. As suggested by Hans. - fix MANIFEST.in processing from picking up README.txt in .svn dirs - need eolconverter recipe for building dists on Windows - "build sdist" broken on Windows - "build webdist" not implemented on Windows - should I do dists for both kinds of EOLs??? - convert to logging package - put up on cheeseshop # Medium Priority - A better longterm fix for 0.9.2's copying content.types to the "binDir" next to preprocess.py is to have the launcher stub NOT have the .py file next to it. We should only be placing one preprocess.py in the lib dir. Perhaps setuptools stub stuff can help here? - test 'includePath' optional argument - test cases for the module interface (do I have any?) - test cases for -k|--keep-lines - patchtemplate functionality: look at how the preprocessor.pl below does this, perhaps this is an acceptible poorman's version (Somewhat have this, see --substitute added in v0.6.0.) - stealing from http://software.hixie.ch/utilities/unix/preprocessor/ - Should I really add #elifdef and #elifndef? - Would #filter/#endfilter be useful? - be more strict: - perhaps add -W option to allow levels of strictness - make #undef of undefined vars an error - perhaps add #pragma to enable turning on of options: e.g. # #pragma substitution preprocess-1.1.0+ds.orig/README.txt0000644000000000000000000003373211130447306015442 0ustar rootrootpreprocess.py -- a portable multi-language file preprocessor ============================================================ Download the latest preprocess.py packages from here: (archive) http://preprocess.googlecode.com/files/preprocess-1.2.0.zip Home : http://trentm.com/projects/preprocess/ License : MIT (see LICENSE.txt) Platforms : Windows, Linux, Mac OS X, Unix Current Version : 1.1 Dev Status : Fairly mature, has been used in the Komodo build system for over 7 years. Requirements : Python >= 2.3 (http://www.activestate.com/ActivePython/) What's new? ----------- Support has been added for preprocessing TeX, Fortran, C#, Java, Shell script and PHP files. See the [Change Log](#changelog) below for more. Why preprocess.py? ------------------ There are millions of templating systems out there (most of them developed for the web). This isn't one of those, though it does share some basics: a markup syntax for templates that are processed to give resultant text output. The main difference with `preprocess.py` is that its syntax is hidden in comments (whatever the syntax for comments maybe in the target filetype) so that the file can still have valid syntax. A comparison with the C preprocessor is more apt. `preprocess.py` is targetted at build systems that deal with many types of files. Languages for which it works include: C++, Python, Perl, Tcl, XML, JavaScript, CSS, IDL, TeX, Fortran, PHP, Java, Shell scripts (Bash, CSH, etc.) and C#. Preprocess is usable both as a command line app and as a Python module. Here is how is works: All preprocessor statements are on their own line. A preprocessor statement is a comment (as appropriate for the language of the file being preprocessed). This way the preprocessor statements do not make an unpreprocessed file syntactically incorrect. For example: preprocess -D FEATURES=macros,scc myapp.py will yield this transformation: ... ... # #if "macros" in FEATURES def do_work_with_macros(): def do_work_with_macros(): pass pass # #else def do_work_without_macros(): pass # #endif ... ... or, with a JavaScript file: ... ... // #if "macros" in FEATURES function do_work_with_macros() { function do_work_with_macros() { } } // #else function do_work_without_macros() { } // #endif ... ... Despite these contrived examples preprocess has proved useful for build-time code differentiation in the [Komodo](http://www.activestate.com/Komodo) build system -- which includes source code in Python, JavaScript, XML, CSS, Perl, and C/C++. The #if expression (`"macros" in FEATURES` in the example) is Python code, so has Python's full comparison richness. A number of preprocessor statements are implemented: #define VAR [VALUE] #undef VAR #ifdef VAR #ifndef VAR #if EXPRESSION #elif EXPRESSION #else #endif #error ERROR_STRING #include "FILE" As well, preprocess will do in-line substitution of defined variables. Although this is currently off by default because substitution will occur in program strings, which is not ideal. When a future version of preprocess can lex languages being preprocessed it will NOT substitute into program strings and substitution will be turned ON by default. Please send any feedback to [Trent Mick](mailto:trentm@google's mail thing.com). Install Notes ------------- Download the latest `preprocess` source package, unzip it, and run `python setup.py install`: unzip preprocess-1.1.0.zip cd preprocess-1.1.0 python setup.py install If your install fails then please visit [the Troubleshooting FAQ](http://trentm.com/faq.html#troubleshooting-python-package-installation). This will install `preprocess.py` into your Python `site-packages` and also into your Python bin directory. If you can now run `preprocess` and get a response then you are good to go, otherwise read on. The *problem* is that the Python bin directory is not always on your PATH on some operating systems -- notably Mac OS X. To finish the install on OS X either manually move 'preprocess' to somewhere on your PATH: cp preprocess.py /usr/local/bin/preprocess or create a symlink to it (try one of these depending on your Python version): ln -s /System/Library/Frameworks/Python.framework/Versions/2.3/bin/preprocess /usr/local/bin/preprocess ln -s /Library/Frameworks/Python.framework/Versions/2.4/bin/preprocess /usr/local/bin/preprocess (Note: You'll probably need to prefix those commands with `sudo` and the exact paths may differ on your system.) Getting Started --------------- Once you have it install, run `preprocess --help` for full usage information: $ preprocess --help Preprocess a file. Command Line Usage: preprocess [...] Options: -h, --help Print this help and exit. -V, --version Print the version info and exit. -v, --verbose Give verbose output for errors. -o Write output to the given file instead of to stdout. -f, --force Overwrite given output file. (Otherwise an IOError will be raised if already exists. -D Define a variable for preprocessing. can simply be a variable name (in which case it will be true) or it can be of the form =. An attempt will be made to convert to an integer so "-D FOO=0" will create a false value. -I Add an directory to the include path for #include directives. -k, --keep-lines Emit empty lines for preprocessor statement lines and skipped output lines. This allows line numbers to stay constant. -s, --substitute Substitute defines into emitted lines. By default substitution is NOT done because it currently will substitute into program strings. Module Usage: from preprocess import preprocess preprocess(infile, outfile=sys.stdout, defines={}, force=0, keepLines=0, includePath=[], substitute=0) The can be marked up with special preprocessor statement lines of the form: where the are the native comment delimiters for that file type. Examples -------- HTML (*.htm, *.html) or XML (*.xml, *.kpf, *.xul) files: ... Python (*.py), Perl (*.pl), Tcl (*.tcl), Ruby (*.rb), Bash (*.sh), or make ([Mm]akefile*) files: # #if defined('FAV_COLOR') and FAV_COLOR == "blue" ... # #elif FAV_COLOR == "red" ... # #else ... # #endif C (*.c, *.h), C++ (*.cpp, *.cxx, *.cc, *.h, *.hpp, *.hxx, *.hh), Java (*.java), PHP (*.php) or C# (*.cs) files: // #define FAV_COLOR 'blue' ... /* #ifndef FAV_COLOR */ ... // #endif Fortran 77 (*.f) or 90/95 (*.f90) files: C #if COEFF == 'var' ... C #endif Preprocessor Syntax ------------------- - Valid statements: #define [] #undef #ifdef #ifndef #if #elif #else #endif #error #include "" where is any valid Python expression. - The expression after #if/elif may be a Python statement. It is an error to refer to a variable that has not been defined by a -D option or by an in-content #define. - Special built-in methods for expressions: defined(varName) Return true if given variable is defined. Tips ---- A suggested file naming convention is to let input files to preprocess be of the form .p. and direct the output of preprocess to ., e.g.: preprocess -o foo.py foo.p.py The advantage is that other tools (esp. editors) will still recognize the unpreprocessed file as the original language. And, for module usage, read the preprocess.preprocess() docstring: pydoc preprocess.preprocess Change Log ---------- ### v1.1.0 - Move to code.google.com/p/preprocess for code hosting. - Re-org directory structure to assist with deployment to pypi and better installation with setup.py. - Pulled the "content.types" file that assists with filetype determination into "preprocess.py". This makes "preprocess.py" fully independent and also makes the "setup.py" simpler. The "-c|--content-types-path" option can be used to specify addition content types information. ### v1.0.9 - Fix the 'contentType' optional arg for #include's. - Add cheap XML content sniffing. ### v1.0.8 - Allow for JS and CSS-style comment delims in XML/HTML. Ideally this would deal with full lexing but that isn't going to happen soon. ### v1.0.7 - Allow explicit specification of content type. ### v1.0.6 - Add ability to include a filename mentioned in a define: '#include VAR'. ### v1.0.5 - Make sure to use the *longest* define names first when doing substitutions. This ensure that substitution in this line: FOO and BAR are FOOBAR will do the right thing if there are "FOO" and "FOOBAR" defines. ### v1.0.4 - Add WiX XML file extensions. - Add XSLT file extensions. ### v1.0.3 - TeX support (from Hans Petter Langtangen) ### v1.0.2 - Fix a bug with -k|--keep-lines and preprocessor some directives in ignored if blocks (undef, define, error, include): those lines were not kept. (bug noted by Eric Promislow) ### v1.0.1 - Fix documentation error for '#define' statement. The correct syntax is '#define VAR [VALUE]' while the docs used to say '#define VAR[=VALUE]'. (from Hans Petter Langtangen) - Correct '! ...' comment-style for Fortran -- the '!' can be on any column in Fortran 90. (from Hans Petter Langtangen) - Return a non-zero exit code on error. ### v1.0.0 - Update the test suite (it had been broken for quite a while) and add a Fortran test case. - Improve Fortran support to support any char in the first column to indicate a comment. (Idea from Hans Petter Langtangen) - Recognize '.f90' files as Fortran. (from Hans Petter Langtangen) - Add Java, C#, Shell script and PHP support. (from Hans Petter Langtangen) ### v0.9.2 - Add Fortran support (from Hans Petter Langtangen) - Ensure content.types gets written to "bindir" next to preprocess.py there so it can be picked up (from Hans Petter Langtangen). ### v0.9.1 - Fully read in the input file before processing. This allows preprocessing of a file onto itself. ### v0.9.0 - Change version attributes and semantics. Before: had a _version_ tuple. After: __version__ is a string, __version_info__ is a tuple. ### v0.8.1 - Mentioned #ifdef and #ifndef in documentation (these have been there for a while). - Add preprocess.exe to source package (should fix installation on Windows). - Incorporate Komodo changes: - change 171050: add Ruby support - change 160914: Only attempt to convert define strings from the command-line to *int* instead of eval'ing as any Python expression: which could surprise with strings that work as floats. - change 67962: Fix '#include' directives in preprocessed files. ### v0.8.0 - Move hosting to trentm.com. Improve the starter docs a little bit. ### 0.7.0: - Fix bug 1: Nested #if-blocks will not be properly handled. - Add 'Text' type for .txt files and default (with a warn) unknown filetypes to 'Text'. Text files are defined to use to '#...'-style comments to allow if/else/.../endif directives as in Perl/Python/Tcl files. ### 0.6.1: - Fix a bug where preprocessor statements were not ignored when not emitting. For example the following should _not_ cause an error: # #if 0 # #error womba womba womba # #endif - Fix a bug where multiple uses of preprocess.preprocess() in the same interpreter would erroneously re-use the same list of __preprocessedFiles. This could cause false detection of recursive #include's. - Fix #include, broken in 0.6.0. ### 0.6.0: - substitution: Variables can now replaced with their defined value in preprocessed file content. This is turned OFF by default because, IMO, substitution should not be done in program strings. I need to add lexing for all supported languages before I can do *that* properly. Substitution can be turned on with the --substitute command-line option or the subst=1 module interface option. - Add support for preprocessing HTML files. ### 0.5.0: - Add #error, #define, #undef, #ifdef and #ifndef statements. - #include statement, -I command line option and 'includePath' module interface option to specify an include path - Add __FILE__ and __LINE__ default defines. - More strict and more helpful error messages: - Lines of the form "#else " and "#endif " no longer match. - error messages for illegal #if-block constructs - error messages for use of defined(BAR) instead of defined('BAR') in expressions - New "keep lines" option to output blank lines for skipped content lines and preprocessor statement lines (to preserve line numbers in the processed file). ### 0.4.0: - Add #elif preprocessor statement. - Add defined() built-in, e.g. #if defined('FOO') ### 0.3.2: - Make #if expressions Python code. - Change "defines" attribute of preprocess.preprocess(). - Add -f|--force option to overwrite given output file. ### 0.2.0: - Add content types for C/C++. - Better module documentation. - You can define *false* vars on the command line now. - 'python setup.py install' works. ### 0.1.0: - First release. preprocess-1.1.0+ds.orig/test/0000755000000000000000000000000011573617731014727 5ustar rootrootpreprocess-1.1.0+ds.orig/test/inputs/0000755000000000000000000000000011573617731016251 5ustar rootrootpreprocess-1.1.0+ds.orig/test/inputs/defined.py0000644000000000000000000000022311120665766020215 0ustar rootroot#!python if __name__ == '__main__': # #if defined('ASDF') print "ASDF defined" # #else print "ASDF not defined" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/substitution.py0000644000000000000000000000012311120665766021372 0ustar rootroot#!python # #define VAR foo if __name__ == '__main__': foo = 1 print VAR preprocess-1.1.0+ds.orig/test/inputs/undefined.py0000644000000000000000000000015011120665766020557 0ustar rootroot#!python if __name__ == '__main__': # #if FOO print "foo is not defined" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/empty.py0000644000000000000000000000016411120665766017761 0ustar rootroot#!python """This is a Python file with NO preprocessor stmts in it.""" if __name__ == '__main__': print "hi" preprocess-1.1.0+ds.orig/test/inputs/if.py0000644000000000000000000000021011120665766017211 0ustar rootroot#!python # #define ONE 1 # #define ZERO 0 # #define UN 1 if __name__ == '__main__': # #if ONE print "hi" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/define_types.py0000644000000000000000000000123111120665766021275 0ustar rootroot#!python # #define FOO_NONE # #define FOO_INT 42 # #define FOO_FLOAT 3.14 # #define FOO_STRING1 foo # #define FOO_STRING2 "foo" # #define FOO_LIST [1, 'a', 2.5] # #define FOO_TUPLE (1, 'a', 2.5) # #define FOO_DICT {'a':1, 'b':2} # #if FOO_NONE is None print "FOO_NONE" # #endif # #if FOO_INT == 42 print "FOO_INT" # #endif # #if FOO_FLOAT == 3.14 print "FOO_FLOAT" # #endif # #if FOO_STRING1 == "foo" print "FOO_STRING1" # #endif # #if FOO_STRING2 == "foo" print "FOO_STRING2" # #endif # #if FOO_LIST == [1, 'a', 2.5] print "FOO_LIST" # #endif # #if FOO_TUPLE == (1, 'a', 2.5) print "FOO_TUPLE" # #endif # #if FOO_DICT == {'a':1, 'b':2} print "FOO_DICT" # #endif preprocess-1.1.0+ds.orig/test/inputs/elif.py0000644000000000000000000000035511120665766017544 0ustar rootroot#!python # #define ONE 1 # #define ZERO 0 # #define UN 1 if __name__ == '__main__': # #if ZERO print "a" # #elif ZERO print "b" # #elif ONE print "c" # #elif ONE print "d" # #else print "e" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/file_and_line.py0000644000000000000000000000052011120665766021367 0ustar rootroot # #if defined('__FILE__') print "__FILE__ is defined" # #endif # #if __FILE__.endswith("file_and_line.py") print "__FILE__.endswith('file_and_line.py')" # #endif # #if defined('__LINE__') print "__LINE__ is defined" # #endif # #if __LINE__ == 14 print "__LINE__ is 14" # #endif # #if __LINE__ == 18 print "__LINE__ is 18" # #endif preprocess-1.1.0+ds.orig/test/inputs/exc5.py0000644000000000000000000000005111120665766017462 0ustar rootroot# #if defined(FOO) print "foo" # #endif preprocess-1.1.0+ds.orig/test/inputs/sample.tex0000644000000000000000000000011211120665766020245 0ustar rootroot% #define TEST % #ifdef TEST some text % #else some other text % #endif preprocess-1.1.0+ds.orig/test/inputs/keep_lines_bugs.py0000644000000000000000000000040411120665766021756 0ustar rootroot# Test a bug where --keep-lines wasn't obeyed for directives inside # skipped #if-blocks. print "this is line 4" # #ifdef UNDEFINED # #error "UNDEFINED is defined!" # #define BAR 1 # #endif print "this is line 12" # #define FOO 2 print "this is line 15" preprocess-1.1.0+ds.orig/test/inputs/subst_bug2.py0000644000000000000000000000061511120665766020703 0ustar rootroot#!python # Test that substitution does NOT happen in strings. In current # preprocess.py it *does* (hence this test is currently expected to # fail). However, the long term goal is to understand languages' string # tokens and skip them for substitution. # #define VAR foo if __name__ == '__main__': foo = 1 # The V-A-R should _not_ be substituted in the string. print "VAR is", VAR preprocess-1.1.0+ds.orig/test/inputs/nested_bug1.py0000644000000000000000000000032311120665766021020 0ustar rootroot#!python if __name__ == '__main__': print "hi" # #if 0 print "should not be emitted 1" # #if 1 print "should not be emitted 2" # #endif print "should not be emitted 3" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/keep_lines_bugs.py.opts0000644000000000000000000000001511120665766022740 0ustar rootroot--keep-lines preprocess-1.1.0+ds.orig/test/inputs/ignore_error.py0000644000000000000000000000024111120665766021313 0ustar rootroot#!python print "hi" # #if 0 # The following should not cause an error, but did up until # preprocess v0.6.1. # #error womba womba womba # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/else_expr.py0000644000000000000000000000024711120665766020613 0ustar rootroot#!python # #define ONE 1 # #define ZERO 0 # #define UN 1 if __name__ == '__main__': # #if ONE print "hi" # #else ZERO print "hello" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/subst_bug2.py.tags0000644000000000000000000000001611127431604021620 0ustar rootrootknownfailure preprocess-1.1.0+ds.orig/test/inputs/recursive_include_a.py0000644000000000000000000000004611120665766022634 0ustar rootroot # #include "recursive_include_b.py" preprocess-1.1.0+ds.orig/test/inputs/sphere.f0000644000000000000000000000176711120665766017720 0ustar rootrootc23456789012345678901234567890123456789012345678901234567890123456789012 PROGRAM sphere c This program determines the surface area and volume of a sphere, given c its radius. c Variable declarations REAL rad, area, volume, pi c Definition of variables c rad = radius, area = surface area, volume = volume of the sphere c Assign a value to the variable pi. pi = 3.141593 c Input the value of the radius and echo the inputted value. PRINT *, 'Enter the radius of the sphere.' READ *, rad ! #define VERBOSE 1 C #if VERBOSE PRINT *, rad, ' is the value of the radius.' ! #endif c Compute the surface area and volume of the sphere. area = 4.0 * pi * rad**2 volume = (4.0/3.0) * pi * rad**3 c Print the values of the radius (given in cm), the surface area (sq cm), c and the volume (cubic cm). PRINT *,'In a sphere of radius', rad, ' , the surface area is', + area, ' and its volume is', volume, '.' STOP END preprocess-1.1.0+ds.orig/test/inputs/exc1.py0000644000000000000000000000002211120665766017454 0ustar rootroot# #if 1 print "1" preprocess-1.1.0+ds.orig/test/inputs/nested.py0000644000000000000000000000035311120665766020105 0ustar rootroot#!python # #define ONE 1 # #define ZERO 0 # #define UN 1 if __name__ == '__main__': # #if ONE print "one" # #if UN print "un" # #endif print "still, just one" # #if ZERO print "zero" # #endif # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/exc2.py0000644000000000000000000000006111120665766017460 0ustar rootroot# #if 0 print "0" # #endif # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/error.py0000644000000000000000000000025211120665766017752 0ustar rootroot#!python # #define ONE 1 # #define ZERO 0 # #define UN 1 if __name__ == '__main__': # #if ONE print "hi" # #error This is an error string. # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/recursive_include_b.py0000644000000000000000000000004611120665766022635 0ustar rootroot # #include "recursive_include_a.py" preprocess-1.1.0+ds.orig/test/inputs/else.py0000644000000000000000000000021111120665766017544 0ustar rootroot#!python # #define ZERO 0 if __name__ == '__main__': # #if ZERO print "zero" # #else print "not zero" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/exc4.py0000644000000000000000000000010611120665766017462 0ustar rootroot# #if 1 print "1" # #else print "not 1" # #elif 0 print "0" # #endif preprocess-1.1.0+ds.orig/test/inputs/subst_bug2.py.opts0000644000000000000000000000001511120665766021661 0ustar rootroot--substitute preprocess-1.1.0+ds.orig/test/inputs/exc3.py0000644000000000000000000000004411120665766017462 0ustar rootroot# #if 0 print "0" # #endif # #endif preprocess-1.1.0+ds.orig/test/inputs/ifndef.py0000644000000000000000000000054211120665766020056 0ustar rootroot#!python # #define ONE 1 # #define ZERO 0 # #define UN 1 if __name__ == '__main__': # #ifndef ONE print "ONE not defined" # #else print "ONE defined" # #endif # #ifndef ZERO print "ZERO not defined" # #else print "ZERO defined" # #endif # #ifndef FOO print "FOO not defined" # #else print "FOO defined" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/ifdef.py0000644000000000000000000000053711120665766017704 0ustar rootroot#!python # #define ONE 1 # #define ZERO 0 # #define UN 1 if __name__ == '__main__': # #ifdef ONE print "ONE defined" # #else print "ONE not defined" # #endif # #ifdef ZERO print "ZERO defined" # #else print "ZERO not defined" # #endif # #ifdef FOO print "FOO defined" # #else print "FOO not defined" # #endif print "bye" preprocess-1.1.0+ds.orig/test/inputs/define_undef.py0000644000000000000000000000100211120665766021226 0ustar rootroot#!python # #define FOO_A # #define FOO_B 0 # #define FOO_C 1 if __name__ == '__main__': # #if FOO_A print "a" # #endif # #if FOO_B print "b" # #endif # #if defined("FOO_B") print "b defined" # #endif # #if FOO_C print "c" # #endif # #if defined("FOO_D") print "d defined" # #endif # #undef FOO_B # #undef FOO_D # #if FOO_A print "a" # #endif # #if defined("FOO_B") print "b defined" # #endif # #if FOO_C print "c" # #endif # #if defined("FOO_D") print "d defined" # #endif preprocess-1.1.0+ds.orig/test/inputs/substitution.py.opts0000644000000000000000000000001511120665766022356 0ustar rootroot--substitute preprocess-1.1.0+ds.orig/test/testsupport.py0000644000000000000000000000417211120665770017713 0ustar rootroot#!/usr/bin/env python import os import sys import types import shutil #---- test constants TMPDIR = "tmp" #---- Support routines def _escapeArg(arg): """Escape the given command line argument for the shell.""" #XXX There is a *lot* more that we should escape here. return arg.replace('"', r'\"') def _joinArgv(argv): r"""Join an arglist to a string appropriate for running. >>> import os >>> _joinArgv(['foo', 'bar "baz']) 'foo "bar \\"baz"' """ cmdstr = "" for arg in argv: if ' ' in arg: cmdstr += '"%s"' % _escapeArg(arg) else: cmdstr += _escapeArg(arg) cmdstr += ' ' if cmdstr.endswith(' '): cmdstr = cmdstr[:-1] # strip trailing space return cmdstr def run(argv): """Prepare and run the given arg vector, 'argv', and return the results. Returns (, , ). Note: 'argv' may also just be the command string. """ if type(argv) in (types.ListType, types.TupleType): cmd = _joinArgv(argv) else: cmd = argv if sys.platform.startswith('win'): i, o, e = os.popen3(cmd) output = o.read() error = e.read() i.close() e.close() try: retval = o.close() except IOError: # IOError is raised iff the spawned app returns -1. Go # figure. retval = -1 if retval is None: retval = 0 else: import popen2 p = popen2.Popen3(cmd, 1) i, o, e = p.tochild, p.fromchild, p.childerr output = o.read() error = e.read() i.close() o.close() e.close() retval = (p.wait() & 0xFF00) >> 8 if retval > 2**7: # 8-bit signed 1's-complement conversion retval -= 2**8 return output, error, retval def _rmtreeOnError(rmFunction, filePath, excInfo): if excInfo[0] == OSError: # presuming because file is read-only os.chmod(filePath, 0777) rmFunction(filePath) def rmtree(dirname): import shutil shutil.rmtree(dirname, 0, _rmtreeOnError) preprocess-1.1.0+ds.orig/test/test_preprocess.py0000644000000000000000000000531211120665770020520 0ustar rootroot # Copyright (c) 2002 Trent Mick # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """Grab bag of test cases for preprocess.py.""" import sys import os import unittest import difflib import pprint import testsupport from testsupport import TMPDIR #----- test cases class PreprocessTestCase(unittest.TestCase): def setUp(self): self.tmpdir = os.path.join(TMPDIR, "preprocess") if not os.path.exists(self.tmpdir): os.makedirs(self.tmpdir) def test_false_recursive_includes(self): # There was a bug pre-0.6.1 where the private list of already # preprocessed files, used to trap recursive includes, would not # get cleared between independent preprocess() calls in the same # Python process. Test that that case has been fixed here. import preprocess inFile = os.path.join(self.tmpdir, "test_false_recursive_includes.in.py") outFile = os.path.join(self.tmpdir, "test_false_recursive_includes.out.py") fout = open(inFile, 'w') fout.write("foo") fout.close() preprocess.preprocess(inFile, outFile) # If this second one works then the bug is fixed. try: preprocess.preprocess(inFile, outFile) except preprocess.PreprocessError, ex: self.fail("Second independant preprocess() call incorrectly "\ "re-used list of already preprocessed files froma "\ "previous call.") #---- mainline def suite(): """Return a unittest.TestSuite to be used by test.py.""" return unittest.makeSuite(PreprocessTestCase) if __name__ == "__main__": runner = unittest.TextTestRunner(sys.stdout, verbosity=2) result = runner.run(suite()) preprocess-1.1.0+ds.orig/test/test.py0000644000000000000000000000146111127431606016250 0ustar rootroot#!/usr/bin/env python # Copyright (c) 2005-2006 ActiveState Software Inc. """The preprocess test suite entry point.""" import os from os.path import exists, join, dirname, abspath import sys import logging from pprint import pprint import testlib log = logging.getLogger("test") default_tags = ["-knownfailure"] def setup(): # Ensure the *development* preprocess.py is tested. lib_dir = join(dirname(dirname(abspath(__file__))), "lib") sys.path.insert(0, lib_dir) sys.stdout.write("Setup to test: ") sys.stdout.flush() preprocess_py = join(lib_dir, "preprocess.py") os.system("%s %s -V" % (sys.executable, preprocess_py)) sys.stdout.write("-"*70 + '\n') if __name__ == "__main__": retval = testlib.harness(setup_func=setup, default_tags=default_tags) sys.exit(retval) preprocess-1.1.0+ds.orig/test/outputs/0000755000000000000000000000000011573617731016452 5ustar rootrootpreprocess-1.1.0+ds.orig/test/outputs/undefined.py.err0000644000000000000000000000010411120665770021541 0ustar rootrootpreprocess: error: inputs/undefined.py:4: name 'FOO' is not defined preprocess-1.1.0+ds.orig/test/outputs/defined.py0000644000000000000000000000012311120665770020410 0ustar rootroot#!python if __name__ == '__main__': print "ASDF not defined" print "bye" preprocess-1.1.0+ds.orig/test/outputs/substitution.py0000644000000000000000000000010111120665770021562 0ustar rootroot#!python if __name__ == '__main__': foo = 1 print foo preprocess-1.1.0+ds.orig/test/outputs/empty.py0000644000000000000000000000016411120665770020155 0ustar rootroot#!python """This is a Python file with NO preprocessor stmts in it.""" if __name__ == '__main__': print "hi" preprocess-1.1.0+ds.orig/test/outputs/if.py0000644000000000000000000000010511120665770017410 0ustar rootroot#!python if __name__ == '__main__': print "hi" print "bye" preprocess-1.1.0+ds.orig/test/outputs/define_types.py0000644000000000000000000000023211120665770021471 0ustar rootroot#!python print "FOO_NONE" print "FOO_INT" print "FOO_FLOAT" print "FOO_STRING1" print "FOO_STRING2" print "FOO_LIST" print "FOO_TUPLE" print "FOO_DICT" preprocess-1.1.0+ds.orig/test/outputs/exc3.py.err0000644000000000000000000000011711120665770020446 0ustar rootrootpreprocess: error: inputs/exc3.py:4: superfluous #endif on or before this line preprocess-1.1.0+ds.orig/test/outputs/elif.py0000644000000000000000000000010411120665770017730 0ustar rootroot#!python if __name__ == '__main__': print "c" print "bye" preprocess-1.1.0+ds.orig/test/outputs/recursive_include_b.py.err0000644000000000000000000000012211120665770023613 0ustar rootrootpreprocess: error: detected recursive #include of 'inputs/recursive_include_b.py' preprocess-1.1.0+ds.orig/test/outputs/exc4.py.err0000644000000000000000000000012111120665770020442 0ustar rootrootpreprocess: error: inputs/exc4.py:5: illegal #elif after #else in same #if block preprocess-1.1.0+ds.orig/test/outputs/file_and_line.py0000644000000000000000000000023111120665770021562 0ustar rootroot print "__FILE__ is defined" print "__FILE__.endswith('file_and_line.py')" print "__LINE__ is defined" print "__LINE__ is 14" print "__LINE__ is 18" preprocess-1.1.0+ds.orig/test/outputs/exc5.py.err0000644000000000000000000000017511120665770020454 0ustar rootrootpreprocess: error: inputs/exc5.py:1: name 'FOO' is not defined (perhaps you want "defined('FOO')" instead of "defined(FOO)") preprocess-1.1.0+ds.orig/test/outputs/sample.tex0000644000000000000000000000001311120665770020441 0ustar rootrootsome text preprocess-1.1.0+ds.orig/test/outputs/recursive_include_a.py.err0000644000000000000000000000012211120665770023612 0ustar rootrootpreprocess: error: detected recursive #include of 'inputs/recursive_include_a.py' preprocess-1.1.0+ds.orig/test/outputs/keep_lines_bugs.py0000644000000000000000000000025411120665770022155 0ustar rootroot# Test a bug where --keep-lines wasn't obeyed for directives inside # skipped #if-blocks. print "this is line 4" print "this is line 12" print "this is line 15" preprocess-1.1.0+ds.orig/test/outputs/subst_bug2.py0000644000000000000000000000057311120665770021102 0ustar rootroot#!python # Test that substitution does NOT happen in strings. In current # preprocess.py it *does* (hence this test is currently expected to # fail). However, the long term goal is to understand languages' string # tokens and skip them for substitution. if __name__ == '__main__': foo = 1 # The V-A-R should _not_ be substituted in the string. print "VAR is", foo preprocess-1.1.0+ds.orig/test/outputs/nested_bug1.py0000644000000000000000000000010511120665770021212 0ustar rootroot#!python if __name__ == '__main__': print "hi" print "bye" preprocess-1.1.0+ds.orig/test/outputs/ignore_error.py0000644000000000000000000000004211120665770021506 0ustar rootroot#!python print "hi" print "bye" preprocess-1.1.0+ds.orig/test/outputs/else_expr.py0000644000000000000000000000014411120665770021003 0ustar rootroot#!python if __name__ == '__main__': print "hi" # #else ZERO print "hello" print "bye" preprocess-1.1.0+ds.orig/test/outputs/exc2.py.err0000644000000000000000000000011111120665770020437 0ustar rootrootpreprocess: error: inputs/exc2.py:5: superfluous #endif before this line preprocess-1.1.0+ds.orig/test/outputs/sphere.f0000644000000000000000000000170411120665770020103 0ustar rootrootc23456789012345678901234567890123456789012345678901234567890123456789012 PROGRAM sphere c This program determines the surface area and volume of a sphere, given c its radius. c Variable declarations REAL rad, area, volume, pi c Definition of variables c rad = radius, area = surface area, volume = volume of the sphere c Assign a value to the variable pi. pi = 3.141593 c Input the value of the radius and echo the inputted value. PRINT *, 'Enter the radius of the sphere.' READ *, rad PRINT *, rad, ' is the value of the radius.' c Compute the surface area and volume of the sphere. area = 4.0 * pi * rad**2 volume = (4.0/3.0) * pi * rad**3 c Print the values of the radius (given in cm), the surface area (sq cm), c and the volume (cubic cm). PRINT *,'In a sphere of radius', rad, ' , the surface area is', + area, ' and its volume is', volume, '.' STOP END preprocess-1.1.0+ds.orig/test/outputs/nested.py0000644000000000000000000000016111120665770020276 0ustar rootroot#!python if __name__ == '__main__': print "one" print "un" print "still, just one" print "bye" preprocess-1.1.0+ds.orig/test/outputs/exc1.py.err0000644000000000000000000000007411120665770020446 0ustar rootrootpreprocess: error: inputs/exc1.py:2: unterminated #if block preprocess-1.1.0+ds.orig/test/outputs/else.py0000644000000000000000000000011311120665770017741 0ustar rootroot#!python if __name__ == '__main__': print "not zero" print "bye" preprocess-1.1.0+ds.orig/test/outputs/ifndef.py0000644000000000000000000000020311120665770020244 0ustar rootroot#!python if __name__ == '__main__': print "ONE defined" print "ZERO defined" print "FOO not defined" print "bye" preprocess-1.1.0+ds.orig/test/outputs/ifdef.py0000644000000000000000000000020311120665770020066 0ustar rootroot#!python if __name__ == '__main__': print "ONE defined" print "ZERO defined" print "FOO not defined" print "bye" preprocess-1.1.0+ds.orig/test/outputs/error.py.err0000644000000000000000000000010711120665770020734 0ustar rootrootpreprocess: error: inputs/error.py:9: #error: This is an error string. preprocess-1.1.0+ds.orig/test/outputs/define_undef.py0000644000000000000000000000013311120665770021426 0ustar rootroot#!python if __name__ == '__main__': print "b defined" print "c" print "c" preprocess-1.1.0+ds.orig/test/test_preprocess_inputs.py0000644000000000000000000001022111127431606022111 0ustar rootroot#!/usr/bin/env python # Copyright (c) 2002-2008 Trent Mick # License: MIT License (http://www.opensource.org/licenses/mit-license.php) # Contributors: # Trent Mick (TrentM@ActiveState.com) """Test preprocessing of inputs/... with preprocess.py.""" import sys import os from os.path import join, dirname, abspath, exists import unittest import difflib import pprint import testsupport from testsupport import TMPDIR #----- test cases class PreprocessInputsTestCase(unittest.TestCase): def setUp(self): if not os.path.exists(TMPDIR): os.makedirs(TMPDIR) def _testOneInputFile(self, fname): import preprocess DEBUG = False # Set to true to dump status info for each test run. # Determine input options to use, if any. optsfile = os.path.join('inputs', fname+'.opts') # input options opts = [] if os.path.exists(optsfile): for line in open(optsfile, 'r').readlines(): if line[-1] == "\n": line = line[:-1] opts.append(line.strip()) #print "options from '%s': %s" % (optsfile, pprint.pformat(opts)) # Preprocess. infile = os.path.join('inputs', fname) # input outfile = os.path.join('tmp', fname) # actual output preprocess_py = join(dirname(dirname(abspath(__file__))), "lib", "preprocess.py") argv = [sys.executable, preprocess_py] + opts + ["-o", outfile, infile] dummy, err, retval = testsupport.run(argv) try: out = open(outfile, 'r').read() except IOError, ex: self.fail("unexpected error running '%s': '%s' was not generated:\n" "\t%s" % (' '.join(argv), outfile, err)) if DEBUG: print print "*"*50, "cmd" print ' '.join(argv) print "*"*50, "stdout" print out print "*"*50, "stderr" print err print "*"*50, "retval" print str(retval) print "*" * 50 # Compare results with the expected. expoutfile = os.path.join('outputs', fname) # expected stdout output experrfile = os.path.join('outputs', fname+'.err') # expected error output if os.path.exists(expoutfile): expout = open(expoutfile, 'r').read() #print "expected stdout output: %r" % expout if not sys.platform.startswith("win"): expout = expout.replace('\\','/') # use Un*x paths if expout != out: diff = list(difflib.ndiff(expout.splitlines(1), out.splitlines(1))) self.fail("%r != %r:\n%s"\ % (expoutfile, outfile, pprint.pformat(diff))) if os.path.exists(experrfile): experr = open(experrfile, 'r').read() #print "expected stderr output: %r" % experr massaged_experr = experr.replace("inputs/", "inputs"+os.sep) diff = list(difflib.ndiff(massaged_experr.strip().splitlines(1), err.strip().splitlines(1))) self.failUnlessEqual(massaged_experr.strip(), err.strip(), " != :\n%s"\ % pprint.pformat(diff)) elif err: self.fail("there was error output when processing '%s', but no "\ "expected stderr output file, '%s'" % (infile, experrfile)) # Ensure next test file gets a clean preprocess. del sys.modules['preprocess'] def _fillPreprocessInputsTestCase(): dpath = "inputs" for fname in os.listdir(dpath): if os.path.isdir(os.path.join(dpath, fname)): continue if fname.endswith(".opts"): continue # skip input option files if fname.endswith(".tags"): continue # skip tags files testFunction = lambda self, fname=fname: _testOneInputFile(self, fname) # Set tags for this test case. tags = [] tagspath = join(dpath, fname + ".tags") # ws-separate set of tags if exists(tagspath): tags += open(tagspath, 'r').read().split() if tags: testFunction.tags = tags name = "test_" + fname setattr(PreprocessInputsTestCase, name, testFunction) #---- mainline def test_cases(): _fillPreprocessInputsTestCase() yield PreprocessInputsTestCase if __name__ == "__main__": unittest.main() preprocess-1.1.0+ds.orig/test/testlib.py0000644000000000000000000006277711127431606016760 0ustar rootroot#!python # Copyright (c) 2000-2008 ActiveState Software Inc. # License: MIT License (http://www.opensource.org/licenses/mit-license.php) """ test suite harness Usage: test --list [...] # list available tests modules test [...] # run test modules Options: -v, --verbose more verbose output -q, --quiet don't print anything except if a test fails -d, --debug log debug information -h, --help print this text and exit -l, --list Just list the available test modules. You can also specify tags to play with module filtering. -n, --no-default-tags Ignore default tags -L Specify a logging level via : For example: codeintel.db:DEBUG This option can be used multiple times. By default this will run all tests in all available "test_*" modules. Tags can be specified to control which tests are run. For example: test python # run tests with the 'python' tag test python cpln # run tests with both 'python' and 'cpln' tags test -- -python # exclude tests with the 'python' tag # (the '--' is necessary to end the option list) The full name and base name of a test module are implicit tags for that module, e.g. module "test_xdebug.py" has tags "test_xdebug" and "xdebug". A TestCase's class name (with and without "TestCase") is an implicit tag for an test_* methods. A "test_foo" method also has "test_foo" and "foo" implicit tags. Tags can be added explicitly added: - to modules via a __tags__ global list; and - to individual test_* methods via a "tags" attribute list (you can use the testlib.tag() decorator for this). """ #TODO: # - Document how tests are found (note the special "test_cases()" and # "test_suite_class" hooks). # - See the optparse "TODO" below. # - Make the quiet option actually quiet. __version_info__ = (0, 6, 4) __version__ = '.'.join(map(str, __version_info__)) import os from os.path import join, basename, dirname, abspath, splitext, \ isfile, isdir, normpath, exists import sys import getopt import glob import time import types import tempfile import unittest from pprint import pprint import imp import optparse import logging import textwrap import traceback #---- globals and exceptions log = logging.getLogger("test") #---- exports generally useful to test cases class TestError(Exception): pass class TestSkipped(Exception): """Raise this to indicate that a test is being skipped. ConsoleTestRunner knows to interpret these at NOT failures. """ pass class TestFailed(Exception): pass def tag(*tags): """Decorator to add tags to test_* functions. Example: class MyTestCase(unittest.TestCase): @testlib.tag("knownfailure") def test_foo(self): #... """ def decorate(f): if not hasattr(f, "tags"): f.tags = [] f.tags += tags return f return decorate #---- timedtest decorator # Use this to assert that a test completes in a given amount of time. # This is from http://www.artima.com/forums/flat.jsp?forum=122&thread=129497 # Including here, becase it might be useful. # NOTE: Untested and I suspect some breakage. TOLERANCE = 0.05 class DurationError(AssertionError): pass def timedtest(max_time, tolerance=TOLERANCE): """ timedtest decorator decorates the test method with a timer when the time spent by the test exceeds max_time in seconds, an Assertion error is thrown. """ def _timedtest(function): def wrapper(*args, **kw): start_time = time.time() try: function(*args, **kw) finally: total_time = time.time() - start_time if total_time > max_time + tolerance: raise DurationError(('Test was too long (%.2f s)' % total_time)) return wrapper return _timedtest #---- module api class Test(object): def __init__(self, ns, testmod, testcase, testfn_name, testsuite_class=None): self.ns = ns self.testmod = testmod self.testcase = testcase self.testfn_name = testfn_name self.testsuite_class = testsuite_class # Give each testcase some extra testlib attributes for useful # introspection on TestCase instances later on. self.testcase._testlib_shortname_ = self.shortname() self.testcase._testlib_explicit_tags_ = self.explicit_tags() self.testcase._testlib_implicit_tags_ = self.implicit_tags() def __str__(self): return self.shortname() def __repr__(self): return "" % self.shortname() def shortname(self): bits = [self._normname(self.testmod.__name__), self._normname(self.testcase.__class__.__name__), self._normname(self.testfn_name)] if self.ns: bits.insert(0, self.ns) return '/'.join(bits) def _flatten_tags(self, tags): """Split tags with '/' in them into multiple tags. '/' is the reserved tag separator and allowing tags with embedded '/' results in one being unable to select those via filtering. As long as tag order is stable then presentation of these subsplit tags should be fine. """ flattened = [] for t in tags: flattened += t.split('/') return flattened def explicit_tags(self): tags = [] if hasattr(self.testmod, "__tags__"): tags += self.testmod.__tags__ if hasattr(self.testcase, "__tags__"): tags += self.testcase.__tags__ testfn = getattr(self.testcase, self.testfn_name) if hasattr(testfn, "tags"): tags += testfn.tags return self._flatten_tags(tags) def implicit_tags(self): tags = [ self.testmod.__name__.lower(), self._normname(self.testmod.__name__), self.testcase.__class__.__name__.lower(), self._normname(self.testcase.__class__.__name__), self.testfn_name, self._normname(self.testfn_name), ] if self.ns: tags.insert(0, self.ns) return self._flatten_tags(tags) def tags(self): return self.explicit_tags() + self.implicit_tags() def doc(self): testfn = getattr(self.testcase, self.testfn_name) return testfn.__doc__ or "" def _normname(self, name): if name.startswith("test_"): return name[5:].lower() elif name.startswith("test"): return name[4:].lower() elif name.endswith("TestCase"): return name[:-8].lower() else: return name def testmod_paths_from_testdir(testdir): """Generate test module paths in the given dir.""" for path in glob.glob(join(testdir, "test_*.py")): yield path for path in glob.glob(join(testdir, "test_*")): if not isdir(path): continue if not isfile(join(path, "__init__.py")): continue yield path def testmods_from_testdir(testdir): """Generate test modules in the given test dir. Modules are imported with 'testdir' first on sys.path. """ testdir = normpath(testdir) for testmod_path in testmod_paths_from_testdir(testdir): testmod_name = splitext(basename(testmod_path))[0] log.debug("import test module '%s'", testmod_path) try: iinfo = imp.find_module(testmod_name, [dirname(testmod_path)]) testabsdir = abspath(testdir) sys.path.insert(0, testabsdir) old_dir = os.getcwd() os.chdir(testdir) try: testmod = imp.load_module(testmod_name, *iinfo) finally: os.chdir(old_dir) sys.path.remove(testabsdir) except TestSkipped, ex: log.warn("'%s' module skipped: %s", testmod_name, ex) except Exception, ex: log.warn("could not import test module '%s': %s (skipping, " "run with '-d' for full traceback)", testmod_path, ex) if log.isEnabledFor(logging.DEBUG): traceback.print_exc() else: yield testmod def testcases_from_testmod(testmod): """Gather tests from a 'test_*' module. Returns a list of TestCase-subclass instances. One instance for each found test function. In general the normal unittest TestLoader.loadTests*() semantics are used for loading tests with some differences: - TestCase subclasses beginning with '_' are skipped (presumed to be internal). - If the module has a top-level "test_cases", it is called for a list of TestCase subclasses from which to load tests (can be a generator). This allows for run-time setup of test cases. - If the module has a top-level "test_suite_class", it is used to group all test cases from that module into an instance of that TestSuite subclass. This allows for overriding of test running behaviour. """ class TestListLoader(unittest.TestLoader): suiteClass = list loader = TestListLoader() if hasattr(testmod, "test_cases"): try: for testcase_class in testmod.test_cases(): if testcase_class.__name__.startswith("_"): log.debug("skip private TestCase class '%s'", testcase_class.__name__) continue for testcase in loader.loadTestsFromTestCase(testcase_class): yield testcase except Exception, ex: testmod_path = testmod.__file__ if testmod_path.endswith(".pyc"): testmod_path = testmod_path[:-1] log.warn("error running test_cases() in '%s': %s (skipping, " "run with '-d' for full traceback)", testmod_path, ex) if log.isEnabledFor(logging.DEBUG): traceback.print_exc() else: class_names_skipped = [] for testcases in loader.loadTestsFromModule(testmod): for testcase in testcases: class_name = testcase.__class__.__name__ if class_name in class_names_skipped: pass elif class_name.startswith("_"): log.debug("skip private TestCase class '%s'", class_name) class_names_skipped.append(class_name) else: yield testcase def tests_from_manifest(testdir_from_ns): """Return a list of `testlib.Test` instances for each test found in the manifest. There will be a test for (a) each "test*" function of (b) each TestCase-subclass in (c) each "test_*" Python module in (d) each test dir in the manifest. If a "test_*" module has a top-level "test_suite_class", it will later be used to group all test cases from that module into an instance of that TestSuite subclass. This allows for overriding of test running behaviour. """ for ns, testdir in testdir_from_ns.items(): for testmod in testmods_from_testdir(testdir): if hasattr(testmod, "test_suite_class"): testsuite_class = testmod.test_suite_class if not issubclass(testsuite_class, unittest.TestSuite): testmod_path = testmod.__file__ if testmod_path.endswith(".pyc"): testmod_path = testmod_path[:-1] log.warn("'test_suite_class' of '%s' module is not a " "subclass of 'unittest.TestSuite': ignoring", testmod_path) else: testsuite_class = None for testcase in testcases_from_testmod(testmod): try: yield Test(ns, testmod, testcase, testcase._testMethodName, testsuite_class) except AttributeError: # Python 2.4 and older: yield Test(ns, testmod, testcase, testcase._TestCase__testMethodName, testsuite_class) def tests_from_manifest_and_tags(testdir_from_ns, tags): include_tags = [tag.lower() for tag in tags if not tag.startswith('-')] exclude_tags = [tag[1:].lower() for tag in tags if tag.startswith('-')] for test in tests_from_manifest(testdir_from_ns): test_tags = [t.lower() for t in test.tags()] matching_exclude_tags = [t for t in exclude_tags if t in test_tags] if matching_exclude_tags: #log.debug("test '%s' matches exclude tag(s) '%s': skipping", # test.shortname(), "', '".join(matching_exclude_tags)) continue if not include_tags: yield test else: for tag in include_tags: if tag not in test_tags: #log.debug("test '%s' does not match tag '%s': skipping", # test.shortname(), tag) break else: #log.debug("test '%s' matches tags: %s", test.shortname(), # ' '.join(tags)) yield test def test(testdir_from_ns, tags=[], setup_func=None): log.debug("test(testdir_from_ns=%r, tags=%r, ...)", testdir_from_ns, tags) if setup_func is not None: setup_func() tests = list(tests_from_manifest_and_tags(testdir_from_ns, tags)) if not tests: return None # Groups test cases into a test suite class given by their test module's # "test_suite_class" hook, if any. suite = unittest.TestSuite() suite_for_testmod = None testmod = None for test in tests: if test.testmod != testmod: if suite_for_testmod is not None: suite.addTest(suite_for_testmod) suite_for_testmod = (test.testsuite_class or unittest.TestSuite)() testmod = test.testmod suite_for_testmod.addTest(test.testcase) if suite_for_testmod is not None: suite.addTest(suite_for_testmod) runner = ConsoleTestRunner(sys.stdout) result = runner.run(suite) return result def list_tests(testdir_from_ns, tags): # Say I have two test_* modules: # test_python.py: # __tags__ = ["guido"] # class BasicTestCase(unittest.TestCase): # def test_def(self): # def test_class(self): # class ComplexTestCase(unittest.TestCase): # def test_foo(self): # def test_bar(self): # test_perl/__init__.py: # __tags__ = ["larry", "wall"] # class BasicTestCase(unittest.TestCase): # def test_sub(self): # def test_package(self): # class EclecticTestCase(unittest.TestCase): # def test_foo(self): # def test_bar(self): # The short-form list output for this should look like: # python/basic/def [guido] # python/basic/class [guido] # python/complex/foo [guido] # python/complex/bar [guido] # perl/basic/sub [larry, wall] # perl/basic/package [larry, wall] # perl/eclectic/foo [larry, wall] # perl/eclectic/bar [larry, wall] log.debug("list_tests(testdir_from_ns=%r, tags=%r)", testdir_from_ns, tags) tests = list(tests_from_manifest_and_tags(testdir_from_ns, tags)) if not tests: return WIDTH = 78 if log.isEnabledFor(logging.INFO): # long-form for i, t in enumerate(tests): if i: print testfile = t.testmod.__file__ if testfile.endswith(".pyc"): testfile = testfile[:-1] print "%s:" % t.shortname() print " from: %s#%s.%s" \ % (testfile, t.testcase.__class__.__name__, t.testfn_name) wrapped = textwrap.fill(' '.join(t.tags()), WIDTH-10) print " tags: %s" % _indent(wrapped, 8, True) if t.doc(): print _indent(t.doc(), width=2) else: for t in tests: line = t.shortname() + ' ' if t.explicit_tags(): line += '[%s]' % ' '.join(t.explicit_tags()) print line #---- text test runner that can handle TestSkipped reasonably class ConsoleTestResult(unittest.TestResult): """A test result class that can print formatted text results to a stream. Used by ConsoleTestRunner. """ separator1 = '=' * 70 separator2 = '-' * 70 def __init__(self, stream): unittest.TestResult.__init__(self) self.skips = [] self.stream = stream def getDescription(self, test): if test._testlib_explicit_tags_: return "%s [%s]" % (test._testlib_shortname_, ', '.join(test._testlib_explicit_tags_)) else: return test._testlib_shortname_ def startTest(self, test): unittest.TestResult.startTest(self, test) self.stream.write(self.getDescription(test)) self.stream.write(" ... ") def addSuccess(self, test): unittest.TestResult.addSuccess(self, test) self.stream.write("ok\n") def addSkip(self, test, err): why = str(err[1]) self.skips.append((test, why)) self.stream.write("skipped (%s)\n" % why) def addError(self, test, err): if isinstance(err[1], TestSkipped): self.addSkip(test, err) else: unittest.TestResult.addError(self, test, err) self.stream.write("ERROR\n") def addFailure(self, test, err): unittest.TestResult.addFailure(self, test, err) self.stream.write("FAIL\n") def printSummary(self): self.stream.write('\n') self.printErrorList('ERROR', self.errors) self.printErrorList('FAIL', self.failures) def printErrorList(self, flavour, errors): for test, err in errors: self.stream.write(self.separator1 + '\n') self.stream.write("%s: %s\n" % (flavour, self.getDescription(test))) self.stream.write(self.separator2 + '\n') self.stream.write("%s\n" % err) class ConsoleTestRunner(object): """A test runner class that displays results on the console. It prints out the names of tests as they are run, errors as they occur, and a summary of the results at the end of the test run. Differences with unittest.TextTestRunner: - adds support for *skipped* tests (those that raise TestSkipped) - no verbosity option (only have equiv of verbosity=2) - test "short desc" is it 3-level tag name (e.g. 'foo/bar/baz' where that identifies: 'test_foo.py::BarTestCase.test_baz'. """ def __init__(self, stream=sys.stderr): self.stream = stream def run(self, test_or_suite, test_result_class=ConsoleTestResult): """Run the given test case or test suite.""" result = test_result_class(self.stream) start_time = time.time() test_or_suite.run(result) time_taken = time.time() - start_time result.printSummary() self.stream.write(result.separator2 + '\n') self.stream.write("Ran %d test%s in %.3fs\n\n" % (result.testsRun, result.testsRun != 1 and "s" or "", time_taken)) details = [] num_skips = len(result.skips) if num_skips: details.append("%d skip%s" % (num_skips, (num_skips != 1 and "s" or ""))) if not result.wasSuccessful(): num_failures = len(result.failures) if num_failures: details.append("%d failure%s" % (num_failures, (num_failures != 1 and "s" or ""))) num_errors = len(result.errors) if num_errors: details.append("%d error%s" % (num_errors, (num_errors != 1 and "s" or ""))) self.stream.write("FAILED (%s)\n" % ', '.join(details)) elif details: self.stream.write("OK (%s)\n" % ', '.join(details)) else: self.stream.write("OK\n") return result #---- internal support stuff # Recipe: indent (0.2.1) def _indent(s, width=4, skip_first_line=False): """_indent(s, [width=4]) -> 's' indented by 'width' spaces The optional "skip_first_line" argument is a boolean (default False) indicating if the first line should NOT be indented. """ lines = s.splitlines(1) indentstr = ' '*width if skip_first_line: return indentstr.join(lines) else: return indentstr + indentstr.join(lines) #---- mainline #TODO: pass in add_help_option=False and add it ourself here. ## Optparse's handling of the doc passed in for -h|--help handling is ## abysmal. Hence we'll stick with getopt. #def _parse_opts(args): # """_parse_opts(args) -> (options, tags)""" # usage = "usage: %prog [OPTIONS...] [TAGS...]" # parser = optparse.OptionParser(prog="test", usage=usage, # description=__doc__) # parser.add_option("-v", "--verbose", dest="log_level", # action="store_const", const=logging.DEBUG, # help="more verbose output") # parser.add_option("-q", "--quiet", dest="log_level", # action="store_const", const=logging.WARNING, # help="quieter output") # parser.add_option("-l", "--list", dest="action", # action="store_const", const="list", # help="list available tests") # parser.set_defaults(log_level=logging.INFO, action="test") # opts, raw_tags = parser.parse_args() # # # Trim '.py' from user-supplied tags. They might have gotten there # # via shell expansion. # ... # # return opts, raw_tags def _parse_opts(args, default_tags): """_parse_opts(args) -> (log_level, action, tags)""" opts, raw_tags = getopt.getopt(args, "hvqdlL:n", ["help", "verbose", "quiet", "debug", "list", "no-default-tags"]) log_level = logging.WARN action = "test" no_default_tags = False for opt, optarg in opts: if opt in ("-h", "--help"): action = "help" elif opt in ("-v", "--verbose"): log_level = logging.INFO elif opt in ("-q", "--quiet"): log_level = logging.ERROR elif opt in ("-d", "--debug"): log_level = logging.DEBUG elif opt in ("-l", "--list"): action = "list" elif opt in ("-n", "--no-default-tags"): no_default_tags = True elif opt == "-L": # Optarg is of the form ':', e.g. # "codeintel:DEBUG", "codeintel.db:INFO". lname, llevelname = optarg.split(':', 1) llevel = getattr(logging, llevelname) logging.getLogger(lname).setLevel(llevel) # Clean up the given tags. if no_default_tags: tags = [] else: tags = default_tags for raw_tag in raw_tags: if splitext(raw_tag)[1] in (".py", ".pyc", ".pyo", ".pyw") \ and exists(raw_tag): # Trim '.py' from user-supplied tags if it looks to be from # shell expansion. tags.append(splitext(raw_tag)[0]) elif '/' in raw_tag: # Split one '/' to allow the shortname from the test listing # to be used as a filter. tags += raw_tag.split('/') else: tags.append(raw_tag) return log_level, action, tags def harness(testdir_from_ns={None: os.curdir}, argv=sys.argv, setup_func=None, default_tags=None): """Convenience mainline for a test harness "test.py" script. "testdir_from_ns" (optional) is basically a set of directories in which to look for test cases. It is a dict with: : where is a (short) string that becomes part of the included test names and an implicit tag for filtering those tests. By default the current dir is use with an empty namespace: {None: os.curdir} "setup_func" (optional) is a callable that will be called once before any tests are run to prepare for the test suite. It is not called if no tests will be run. "default_tags" (optional) Typically, if you have a number of test_*.py modules you can create a test harness, "test.py", for them that looks like this: #!/usr/bin/env python if __name__ == "__main__": retval = testlib.harness() sys.exit(retval) """ if not logging.root.handlers: logging.basicConfig() try: log_level, action, tags = _parse_opts(argv[1:], default_tags or []) except getopt.error, ex: log.error(str(ex) + " (did you need a '--' before a '-TAG' argument?)") return 1 log.setLevel(log_level) if action == "help": print __doc__ return 0 if action == "list": return list_tests(testdir_from_ns, tags) elif action == "test": result = test(testdir_from_ns, tags, setup_func=setup_func) if result is None: return None return len(result.errors) + len(result.failures) else: raise TestError("unexpected action/mode: '%s'" % action) preprocess-1.1.0+ds.orig/src/0000755000000000000000000000000011573617731014537 5ustar rootrootpreprocess-1.1.0+ds.orig/src/exe/0000755000000000000000000000000011573617731015320 5ustar rootrootpreprocess-1.1.0+ds.orig/src/exe/Makefile.win0000644000000000000000000000106011120667260017537 0ustar rootroot# A Makefile to do this: launcher.cpp -> foo.exe APPNAME=preprocess # for release: CFLAGS=-D_CONSOLE -D_MBCS -DWIN32 -W3 -Ox -DNDEBUG -D_NDEBUG -MD LDFLAGS=/subsystem:console kernel32.lib user32.lib gdi32.lib advapi32.lib shlwapi.lib # for debug: # CFLAGS = -D_CONSOLE -D_MBCS /DWIN32 /Zi /Od /DDEBUG /D_DEBUG /MDd # LDFLAGS += /DEBUG $(APPNAME).exe: launcher.cpp cl -nologo $(CFLAGS) -c launcher.cpp link -nologo $(LDFLAGS) launcher.obj -out:$(APPNAME).exe clean: if exist launcher.obj; del launcher.obj if exist $(APPNAME).exe; del $(APPNAME).exe preprocess-1.1.0+ds.orig/src/exe/launcher.cpp0000644000000000000000000002650611120667260017624 0ustar rootroot/* * Copyright (c) 2002 Trent Mick * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Console launch executable. * * This program exists solely to launch: * python /.py * on Windows. ".py" must be in the same directory. * * Rationale: * - On some Windows flavours .py *can* be put on the PATHEXT to be * able to find ".py" if it is on the PATH. This is fine * until you need shell redirection to work. It does NOT for * extensions to PATHEXT. Redirection *does* work for "python *