def test__resolve_configuration__external_internal_library(): """ Test resolution for an internal api of an external library. """ _pytest.python_api.approx = configurable(_pytest.python_api.approx) parsed = _parse_configuration({'pytest.approx': HParams(expected='')}) function_signature = _get_function_signature(pytest.approx.__wrapped__) assert isinstance( _resolve_configuration(parsed)[function_signature], HParams)
def test__resolve_configuration__external_library(): """ Test resolution for an external library and with a none-empty `HParams`. """ pytest.approx = configurable(pytest.approx) parsed = _parse_configuration({'pytest.approx': HParams(expected='')}) function_signature = _get_function_signature(pytest.approx.__wrapped__) assert isinstance( _resolve_configuration(parsed)[function_signature], HParams)
def test__resolve_configuration__configured_hparam(): """ Test resolution for a configured `HParam`. """ parsed = _parse_configuration( {_test__resolve_configuration__configured_hparam: HParams(arg=None)}) function_signature = _get_function_signature( _test__resolve_configuration__configured_hparam.__wrapped__) assert isinstance(_resolve_configuration(parsed)[function_signature], HParams)
def test__resolve_configuration__built_in_function(): """ Test resolution for an built in function. """ builtins.open = configurable(builtins.open) function_name = 'builtins.open' parsed = _parse_configuration({function_name: HParams()}) function_signature = _get_function_signature(builtins.open.__wrapped__) assert isinstance(_resolve_configuration(parsed)[function_signature], HParams)
def test__resolve_configuration__multiple_configurations(): """ Test resolution for with multiple configurations. """ @configurable def configured(arg): pass class Configured: @configurable def __init__(self): pass parsed = _parse_configuration({ 'tests.test_hparams.test__resolve_configuration__multiple_configurations': { '<locals>.Configured.__init__': HParams(), '<locals>.configured': HParams() } }) resolved = _resolve_configuration(parsed) assert isinstance( resolved[_get_function_signature(Configured.__init__.__wrapped__)], HParams) assert isinstance( resolved[_get_function_signature(configured.__wrapped__)], HParams) assert len(resolved) == 2
def test__resolve_configuration__lambda_function(): """ Test resolution for an lambda function. """ configured = configurable(lambda: None) function_name = ('tests.test_hparams.test__resolve_configuration__lambda_function' '.<locals>.<lambda>') parsed = _parse_configuration({function_name: HParams()}) function_signature = _get_function_signature(configured.__wrapped__) assert isinstance(_resolve_configuration(parsed)[function_signature], HParams)
def test__resolve_configuration__multiple_sys_path(): """ Test resolution for multiple `sys` path. """ sys.path = [os.path.dirname(__file__)] + sys.path function_name = 'test_hparams._test__resolve_configuration__multiple_sys_path' parsed = _parse_configuration({function_name: HParams()}) function_signature = _get_function_signature( _test__resolve_configuration__multiple_sys_path.__wrapped__) assert isinstance(_resolve_configuration(parsed)[function_signature], HParams) sys.path.pop(0)
def test__resolve_configuration__no_sys_path(): """ Test resolution with no `sys` path. """ original = sys.path sys.path = [] parsed = _parse_configuration( {_test__resolve_configuration__no_sys_path.__wrapped__: HParams()}) function_signature = _get_function_signature( _test__resolve_configuration__no_sys_path.__wrapped__) assert isinstance(_resolve_configuration(parsed)[function_signature], HParams) sys.path = original
def test__resolve_configuration__duplicate(): """ Test resolution for multiple sys path allowing for duplicate configuration. """ sys.path = [os.path.dirname(__file__)] + sys.path parsed = _parse_configuration({ 'test_hparams._test__resolve_configuration__duplicate': HParams(), 'tests.test_hparams._test__resolve_configuration__duplicate': HParams(), }) with pytest.raises(TypeError): _resolve_configuration(parsed) sys.path.pop(0)
def test__resolve_configuration__internal_function(): """ Test resolution for an internal function. """ @configurable def configured(arg): pass function_name = ('tests.test_hparams.test__resolve_configuration__internal_function' '.<locals>.configured') parsed = _parse_configuration({function_name: HParams()}) function_signature = _get_function_signature(configured.__wrapped__) assert isinstance(_resolve_configuration(parsed)[function_signature], HParams)
def test__parse_configuration__function(): """ Test for `_parse_configuration` to resolve a function. """ parsed = _parse_configuration({test__parse_configuration__function: {'cda': 'abc'}}) assert parsed == { 'tests': { 'test_hparams': { 'test__parse_configuration__function': { 'cda': 'abc' } } } }
def test__resolve_configuration__internal_class(): """ Test resolution for an internal class. """ class Configured: @configurable def __init__(self): pass function_name = ('tests.test_hparams.test__resolve_configuration__internal_class.' '<locals>.Configured.__init__') parsed = _parse_configuration({function_name: HParams()}) function_signature = _get_function_signature(Configured.__init__.__wrapped__) assert isinstance(_resolve_configuration(parsed)[function_signature], HParams)
def test__parse_configuration__hparams(): """ Test if `_parse_configuration` respects `HParams`. """ parsed = _parse_configuration({'abc': HParams()}) assert parsed == {'abc': HParams()} assert isinstance(parsed['abc'], HParams)
def test__resolve_configuration__no_decorator(): """ Test resolution for a function that is not decorated. """ parsed = _parse_configuration({test__resolve_configuration__no_decorator: HParams()}) with pytest.raises(TypeError): _resolve_configuration(parsed)
def test__resolve_configuration__wrong_arguments(): """ Test resolution with the a none-existant function argument. """ parsed = _parse_configuration({'pytest.approx': HParams(abcdefghijklmnopqrstuvwxyz='')}) with pytest.raises(TypeError): _resolve_configuration(parsed)
def test__parse_configuration__package(): """ Test for `_parse_configuration` to resolve a package. """ parsed = _parse_configuration({hparams: {'cda': 'abc'}}) assert parsed == {'hparams': {'cda': 'abc'}}
def test__parse_configuration(): """ Basic test for `_parse_configuration`. """ parsed = _parse_configuration({'abc.abc': {'cda': 'abc'}}) assert parsed == {'abc': {'abc': {'cda': 'abc'}}}
def test__resolve_configuration__no_decorator(warnings_mock): """ Test resolution for a function that is not decorated. """ parsed = _parse_configuration( {test__resolve_configuration__no_decorator: HParams()}) _resolve_configuration(parsed) assert warnings_mock.warn.call_count == 1
def test__resolve_configuration__import_error(warnings_mock): """ Test resolution for an none-existant module. """ parsed = _parse_configuration({'abcdefghijklmnopqrstuvwxyz': HParams()}) _resolve_configuration(parsed) assert warnings_mock.warn.call_count == 1
def test__resolve_configuration__attribute_error(warnings_mock): """ Test resolution for an none-existant function in an existing module. """ parsed = _parse_configuration( {'pytest.abcdefghijklmnopqrstuvwxyz': HParams()}) _resolve_configuration(parsed) assert warnings_mock.warn.call_count == 1
def test__resolve_configuration__attribute_error(): """ Test resolution for an none-existant function in an existing module. """ parsed = _parse_configuration({'pytest.abcdefghijklmnopqrstuvwxyz': HParams()}) with pytest.raises(TypeError): _resolve_configuration(parsed)
def test__parse_configuration__wrong_type(): """ Test if the key is not a string, module, or callable a `TypeError` is raised. """ with pytest.raises(TypeError): _parse_configuration({None: 'abc'})
def test__resolve_configuration__import_error(): """ Test resolution for an none-existant module. """ parsed = _parse_configuration({'abcdefghijklmnopqrstuvwxyz': HParams()}) with pytest.raises(TypeError): _resolve_configuration(parsed)
def test__parse_configuration__improper_format_four(): """ Test if the key is improperly formatted a `TypeError` is raised. """ with pytest.raises(TypeError): _parse_configuration({'.': 'abc'})
def test__resolve_configuration__empty(): """ Test resolution for a function that is not configured. """ parsed = _parse_configuration({test__resolve_configuration__empty: {}}) with pytest.raises(TypeError): _resolve_configuration(parsed)
def test__parse_configuration__duplicate_key(): """ Test if the key is duplicated a `TypeError` is raised. """ with pytest.raises(TypeError): _parse_configuration({'abc.abc': 'abc', 'abc': {'abc': 'xyz'}})