def test_requirement_status_repr(): requirement = EnvVarRequirement(registry=RequirementsRegistry(), env_var='FOO') status = requirement.check_status(dict(FOO=''), tmp_local_state_file(), 'default', UserConfigOverrides()) assert "RequirementStatus(False,'Environment variable FOO is not set.',EnvVarRequirement(env_var='FOO'))" == repr( status)
def check_provide_contents(dirname): environ = dict() local_state_file = LocalStateFile.load_for_directory(dirname) local_state_file.set_service_run_state("myservice", dict(port=42)) requirement = EnvVarRequirement(RequirementsRegistry(), env_var="FOO") status = requirement.check_status(environ, local_state_file, 'default', UserConfigOverrides()) context = ProvideContext(environ=environ, local_state_file=local_state_file, default_env_spec_name='default', status=status, mode=PROVIDE_MODE_DEVELOPMENT, frontend=NullFrontend()) def transform_it(state): assert 42 == state['port'] state['port'] = 43 state['foo'] = 'bar' return 1234 result = context.transform_service_run_state("myservice", transform_it) assert 1234 == result assert dict( port=43, foo='bar') == local_state_file.get_service_run_state("myservice")
def test_empty_variable_treated_as_unset(): requirement = EnvVarRequirement(registry=RequirementsRegistry(), env_var='FOO') status = requirement.check_status(dict(FOO=''), tmp_local_state_file(), 'default', UserConfigOverrides()) assert not status assert "Environment variable FOO is not set." == status.status_description assert [] == status.errors
def check_provide_contents(dirname): environ = dict(foo='bar') local_state_file = LocalStateFile.load_for_directory(dirname) requirement = EnvVarRequirement(RequirementsRegistry(), env_var="FOO") status = requirement.check_status(environ, local_state_file, 'default', UserConfigOverrides()) context = ProvideContext(environ=environ, local_state_file=local_state_file, default_env_spec_name='default', status=status, mode=PROVIDE_MODE_DEVELOPMENT, frontend=NullFrontend()) assert dict(foo='bar') == context.environ assert context.status is status
def check_provide_contents(dirname): environ = dict() local_state_file = LocalStateFile.load_for_directory(dirname) requirement = EnvVarRequirement(RequirementsRegistry(), env_var="FOO") status = requirement.check_status(environ, local_state_file, 'default', UserConfigOverrides()) context = ProvideContext(environ=environ, local_state_file=local_state_file, default_env_spec_name='default', status=status, mode=PROVIDE_MODE_DEVELOPMENT, frontend=NullFrontend()) with pytest.raises(IOError) as excinfo: context.ensure_service_directory("foo") assert "this is not EEXIST" in repr(excinfo.value)
def check_provide_contents(dirname): environ = dict() local_state_file = LocalStateFile.load_for_directory(dirname) requirement = EnvVarRequirement(RequirementsRegistry(), env_var="FOO") status = requirement.check_status(environ, local_state_file, 'default', UserConfigOverrides()) context = ProvideContext(environ=environ, local_state_file=local_state_file, default_env_spec_name='default', status=status, mode=PROVIDE_MODE_DEVELOPMENT, frontend=NullFrontend()) workpath = context.ensure_service_directory("foo") assert os.path.isdir(workpath) assert workpath.endswith("foo") parent = os.path.dirname(workpath) assert parent.endswith("services") parent = os.path.dirname(parent) assert parent == dirname # be sure we can create if it already exists workpath2 = context.ensure_service_directory("foo") assert os.path.isdir(workpath2) assert workpath == workpath2