Testing Your Install

There are three steps to testing your install:

  1. Make sure Python is working.
  2. Test that Python can find your Opus packages.
  3. (Optional) Check that the Opus packages pass their unit tests.

Making Sure Python is Working

Open a command window. 

Now check that Python itself is installed and working by typing python at the command prompt to start a Python session. For example, here are the results for this on Windows:

C:\>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>

Once you’re in Python, type in a simple expression and see if you get a reasonable answer:

>>> 3+4
7
>>>

Can Python find the Opus packages?

Now test that the opus_core and urbansim packages are downloaded and that Python can find them by checking that you can get the package info for them:

>>> import opus_core.opus_package_info
>>> opus_core.opus_package_info.package().info()
Opus package opus_core
Required Opus packages for opus_core: []
Required external packages for opus_core: ['numpy>=1.0.4', 'matplotlib>=0.91.2', 'sqlalchemy>=0.4.5', 'scipy>=0.7']

>>> import urbansim.opus_package_info
>>> urbansim.opus_package_info.package().info()
Opus package urbansim
Required Opus packages for urbansim: ['opus_core']
Required external packages for urbansim: []
>>>

Do the unit tests pass?

As an optional part of testing the installation, all of the base Opus packages have unit tests that should succeed.

The unit tests in each Opus package are set up to run as standalone Python programs: simply invoke Python on the file containing the unit test. For instance, to test the Python module opus_core.tests.test_sampling_toolbox.py, open a command shell, connect to the directory opusworkspace/opus_core/tests, and type:

python test_sampling_toolbox.py
.......
----------------------------------------------------------------------
Ran 7 tests in 0.084s

OK

where a period gets printed each time a test is run, perhaps along with some additional information, followed by a summary at the end.  If you have installed Opus to a different directory, use that path in the command, above.

To run all of the unit tests defined in the opus_core package, and thus perform a more comprehensive test of your installation, invoke opus_core’s all_tests.py über-test module:

python C:\opusworkspace\opus_core\tests\all_tests.py

WARNING: Could not import gdal library. Skipping test_input_numpy_output_geotiff.

================================================================================
opus_core.VVV_lagLLL.VVV_lagLLLTests
test_lag_variable
================================================================================
-------------------------------------( OK )-------------------------------------

================================================================================
opus_core.store.attribute_cache.AttributeCacheTests
test_determine_field_names
================================================================================
-------------------------------------( OK )-------------------------------------

================================================================================
opus_core.store.attribute_cache.AttributeCacheTests
test_getting_data_from_prior_years
================================================================================
Loading attr From Cache cache_directory c:\docume~1\socha\locals~1\temp\opus_tmp39upx7\cache\2000 (testdata)
Loading id From Cache cache_directory c:\docume~1\socha\locals~1\temp\opus_tmp39upx7\cache\2000 (testdata)
-------------------------------------( OK )-------------------------------------

(and so on and so on ...)

Cautions: particularly if you don't have a fast machine, running all_tests.py may be time consuming, but you can always cancel the tests part way through. Also, some of the unit tests depend on having MySQL available -- if you don't have it, those tests won't pass. (Other stuff will still run fine however.)

Every Opus package has a ‘tests’ directory with a ‘all_tests.py’ module. The ‘all_tests’ module will scan all files in the package searching for unit tests. It will run all that it finds. Note: unit tests that are ‘hidden’ behind an if __name__ == '__main__': check will not be found.

As part of our automated build process at CUSPA, we automatically run ‘all_tests’ every time a new version of a package is checked into our subversion repository.