Ejemplo n.º 1
0
def user_runtime():
    if fixtures.USER_CONFIG_FILE:
        with rt.temp_runtime(fixtures.USER_CONFIG_FILE,
                             fixtures.USER_SYSTEM):
            yield rt.runtime()
    else:
        yield rt.runtime()
Ejemplo n.º 2
0
def run_command_inline(argv, funct, *args, **kwargs):
    # Save current execution context
    argv_save = sys.argv
    environ_save = env.snapshot()
    sys.argv = argv
    exitcode = None

    captured_stdout = StringIO()
    captured_stderr = StringIO()
    print(*sys.argv)
    with redirect_stdout(captured_stdout):
        with redirect_stderr(captured_stderr):
            try:
                with rt.temp_runtime(None):
                    exitcode = funct(*args, **kwargs)
            except SystemExit as e:
                exitcode = e.code
            finally:
                # Restore execution context
                environ_save.restore()
                sys.argv = argv_save

    return (exitcode,
            captured_stdout.getvalue(),
            captured_stderr.getvalue())
Ejemplo n.º 3
0
    def _temp_runtime(logging_config):
        site_config = copy.deepcopy(settings.site_configuration)
        site_config['logging'] = [logging_config]
        with tempfile.NamedTemporaryFile(mode='w+t', dir=str(tmp_path),
                                         suffix='.py', delete=False) as fp:
            fp.write(f'site_configuration = {util.ppretty(site_config)}')

        with rt.temp_runtime(fp.name):
            yield
Ejemplo n.º 4
0
def test_option_envvar_conversion_error(extended_parser):
    with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE):
        with rt.temp_environment(variables={
                'RFM_NON_DEFAULT_CRAYPE': 'foo',
        }):
            site_config = rt.runtime().site_config
            options = extended_parser.parse_args(['--nocolor'])
            errors = options.update_config(site_config)
            assert len(errors) == 1
Ejemplo n.º 5
0
def test_option_precedence(extended_parser):
    with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE):
        with rt.temp_environment(variables={
                'RFM_TIMESTAMP': '%F',
                'RFM_NON_DEFAULT_CRAYPE': 'yes',
                'RFM_MODULES_PRELOAD': 'a,b,c',
                'RFM_CHECK_SEARCH_PATH': 'x:y:z'

        }):
            options = extended_parser.parse_args(
                ['--timestamp=%FT%T', '--nocolor']
            )
            assert options.recursive is None
            assert options.timestamp == '%FT%T'
            assert options.non_default_craype is True
            assert options.config_file is None
            assert options.prefix is None
            assert options.stagedir == '/foo'
            assert options.module == ['a', 'b', 'c']
            assert options.check_path == ['x', 'y', 'z']
            assert options.colorize is False
Ejemplo n.º 6
0
def test_option_with_config(extended_parser):
    with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE):
        with rt.temp_environment(variables={
                'RFM_TIMESTAMP': '%F',
                'RFM_NON_DEFAULT_CRAYPE': 'yes',
                'RFM_MODULES_PRELOAD': 'a,b,c',
                'RFM_KEEP_STAGE_FILES': 'no'
        }):
            site_config = rt.runtime().site_config
            options = extended_parser.parse_args(
                ['--timestamp=%FT%T', '--nocolor']
            )
            options.update_config(site_config)
            assert site_config.get('general/0/check_search_recursive') is False
            assert site_config.get('general/0/timestamp_dirs') == '%FT%T'
            assert site_config.get('general/0/non_default_craype') is True
            assert site_config.get('systems/0/prefix') == '.'
            assert site_config.get('general/0/colorize') is False
            assert site_config.get('general/0/keep_stage_files') is False

            # Defaults specified in parser override those in configuration file
            assert site_config.get('systems/0/stagedir') == '/foo'
Ejemplo n.º 7
0
 def _temp_runtime(site_config, system=None, options={}):
     options.update({'systems/prefix': str(tmp_path)})
     with rt.temp_runtime(site_config, system, options):
         yield rt.runtime
Ejemplo n.º 8
0
def with_colors(request):
    with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE, 'generic',
                         {'general/colorize': request.param == 'colors'}):
        yield request.param == 'colors'
Ejemplo n.º 9
0
 def _temp_runtime(site_config, system=None, options=None):
     options = options or {}
     options.update({'systems/prefix': tmp_path})
     with rt.temp_runtime(site_config, system, options):
         yield
Ejemplo n.º 10
0
 def _temp_runtime(config_file, system=None, options=None):
     options = options or {}
     options.update({'systems/prefix': str(tmp_path)})
     with rt.temp_runtime(config_file, system, options):
         yield
Ejemplo n.º 11
0
def argparser():
    with rt.temp_runtime(fixtures.TEST_CONFIG_FILE):
        return ArgumentParser()
Ejemplo n.º 12
0
 def _make_rt(self):
     with rt.temp_runtime(self.config_file, self.system, self.options):
         yield
Ejemplo n.º 13
0
 def _temp_runtime(site_config, system=None, options={}):
     options.update({'systems/prefix': tmp_path})
     with rt.temp_runtime(site_config, system, options) as ctx:
         yield ctx