Pressio/pressio4py

proper build structure of tests

fnrizzi opened this issue · 3 comments

Right now we have to copy the python test files into the same directory as the .so file so we can easily import pressio4py into the python test files. We want to place the test files in the correct subfolders. One option is to add a temporary python path in the beginning of the .py test file so that the python file doesn’t have to be in the same directory as the python .so file. Alternatively, we need to look for a method to somehow temporarily add a path to the python file (similar to the addpath functionality) but using a cmake directive in case we might need to change the directory structure.

Right now, when you build you get this structure (subdirectories are marked with *):

*burgers1d_galerkin
*burgers1d_lspg
burgers1d_sparse_jacobian.py
cmake_install.cmake
CMakeCache.txt
*CMakeFiles
Makefile
pressio4py.cpython-36m-darwin.so
test_burgers1d_galerkin.py
test_burgers1d_lspg.py
test_decoder.py
test_wrapper_module.cpython-36m-darwin.so
test_wrapper.py
*tests

what I would like is to have all tests inside tests, which means tests should have the same structure that is has in the source as follows:

tests
  /regression
    /burgers1d_galerkin
    /burgers1d_lapg
  /unit
    test_decoder.py
    test_wrapper.py 
    test_wrapper_module.cpython-36m-darwin.so

and the top-level build then looks like this:

cmake_install.cmake
CMakeCache.txt
*CMakeFiles
Makefile
pressio4py.cpython-36m-darwin.so
*tests

After some quick googling, there might be three options here:

  1. Move all test files to their respective folders and just add an "addpath" line to the beginning of the test*py file that includes the directory of the .so file
  2. There might be an option in pytest to temporarily define a python path when you call pytest from the command line. But then the user has to know where the .so file is in the build directory.
  3. CMAKE's ctest function might be able to handle the execution of pytest all together. I think you can define pytest as the command to perform the test in CMAKE. This last option could work in combination with (1) and (2).

I will try (1) since that is the easiest, and then see if (2) or (3) is a possibility.

  1. Move all test files to their respective folders and just add an "addpath" line to the beginning of the test*py file that includes the directory of the .so file

This is fine with me!
Please keep the structure consistent between source and build like said above.

We can now do this. We just need to setup the relative paths correctly so that when we import modules in the test scripts it find the right libraries. Let's discuss soon.