Пример #1
0
def test_bad_datasets(bad_cdataset, bad_ddataset):
    # ensure library doesn't fail with a terrible dataset that should never
    # be executed in the first place (which causes BMDS to throw NaN)

    session = bmds.BMDS.latest_version(bmds.constants.CONTINUOUS, dataset=bad_cdataset)
    session.add_default_models()
    session.execute()
    session.recommend()
    assert session.recommended_model_index is None

    with settings_stub(BMDS_MODEL_TIMEOUT_SECONDS=3):
        # works in later versions; fix to this version
        BMDSv2601 = bmds.BMDS.versions["BMDS2601"]
        session = BMDSv2601(bmds.constants.DICHOTOMOUS, dataset=bad_ddataset)
        session.add_default_models()
        session.execute()
        session.recommend()
        assert session.recommended_model_index is None

        # assert that the execution_halted flag is appropriately set
        halted = [model.execution_halted for model in session.models]
        str_halted = (
            "[False, False, False, False, False, False, False, True, False, False]"
        )  # noqa
        assert halted[7] is True and session.models[7].name == "Gamma"
        assert str(halted) == str_halted
        total_time = session.models[7].execution_duration
        timeout = settings.BMDS_MODEL_TIMEOUT_SECONDS
        assert np.isclose(total_time, timeout) or total_time > timeout
Пример #2
0
    def test_stub_settings_should_raise_value_error_from_a_wrong_settings(
            self, current_settings):
        with pytest.raises(ValueError) as exc:
            with settings_stub(WRONG_SETTING='ops'):
                pass

        assert 'WRONG_SETTING' in str(exc)
Пример #3
0
    def test_stub_settings_should_raise_value_error_from_a_wrong_settings(
        self, current_settings
    ):
        with pytest.raises(ValueError) as exc:
            with settings_stub(WRONG_SETTING='ops'):
                pass

        assert 'WRONG_SETTING' in str(exc)
Пример #4
0
 def test_should_return_check_value_of_debug_setting(
     self,
     debug,
     expected,
     log_filter
 ):
     with settings_stub(DEBUG=debug):
         assert log_filter.filter(None) is expected
Пример #5
0
    def test_stub_settings_should_setup_lazy_settings_object(self):
        with patch.object(sys, 'argv',
                          ['', '--settings=tests.samples.simple']):
            with settings_stub(SIMPLE_STRING='stubed'):
                assert settings.SIMPLE_STRING == 'stubed'

        assert settings.SIMPLE_STRING == 'simple'
        self._clean_simple_settings()
Пример #6
0
    def test_stub_settings_shoud_setup_lazy_settings_object(self):
        with patch.object(
            sys, 'argv', ['', '--settings=tests.samples.simple']
        ):
            with settings_stub(SIMPLE_STRING='stubed'):
                assert settings.SIMPLE_STRING == 'stubed'

        assert settings.SIMPLE_STRING == 'simple'
        self._clean_simple_settings()
Пример #7
0
def test_should_configure_if_simple_settings_is_installed():
    POOL_OF_RAMOS = {
        'backend_a': ['path.to.backend'],
        'backend_b': ['path.to.backend'],
    }

    assert get_installed_pools() != POOL_OF_RAMOS
    with settings_stub(POOL_OF_RAMOS=POOL_OF_RAMOS):
        assert get_installed_pools() == POOL_OF_RAMOS
Пример #8
0
    def test_stub_settings_with_context_manager(self, current_settings):
        with settings_stub(SIMPLE_STRING='stubed'):
            assert current_settings.SIMPLE_STRING == 'stubed'

        assert current_settings.SIMPLE_STRING == 'simple'
Пример #9
0
def test_timeout():
    # confirm that timeout setting works as expected; slow dataset provided
    # by CEBS team on 2017-11-12. Only slow in BMDS version 2.6; fixed in 2.7.

    dataset = bmds.ContinuousIndividualDataset(
        doses=[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0.000316,
            0.000316,
            0.000316,
            0.000316,
            0.001,
            0.001,
            0.001,
            0.001,
            0.00316,
            0.00316,
            0.00316,
            0.00316,
            0.01,
            0.01,
            0.01,
            0.01,
            0.0316,
            0.0316,
            0.0316,
            0.0316,
            0.1,
            0.1,
            0.1,
            0.1,
            0.316,
            0.316,
            0.316,
            0.316,
            1,
            1,
            1,
            1,
            3.16,
            3.16,
            3.16,
            3.16,
            10,
            10,
            10,
            10,
        ],
        responses=[
            2289000,
            2047000,
            2108000,
            2148000,
            2325000,
            2014000,
            2173000,
            2261000,
            2024000,
            2272000,
            1742000,
            1970000,
            1850000,
            1030000,
            2074000,
            2159000,
            2348000,
            2270000,
            2238000,
            2082000,
            1894000,
            1829000,
            2181000,
            2044000,
            2438000,
            2264000,
            2303000,
            2316000,
            2061000,
            2165000,
            2310000,
            2294000,
            2550000,
            2076000,
            2284000,
            2249000,
            2308000,
            2096000,
            2347000,
            2340000,
            2170000,
            1916000,
            2858000,
            2448000,
            2648000,
            2226000,
            1164000,
            1283000,
            1278000,
            1577000,
            40305,
            36227,
            27300,
            21531,
        ],
    )

    with settings_stub(BMDS_MODEL_TIMEOUT_SECONDS=3):
        model = models.Hill_217(dataset)
        model.execute()
        assert model.has_successfully_executed is False

    with settings_stub(BMDS_MODEL_TIMEOUT_SECONDS=10):
        model = models.Hill_217(dataset)
        model.execute()
        assert model.has_successfully_executed is True
Пример #10
0
from simple_settings import settings
from simple_settings.utils import settings_stub

# Stub examples
with settings_stub(SOME_SETTING='foo'):
    assert settings.SOME_SETTING == 'foo'
assert settings.SOME_SETTING == 'bar'


@settings_stub(SOME_SETTING='foo')
def get_some_setting():
    return settings.SOME_SETTING


assert get_some_setting() == 'foo'
assert settings.SOME_SETTING == 'bar'
Пример #11
0
# -*- coding: utf-8 -*-
from simple_settings import settings
from simple_settings.utils import settings_stub


# Stub examples
with settings_stub(SOME_SETTING='foo'):
    assert settings.SOME_SETTING == 'foo'
assert settings.SOME_SETTING == 'bar'


@settings_stub(SOME_SETTING='foo')
def get_some_setting():
    return settings.SOME_SETTING

assert get_some_setting() == 'foo'
assert settings.SOME_SETTING == 'bar'
Пример #12
0
def settings_with_applications(token):
    applications_settings = {'test': token}

    with settings_stub(
            AUTH_APPLICATIONS=applications_settings) as mocked_settings:
        yield mocked_settings
Пример #13
0
    def test_stub_settings_with_context_manager(self, current_settings):
        with settings_stub(SIMPLE_STRING='stubed'):
            assert current_settings.SIMPLE_STRING == 'stubed'

        assert current_settings.SIMPLE_STRING == 'simple'
Пример #14
0
def test_settings():
    assert settings.BMDS_MODEL_TIMEOUT_SECONDS == 30
    with settings_stub(BMDS_MODEL_TIMEOUT_SECONDS=1):
        assert settings.BMDS_MODEL_TIMEOUT_SECONDS == 1