Skip to content

Commit

Permalink
refactor hail context management in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-schultz committed Oct 21, 2022
1 parent 76dfaec commit d5bf722
Show file tree
Hide file tree
Showing 37 changed files with 26 additions and 149 deletions.
5 changes: 5 additions & 0 deletions hail/python/hail/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def init(doctest_namespace):
os.chdir(olddir)


@pytest.fixture(autouse=True)
def reset_randomness(init):
hl.reset_global_randomness()


def generate_datasets(doctest_namespace):
doctest_namespace['hl'] = hl
doctest_namespace['np'] = np
Expand Down
12 changes: 10 additions & 2 deletions hail/python/test/hail/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import pytest

from hail import current_backend
from hail import current_backend, init
from hail.backend.service_backend import ServiceBackend
from .helpers import startTestHailContext, stopTestHailContext


def pytest_collection_modifyitems(config, items):
Expand Down Expand Up @@ -33,8 +34,15 @@ def ensure_event_loop_is_initialized_in_test_thread():
asyncio.set_event_loop(asyncio.new_event_loop())


@pytest.fixture(scope="session", autouse=True)
def init_hail():
startTestHailContext()
yield
stopTestHailContext()


@pytest.fixture(autouse=True)
def set_query_name(request):
def set_query_name(init_hail, request):
backend = current_backend()
if isinstance(backend, ServiceBackend):
backend.batch_attributes = dict(name=request.node.name)
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/experimental/test_codec.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import hail as hl
from test.hail.helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext

UNBLOCKED_UNBUFFERED_SPEC = '{"name":"StreamBufferSpec"}'


Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/experimental/test_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from ..helpers import *
from hail.utils import new_temp_file

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
@fails_service_backend()
Expand Down
5 changes: 1 addition & 4 deletions hail/python/test/hail/experimental/test_vcf_combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from hail.experimental.vcf_combiner import vcf_combiner as vc
from hail.utils.java import Env
from hail.utils.misc import new_temp_file
from ..helpers import resource, startTestHailContext, stopTestHailContext, fails_local_backend, fails_service_backend

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext
from ..helpers import resource, fails_local_backend, fails_service_backend


all_samples = ['HG00308', 'HG00592', 'HG02230', 'NA18534', 'NA20760',
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/expr/test_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import hail.ir as ir
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


def _test_many_equal(test_cases):
expressions = [t[0] for t in test_cases]
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/expr/test_ndarrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

from hail.utils.java import FatalError, HailUserError

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext

def assert_ndarrays(asserter, exprs_and_expecteds):
exprs, expecteds = zip(*exprs_and_expecteds)

Expand Down
4 changes: 0 additions & 4 deletions hail/python/test/hail/expr/test_show.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from ..helpers import startTestHailContext, stopTestHailContext
import unittest

import hail as hl

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def test(self):
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/expr/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from ..helpers import *
from hail.utils.java import Env

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def types_to_test(self):
Expand Down
4 changes: 0 additions & 4 deletions hail/python/test/hail/fs/test_worker_driver_fs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import hail as hl
from ..helpers import startTestHailContext, stopTestHailContext
from hailtop.utils import secret_alnum_string
from hailtop.test_utils import skip_in_azure

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


@skip_in_azure
def test_requester_pays_no_settings():
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/genetics/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from hail.genetics import *
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def test_hom_ref(self):
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/genetics/test_locus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from hail.genetics import *
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext

class Tests(unittest.TestCase):

def test_constructor(self):
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/genetics/test_pedigree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from ..helpers import *
from hail.utils.java import FatalError

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):

Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/genetics/test_reference_genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from ..helpers import *
from hail.utils import FatalError

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):

Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/linalg/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import math
from hail.expr.expressions import ExpressionException

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


def sparsify_numpy(np_mat, block_size, blocks_to_sparsify):
n_rows, n_cols = np_mat.shape
Expand Down
7 changes: 2 additions & 5 deletions hail/python/test/hail/matrixtable/test_file_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from hail.utils.java import Env, scala_object
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


def create_backward_compatibility_files():
import os
Expand Down Expand Up @@ -39,12 +36,12 @@ def test_write():


@pytest.fixture(scope="module")
def all_values_matrix_table_fixture():
def all_values_matrix_table_fixture(init_hail):
return create_all_values_matrix_table()


