|
| 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