5.4. Unit tests

It is possible to test python script 'on the fly' as in the example: On-the-fly interscript for test 10 follows.
Start interscript section from tutorial.pak
   396: @head(1,'A python test')
   397: Test the test_python function.
   398: @test_python(hlevel=2,descr='A simple test',source_terminator='//')
   399: print 'A simple test'
   400: //
End interscript section from tutorial.pak
Test output at ../tests/output/test_10.html. Logfile at ../tests/output/test_10.log.

The test is also registered in a table of tests.

It is also possible to provide expected output: Interscript will verify your code by comparing the expected and actual output, and print a difference table if the test failed. Note that the difference table is only available if the module "interscript.utilities.diff" is available and operates correctly: the current implementation uses GNU diff invoked using "os.system()". Here's an example that veifies OK: On-the-fly interscript for test 11 follows.

Start interscript section from tutorial.pak
   413: @head(1,'A diff OK test')
   414: Test the test_python function.
   415: @test_python(hlevel=2,\
   416:   descr='A diff OK test',source_terminator='//', expected_terminator='//')
   417: print 'A simple diff test'
   418: print 'A simple diff test line 2'
   419: print 'A simple diff test line 3'
   420: //
   421: A simple diff test
   422: A simple diff test line 2
   423: A simple diff test line 3
   424: //
End interscript section from tutorial.pak
Test output at ../tests/output/test_11.html. Logfile at ../tests/output/test_11.log.

And here's one that should fail: On-the-fly interscript for test 12 follows.

Start interscript section from tutorial.pak
   428: @head(1,'A diff fail test')
   429: Test the test_python function.
   430: @test_python(hlevel=2,\
   431:   descr='A diff test',source_terminator='//', expected_terminator='//')
   432: print 'A simple diff test'
   433: print 'A simple diff test line 2'
   434: print 'A simple diff test line 3'
   435: //
   436: A simple diff test
   437: A simple diff test line 2 CHANGED
   438: A simple diff test line 3
   439: //
End interscript section from tutorial.pak
Test output at ../tests/output/test_12.html. Logfile at ../tests/output/test_12.log.


5.4.1. Weaver Control
5.4.2. Perl hates @