Skip to content

Commit dec7b77

Browse files
authored
Add tests to PR checks (#361)
* Setup pytest * Add some tests for resource classes * Add instructions for running tests to contributing docs * Use a gnomAD bucket for test paths
1 parent ea4648a commit dec7b77

File tree

6 files changed

+73
-2
lines changed

6 files changed

+73
-2
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
- name: Run Pylint
3131
run: ./lint --disable=W
3232
- name: Check formatting
33-
run: black --check gnomad
33+
run: black --check gnomad tests
34+
- name: Run tests
35+
run: python -m pytest
3436
docs:
3537
name: Build documentation
3638
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ Use [Black](https://black.readthedocs.io/) to format code.
3636
black gnomad
3737
```
3838

39+
## Running tests
40+
41+
Run tests using [pytest](https://docs.pytest.org/en/stable/).
42+
43+
```
44+
python -m pytest
45+
```
46+
3947
## Building documentation
4048

4149
See instructions in [docs/README.md](./docs/README.md).

lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
cd "$(dirname "$0")"
44

5-
PYTHONPATH=$PYTHONPATH:$(pwd) pylint "$@" gnomad
5+
PYTHONPATH=$PYTHONPATH:$(pwd) pylint "$@" gnomad tests

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
testpaths = tests

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
black==19.10b0
22
pre-commit==2.10.1
33
pylint
4+
pytest==6.2.3
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from unittest.mock import patch
2+
3+
from gnomad.resources import resource_utils
4+
5+
6+
class TestTableResource:
7+
@patch("hail.read_table")
8+
def test_read_table(self, read_table):
9+
resource = resource_utils.TableResource("gs://gnomad-public/table.ht")
10+
11+
ds = resource.ht()
12+
read_table.assert_called_with("gs://gnomad-public/table.ht")
13+
assert ds == read_table.return_value
14+
15+
16+
class TestMatrixTableResource:
17+
@patch("hail.read_matrix_table")
18+
def test_read_matrix_table(self, read_matrix_table):
19+
resource = resource_utils.MatrixTableResource(
20+
"gs://gnomad-public/matrix_table.mt"
21+
)
22+
23+
ds = resource.mt()
24+
read_matrix_table.assert_called_with("gs://gnomad-public/matrix_table.mt")
25+
assert ds == read_matrix_table.return_value
26+
27+
28+
class TestPedigreeResource:
29+
@patch("hail.Pedigree.read")
30+
def test_read_pedigree(self, read_pedigree):
31+
resource = resource_utils.PedigreeResource("gs://gnomad-public/pedigree.ped")
32+
33+
ds = resource.pedigree()
34+
read_pedigree.assert_called()
35+
print(read_pedigree.call_args)
36+
assert read_pedigree.call_args[0][0] == "gs://gnomad-public/pedigree.ped"
37+
assert ds == read_pedigree.return_value
38+
39+
@patch("hail.import_fam")
40+
def test_read_fam(self, import_fam):
41+
resource = resource_utils.PedigreeResource("gs://gnomad-public/pedigree.fam")
42+
43+
ds = resource.ht()
44+
import_fam.assert_called()
45+
assert import_fam.call_args[0][0] == "gs://gnomad-public/pedigree.fam"
46+
assert ds == import_fam.return_value
47+
48+
49+
class TestBlockMatrixResource:
50+
@patch("hail.linalg.BlockMatrix.read")
51+
def test_read_block_matrix(self, read_block_matrix):
52+
resource = resource_utils.BlockMatrixResource(
53+
"gs://gnomad-public/block_matrix.bm"
54+
)
55+
56+
ds = resource.bm()
57+
read_block_matrix.assert_called_with("gs://gnomad-public/block_matrix.bm")
58+
assert ds == read_block_matrix.return_value

0 commit comments

Comments
 (0)