Exemplo n.º 1
0
def test_sanitize():
    assert '' == util.toalphanum('')
    assert 'ab12' == util.toalphanum('ab12')
    assert 'ab1_2' == util.toalphanum('ab1_2')
    assert 'ab1__2' == util.toalphanum('ab1**2')
    assert 'ab__12_' == util.toalphanum('ab (12)')
    with pytest.raises(TypeError):
        util.toalphanum(None)

    with pytest.raises(TypeError):
        util.toalphanum(12)
Exemplo n.º 2
0
    def variant_name(cls, variant_num=None):
        '''Return the name of the test variant with a specific variant number.

        :param variant_num: An integer in the range of ``[0, cls.num_variants)``.
        '''

        name = cls.__name__
        if variant_num is None:
            return name

        if runtime().get_option('general/0/compact_test_names'):
            if cls.num_variants > 1:
                width = utils.count_digits(cls.num_variants)
                name += f'_{variant_num:0{width}}'
        else:
            pid, fid = cls._map_variant_num(variant_num)

            # Append the parameters to the name
            if cls.param_space.params:
                name += '_' + '_'.join(
                    utils.toalphanum(str(v))
                    for v in cls.param_space[pid].values())

            if len(cls.fixture_space) > 1:
                name += f'_{fid}'

        return name
Exemplo n.º 3
0
    def __new__(cls, *args, **kwargs):
        obj = super().__new__(cls)

        # Create a test name from the class name and the constructor's
        # arguments
        name = cls.__qualname__
        if args or kwargs:
            arg_names = map(lambda x: util.toalphanum(str(x)),
                            itertools.chain(args, kwargs.values()))
            name += '_' + '_'.join(arg_names)

        obj._rfm_init(name,
                      os.path.abspath(os.path.dirname(inspect.getfile(cls))))
        return obj
Exemplo n.º 4
0
    def emit_preamble(self, job):
        # The job name is a string of up to 15 alphanumeric characters
        # where the first character is alphabetic
        job_name = toalphanum(job.name)[:15]
        preamble = [
            self._format_option(f'-N {job_name}'),
            self._format_option(f'-o {job.stdout}'),
            self._format_option(f'-e {job.stderr}'),
        ]

        if job.time_limit is not None:
            h, m, s = seconds_to_hms(job.time_limit)
            preamble.append(
                self._format_option('-l walltime=%d:%d:%d' % (h, m, s)))

        preamble += self._emit_lselect_option(job)

        # PBS starts the job in the home directory by default
        preamble.append(f'cd {job.workdir}')
        return preamble