From: Arlindo da S. <da...@al...> - 2008-03-08 21:10:05
|
Wes et al, I just added a very rudimentary test suite, using PyUnit to organize the tests. This is similar to what I did for GrADS; I have some notes here: http://opengrads.org/wiki/index.php?title=PyTests:_GrADS_Test_Suite The wgrib2 implementation is simpler than the one in grads as we only have one executable (wgrib2) and only one type of input file (grib 2). After you build wgrib2, just type % make check and it will run all tests. We need more test cases!!! In principle, each command line option should have its own unit test. Right now I have a single test data file (under data/model_25.grb2) something the Mike Fiorino prepared for me for testing grads v2. This single file could be used for most if not all test cases. To add a new test, just add a new python function that starts with "test_" in file pytests/TestModelFile.py - no other change is required. For example, to test the -min/-max options I added the function: def test_opt_minmax(self): result = self.g2('-d 1 -min -max ') self.assertEqual(result[0],'1:0:min=10664.5:max=12531.1\n') result = self.g2('-d 33 -min -max ') self.assertEqual(result[0],'33:322100:min=95073.8:max=104675\n') result = self.g2('-d 67 -min -max') self.assertEqual(result[0],'67:676013:min=94670.3:max=104569\n') The statement result = self.g2('-d 1 -min -max ') runs ../src/wgrib2 -d 1 -min -max data/model_25.grb2 and captures the result in 'result'. The statement: self.assertEqual(result[0],'1:0:min=10664.5:max=12531.1\n') compares the result with an expected (hard coded) outcome. This receipt can be used for all the options producing simple ASCII output. For binary files, one could produce the binary file and check the md5sum against a hardcoded value, this way keeping the distribution tarball small enough. I can help with the python wiring of the test cases, but it would be better for people familiar with wgrib2 (i.e., developers) to come up with the actual tests. Take my word for it: a test suite is worth its weight in gold, specially when porting to a new platform. To get the latest wgrib2 sources: % gacvs co -P Wgrib2 and you should get the new pytests/ directory, including the test data. Arlindo -- Arlindo da Silva da...@al... |