def test_loader_error_single(error_filename, verbose=False):
    try:
        yaml.load(open(error_filename, 'rb').read())
    except yaml.YAMLError as exc:
        if verbose:
            print("%s:" % exc.__class__.__name__, exc)
    else:
        raise AssertionError("expected an exception")
Beispiel #2
0
    def test_spec_perms(self):
        """Check that test specific permissions work."""

        env = os.environ.copy()

        env['PAV_CONFIG_DIR'] = self.config_dir.as_posix()

        cmd = [(self.PAV_ROOT_DIR/'bin/pav').as_posix(), 'run', 'perm.*']

        proc = sp.Popen(cmd, env=env, stdout=sp.PIPE, stderr=sp.STDOUT)
        try:
            if proc.wait(10) != 0:
                out = proc.stdout.read()
                out = out.decode()
                self.fail("Error running command.\n{}".format(out))
        except sp.TimeoutExpired:
            self.fail()
        self.wait_tests(self.working_dir)

        perms = {
            'base': (grp.getgrgid(os.getgid()), 0o007),
            'spec_perms1': (self.alt_group, 0o022),
            'spec_perms2': (self.alt_group2, 0o002),
        }

        for test_path in dir_db.select(self.working_dir / 'test_runs')[0]:
            with (test_path/'config').open() as config_file:
                test_config = yaml.load(config_file)

            name = test_config['name']

            group, umask = perms[name]

            self.check_perms(test_path, group, umask)
Beispiel #3
0
def test_unicode_input(unicode_filename, verbose=False):
    data = open(unicode_filename, 'rb').read().decode('utf-8')
    value = ' '.join(data.split())
    output = yaml.load(data)
    assert output == value, (output, value)
    output = yaml.load(io.StringIO(data))
    assert output == value, (output, value)
    for input in [
            data.encode('utf-8'), codecs.BOM_UTF8 + data.encode('utf-8'),
            codecs.BOM_UTF16_BE + data.encode('utf-16-be'),
            codecs.BOM_UTF16_LE + data.encode('utf-16-le')
    ]:
        if verbose:
            print("INPUT:", repr(input[:10]), "...")
        output = yaml.load(input)
        assert output == value, (output, value)
        output = yaml.load(io.BytesIO(input))
        assert output == value, (output, value)
Beispiel #4
0
def test_emitter_events(events_filename, verbose=False):
    events = tuple(yaml.load(open(events_filename, 'rb'), Loader=EventsLoader))
    output = yaml.emit(events)
    if verbose:
        print("OUTPUT:", events_filename)
        print(output)
    new_events = list(yaml.parse(output))
    no_comments = filter(lambda e: not isinstance(e, yaml.CommentEvent),
                         events)
    _compare_events(list(no_comments), new_events)
def test_emitter_error(error_filename, verbose=False):
    events = list(
        yaml.load(open(error_filename, 'rb'),
                  Loader=test_emitter.EventsLoader))
    try:
        yaml.emit(events)
    except yaml.YAMLError as exc:
        if verbose:
            print("%s:" % exc.__class__.__name__, exc)
    else:
        raise AssertionError("expected an exception")
Beispiel #6
0
    def setUp(self) -> None:

        if self.alt_group is None:
            self.fail("Your user must be in at least two groups (other than "
                      "the user's group) to run this test.")

        with self.PAV_CONFIG_PATH.open() as pav_cfg_file:
            raw_cfg = yaml.load(pav_cfg_file)

        self.working_dir = self.PAV_ROOT_DIR/'test'/'working_dir' / \
            'wd-spec_perms'

        if self.working_dir.exists():
            shutil.rmtree(self.working_dir.as_posix())

        self.working_dir.mkdir()

        raw_cfg['umask'] = self.umask
        raw_cfg['working_dir'] = self.working_dir.as_posix()
        raw_cfg['config_dirs'] = [self.TEST_DATA_ROOT/'configs-spec_perms']

        (self.working_dir/'test_runs').mkdir()
        (self.working_dir/'series').mkdir()
        (self.working_dir/'builds').mkdir()
        (self.working_dir/'users').mkdir()

        self.config_dir = self.TEST_DATA_ROOT/'configs-spec_perms'
        with (self.config_dir/'pavilion.yaml').open('w') as pav_cfg_file:
            yaml.dump(raw_cfg, stream=pav_cfg_file)

        tmpl_path = self.config_dir/'tests/perm.yaml.tmpl'
        test_path = self.config_dir/'tests/perm.yaml'
        with tmpl_path.open() as tmpl, test_path.open('w') as test:
            test_yaml = yaml.load(tmpl)
            test_yaml['spec_perms1']['group'] = self.alt_group.gr_name
            test_yaml['spec_perms2']['group'] = self.alt_group2.gr_name
            yaml.dump(test_yaml, test)

        self.pav_cfg = config.find(target=self.config_dir/'pavilion.yaml')

        plugins.initialize_plugins(self.pav_cfg)
