Ejemplo n.º 1
0
def run_smoke_tests_with_config(config_fname, run=None, raise_errors=True,
                                func_kwargs=None):
    from palladium.util import logger  # don't break coverage
    from palladium.util import timer

    if func_kwargs is None:
        func_kwargs = {}

    print("Running functional tests for {}".format(config_fname))

    with patch.dict('os.environ', {'PALLADIUM_CONFIG': config_fname}):
        from palladium.fit import fit
        from palladium.fit import activate
        from palladium.fit import grid_search
        from palladium.eval import test
        from palladium.util import initialize_config

        failed = []

        with change_cwd(os.path.dirname(config_fname)):
            initialize_config(__mode__='fit')
            for func in (fit, activate, grid_search, test, predict):
                if run and func.__name__ not in run:
                    continue
                try:
                    this_kwargs = func_kwargs.get(func.__name__, {})
                    with timer(logger.info,
                               "Running {}".format(func.__name__)):
                        func(**this_kwargs)
                except Exception as e:
                    if raise_errors:
                        raise
                    failed.append((func.__name__, e))

    return failed
Ejemplo n.º 2
0
 def _initialize_config(self, flask_app_test):
     # simulate real config (empty dict), otherwise
     # _initialize_config will not be called
     with patch('palladium.util.open',
                mock_open(read_data=str({})),
                create=True):
         with patch('palladium.util.os.environ',
                    {'PALLADIUM_CONFIG': 'somepath'}):
             with flask_app_test.test_request_context():
                 from palladium.util import initialize_config
                 initialize_config()
Ejemplo n.º 3
0
 def test_initialize_config_already_initialized(self, config,
                                                initialize_config):
     config.clear()
     config.initialized = True
     with pytest.raises(RuntimeError):
         initialize_config(two='three')
Ejemplo n.º 4
0
    def test_initialize_config_extra(self, config, initialize_config):
        config.clear()
        initialize_config(two='three')

        assert config['two'] == 'three'
Ejemplo n.º 5
0
 def test_initialize_config_already_initialized(self, config,
                                                initialize_config):
     config.clear()
     config.initialized = True
     with pytest.raises(RuntimeError):
         initialize_config(two='three')
Ejemplo n.º 6
0
 def test_initialize_config_extra(self, config,
                                  initialize_config):
     config.clear()
     initialize_config(two='three')
     assert config['two'] == 'three'