Skip to content

Testing

Anders Markvardsen edited this page Sep 24, 2019 · 26 revisions

The following document provides instructions as to how to setup an environment for testing

Testing with Docker

Download and install Docker (you may need to create an account)

Installing Docker on Mac

Only possible for Mac OS Sierra and above

Follow the instructions on the Docker website (essentially just creating an account and clicking a download link).

Installing Docker on Linux

CentOS based

Set up repository

sudo yum install -y yum-utils device-mapper-persistent-data lvms
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install Docker CE

sudo yum install docker-ce

Start Docker

sudo systemctl start docker

Verify Docker is running (optional)

sudo docker run hello-world

Ubuntu based

Set up repository (for x86_64/amd64 architecture - see https://docs.docker.com/install/linux/docker-ce/ubuntu/ for others)

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Install Docker CE

sudo apt-get install docker-ce

Verify Docker is running (optional)

sudo docker run hello-world

Running tests in Docker

Start Docker (required once for Mac/Windows, not required for Linux).

For Windows, do not include sudo.

Pull to ensure most recent image:

sudo docker pull tfarmer/mdmc_dependencies

start bash in docker container of mdmc_dependencies:

docker run -it tfarmer/mdmc_dependencies bash

Use pip to install MDMC. Specify the branch after @, e.g. for refinement branch:

pip install -e git+https://github.com/MDMCproject/MDMCv0.2_pilot.git@refinement#egg=MDMC

or to check the main (master) branch out do:

pip install -e git+https://github.com/MDMCproject/MDMCv0.2_pilot.git#egg=MDMC

NB: This will install the src into /src, so to easily keep track of where this is (useful for testing, see below), it might be beneficial to navigate to /usr before this pip install.

Enter GitHub username

Enter GitHub password (it may take a few minutes for GitHub to respond and for pip to start installing)

Starting closed containers (for persistent environment/data)

In order to access a container that you have previously used, but has now exited, do the following:

Display all exited and/or running docker containers:

docker container ls -all

Note down the container name of the most recently exited container which has a command "/bin/bash" or "bash". If the STATUS of this container is Up ignore the step just below. If the STATUS is Exited then first re-start the container:

docker start container_name

Then enter the container at the bash prompt using:

docker exec -it container_name bash

The container should be in the same state in which it was previously stopped.

It should always be possible to restart this container in the same way (i.e. start and the exec) as long as the container is not pruned (this is a docker command which removes all stopped containers. If you wish to prune stopped container then just make sure to start (you don't need to exec) any containers which you do not want removed.

Using Jupyter notebooks in Docker containers

To use a Jupyter notebook from a Docker container, run the container with an open port 8888:

docker run -it -p 8888:8888 tfarmer/mdmc_dependencies

All MDMC docker containers should have Jupyter installed (but if not, you can install it with pip install jupyter). So that Jupyter can be accessed outside of the container, start it with:

jupyter notebook --ip 0.0.0.0 --no-browser

If you are running as root, Jupyter may not start and return a warning instead. If so, use:

jupyter notebook --ip 0.0.0.0 --no-browser --allow-root

This should provide two methods for accessing the notebook in the local machine, although the file approach doesn't work for me personally. If using one of the URLs, you will need to edit the URL provided. For instance if Jupyter prints:

Or copy and paste one of these URLs:
    http://(62098fe3e7da or 127.0.0.1):8888/?token=aa3acd2609aba7ba6b059f9a3e4ca908089b76717d3c4d99

then copy and paste the following into a browser:

http://127.0.0.1:8888/?token=aa3acd2609aba7ba6b059f9a3e4ca908089b76717d3c4d99

This should allow you to access the notebook in the same manner as if you were running Jupyter locally.

Running unit/system tests with pytest

Pytest is included within the container. To run a unit or system test, navigate to the MDMC test directory (relative to wherever pip install was called):

cd /src/mdmc/tests/

Pytest will test all files in all subdirectories which start with 'test'. To test specific unit tests, navigate to the relevant directory before running the following command. If running pytest from the main test directory, it is recommended that you run with the following flags:

python -m pytest -vv --ignore="./system_tests"

-vv provides very verbose output (useful in all cases), and --ignore ./system_tests excludes the system tests; these take a 5-10 minutes to run and so should be excluded unless necessary.

Clone this wiki locally