Beispiel #7
0
def test_unicode_input_errors(unicode_filename, verbose=False):
    data = open(unicode_filename, 'rb').read().decode('utf-8')
    for input in [
            data.encode('utf-16-be'),
            data.encode('utf-16-le'),
            codecs.BOM_UTF8 + data.encode('utf-16-be'),
            codecs.BOM_UTF8 + data.encode('utf-16-le')
    ]:

        try:
            yaml.load(input)
        except yaml.YAMLError as exc:
            if verbose:
                print(exc)
        else:
            raise AssertionError("expected an exception")
        try:
            yaml.load(io.BytesIO(input))
        except yaml.YAMLError as exc:
            if verbose:
                print(exc)
        else:
            raise AssertionError("expected an exception")
Beispiel #8
0
    def load_merge(self, base_data, infile, partial=False):
        """Load the data infile, merge it into base_data, and then validate the combined result.
        :param base_data: Existing data to merge new data into.
        :param file infile: The input file object.
        :param bool partial: The infile is not expected to be a complete
        configuration, so missing 'required' fields can be ignored.
        :returns ConfigDict: A ConfigDict of the contents of the configuration file.
        :raises IOError: On stream read failures.
        :raises YAMLError: (and child exceptions) On YAML format issues.
        """

        new_data = yaml.load(infile)

        new_data = self.normalize(new_data)

        data = self.merge(base_data, new_data)

        return self.validate(data, partial=partial)
Beispiel #9
0
    def load(self, infile, partial=False):
        """Load a configuration YAML file from the given stream, and then
        validate against the config specification.

        :param stream infile: The input stream from which to read.
        :param bool partial: The infile is not expected to be a complete
            configuration, so missing 'required' fields can be ignored.
        :returns ConfigDict: A ConfigDict of the contents of the configuration
            file.
        :raises IOError: On stream read failures.
        :raises YAMLError: (and child exceptions) On YAML format issues.
        :raises ValueError, RequiredError, KeyError: As per validate().
        """

        raw_data = yaml.load(infile)

        values = self.normalize(raw_data)

        return self.validate(values, partial=partial)
Beispiel #10
0
    def setUp(self) -> None:

        with self.PAV_CONFIG_PATH.open() as pav_cfg_file:
            raw_cfg = yaml.load(pav_cfg_file)

        self.working_dir = self.PAV_ROOT_DIR/'test'/'working_dir'/'wd_perms'

        if self.working_dir.exists():
            shutil.rmtree(self.working_dir.as_posix())

        self.working_dir.mkdir()

        raw_cfg['shared_group'] = self.alt_group.gr_name
        raw_cfg['umask'] = self.umask
        raw_cfg['working_dir'] = self.working_dir.as_posix()

        self.config_dir = self.TEST_DATA_ROOT/'configs-permissions'
        with (self.config_dir/'pavilion.yaml').open('w') as pav_cfg_file:
            yaml.dump(raw_cfg, stream=pav_cfg_file)
Beispiel #11
0
    def setUp(self) -> None:

        with self.PAV_CONFIG_PATH.open() as pav_cfg_file:
            raw_cfg = yaml.load(pav_cfg_file)

        self.working_dir = self.PAV_ROOT_DIR / 'test' / 'working_dir' / 'wd_perms'

        if self.working_dir.exists():
            shutil.rmtree(self.working_dir.as_posix())

        self.working_dir.mkdir()

        if self.alt_group is None:
            self.fail("Your user must be in at least two groups (other than "
                      "the user's group) to run this test.")

        raw_cfg['shared_group'] = self.alt_group.gr_name
        raw_cfg['umask'] = self.umask
        raw_cfg['working_dir'] = self.working_dir.as_posix()

        self.config_dir = self.TEST_DATA_ROOT / 'configs-permissions'
        with (self.config_dir / 'pavilion.yaml').open('w') as pav_cfg_file:
            yaml.dump(raw_cfg, stream=pav_cfg_file)
Beispiel #12
0
    def load_raw(infile):
        """Load the raw config. This just does a yaml.load with no
        validation. You're expected to validate separately."""

        return yaml.load(infile)
Beispiel #13
0
def canonical_load(stream):
    return yaml.load(stream, Loader=CanonicalLoader)