@pytest.fixture(scope="module")
def all_values_table_fixture():
def all_values_table_fixture(init_hail):
return create_all_values_table()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import hail as hl
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):

Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/matrixtable/test_matrix_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
from hail.utils.misc import new_temp_file
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def get_mt(self, min_partitions=None) -> hl.MatrixTable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

import hail as hl
import hail.utils as utils
from ...helpers import (startTestHailContext, stopTestHailContext, get_dataset,
fails_service_backend, fails_local_backend)

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext
from ...helpers import get_dataset, fails_service_backend, fails_local_backend


class Tests(unittest.TestCase):
Expand Down
5 changes: 1 addition & 4 deletions hail/python/test/hail/methods/relatedness/test_pc_relate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import hail as hl
import hail.utils as utils

from ...helpers import (resource, startTestHailContext, stopTestHailContext, skip_when_service_backend)

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext
from ...helpers import resource, skip_when_service_backend


def test_pc_relate_against_R_truth():
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/methods/test_family_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import hail as hl
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def test_trio_matrix(self):
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/methods/test_impex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from ..helpers import *
from hail.utils import new_temp_file, FatalError, run_command, uri_path, HailUserError

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext

_FLOAT_INFO_FIELDS = [
'BaseQRankSum',
'ClippingRankSum',
Expand Down
5 changes: 1 addition & 4 deletions hail/python/test/hail/methods/test_king.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import pytest

import hail as hl
from ..helpers import resource, startTestHailContext, stopTestHailContext, fails_local_backend, fails_service_backend

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext
from ..helpers import resource, fails_local_backend, fails_service_backend


def assert_c_king_same_as_hail_king(c_king_path, hail_king_mt):
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/methods/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import hail as hl
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def test_rename_duplicates(self):
Expand Down
7 changes: 1 addition & 6 deletions hail/python/test/hail/methods/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

import hail as hl
from hail.methods.pca import _make_tsm
from ..helpers import (resource, startTestHailContext, stopTestHailContext, fails_local_backend,
fails_service_backend, skip_when_service_backend)


setUpModule = startTestHailContext
tearDownModule = stopTestHailContext
from ..helpers import resource, fails_local_backend, fails_service_backend, skip_when_service_backend


@fails_service_backend()
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/methods/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import hail.expr.aggregators as agg
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def test_sample_qc(self):
Expand Down
6 changes: 1 addition & 5 deletions hail/python/test/hail/methods/test_statgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from hail.linalg import BlockMatrix
from hail.utils import FatalError
from hail.utils.java import choose_backend
from ..helpers import (startTestHailContext, stopTestHailContext, resource,
fails_local_backend, fails_service_backend)

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext
from ..helpers import resource, fails_local_backend, fails_service_backend


class Tests(unittest.TestCase):
Expand Down
4 changes: 0 additions & 4 deletions hail/python/test/hail/table/test_grouped_table.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import unittest

import hail as hl
from ..helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class GroupedTableTests(unittest.TestCase):
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/table/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
from ..helpers import *
from test.hail.matrixtable.test_file_formats import create_all_values_datasets

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def test_annotate(self):
Expand Down
4 changes: 0 additions & 4 deletions hail/python/test/hail/test_context.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import unittest

import hail as hl
from .helpers import startTestHailContext, stopTestHailContext, skip_unless_spark_backend, fails_local_backend, fails_service_backend
from hail.utils.java import Env

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
def test_init_hail_context_twice(self):
Expand Down
3 changes: 0 additions & 3 deletions hail/python/test/hail/test_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
from hail.utils import new_temp_file
from .helpers import *

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class ValueIRTests(unittest.TestCase):
def value_irs_env(self):
Expand Down
5 changes: 0 additions & 5 deletions hail/python/test/hail/utils/test_google_fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
from hailtop.utils import secret_alnum_string
from hailtop.config import get_remote_tmpdir
from hail.utils.java import FatalError
from ..helpers import startTestHailContext, stopTestHailContext, _initialized


setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
Expand Down
4 changes: 0 additions & 4 deletions hail/python/test/hail/utils/test_placement_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import hail as hl

from hail.utils.placement_tree import PlacementTree
from ..helpers import startTestHailContext, stopTestHailContext

setUpModule = startTestHailContext
tearDownModule = stopTestHailContext


class Tests(unittest.TestCase):
Expand Down
Loading

0 comments on commit d5bf722

Please sign in to comment.