Skip to content

Testing the SDK Locally

emmastephenson edited this page Apr 5, 2023 · 1 revision

SDK Testing

The SDK unit tests use poetry. To get these unit tests running locally, follow the following steps.

Setting up your virtual network

Instructions differ for Windows and Unix.

On a Windows machine

  1. On your terminal (command line) go to the base folder for phdi - which should be phdi. (example: C:\REPOS\phdi - for my machine)
  2. Create a virtual environment (named venv) at this level/folder python -m venv .venv
  3. Activate your virtual environment at this same level/folder .venv/Scripts/Activate.ps1
  4. Once activated your terminal command prompt will look something like this: (.venv) PS <base folder> ie... for my machine: (.venv) PS C:\REPOS\phdi

For Linux or Mac

  1. On your terminal (command line) go to the base folder for phdi - which should be phdi. (example: cd phdi)
  2. Create a virtual environment (named venv) at this level/folder python -m venv .venv
  3. Activate your virtual environment at this same level/folder source .venv/bin/activate for bash/zsh. See commands for all shells here.
  4. Once activated your terminal command prompt will look something like this: phdi py

Running the tests

  1. Clear your poetry cache poetry cache clear --all .

    a. Choose 'Y' to clear

  2. Install all dependent packages using poetry poetry install

  3. Get to the tests folder under phdi: cd tests

  4. You can run the tests a few different ways....

    a. pytest

    b. python pytest

    c. pytest -vv for more verbose response

  5. If you only want to run specific tests in a subfolder, just move to the subfolder that contains the test and run pytest or pytest -vv

Setting up your test MPI database for record linkage testing

  1. Confirm that you have Docker installed by running docker -v in your terminal. If you do not see a response similar what is shown below, follow these instructions to install Docker.

  2. Download a copy of the Docker Postgres image: docker pull postgres

  3. Start up the Docker container with Postgres: docker run --name pgsql_dev -e POSTGRES_PASSWORD=pw -p 5432:5432 postgres

    a. The settings above are the same settings used in the record linkage tests and are recommended, but you can change the settings (e.g., the port -p) if needed.

  4. In a new terminal window, connect to the Postgres container you just started by running docker exec -it pgsql_dev sh and then psql -h localhost -U postgres

  5. Create a database called testdb by running create database testdb;

  6. Check that the database has been created: \l

    You should now be able to run the tests in phdi\tests\linkage\test_postgres_mpi_connector.py locally and write additional tests to your local database.