Example #1
0
def test_file_output(unicode_filename, verbose=False):
    data = open(unicode_filename, 'rb').read().decode('utf-8')
    handle, filename = tempfile.mkstemp()
    os.close(handle)
    try:
        stream = io.StringIO()
        yaml.dump(data, stream, allow_unicode=True)
        data1 = stream.getvalue()
        stream = io.BytesIO()
        yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True)
        data2 = stream.getvalue().decode('utf-16-le')[1:]
        stream = open(filename, 'w', encoding='utf-16-le')
        yaml.dump(data, stream, allow_unicode=True)
        stream.close()
        data3 = open(filename, 'r', encoding='utf-16-le').read()
        stream = open(filename, 'wb')
        yaml.dump(data, stream, encoding='utf-8', allow_unicode=True)
        stream.close()
        data4 = open(filename, 'r', encoding='utf-8').read()
        assert data1 == data2, (data1, data2)
        assert data1 == data3, (data1, data3)
        assert data1 == data4, (data1, data4)
    finally:
        if os.path.exists(filename):
            os.unlink(filename)
Example #2
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)
Example #3
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)
Example #4
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)
Example #5
0
def test_unicode_output(unicode_filename, verbose=False):
    data = open(unicode_filename, 'rb').read().decode('utf-8')
    value = ' '.join(data.split())
    for allow_unicode in [False, True]:
        data1 = yaml.dump(value, allow_unicode=allow_unicode)
        for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']:
            stream = io.StringIO()
            yaml.dump(value,
                      stream,
                      encoding=encoding,
                      allow_unicode=allow_unicode)
            data2 = stream.getvalue()
            data3 = yaml.dump(value,
                              encoding=encoding,
                              allow_unicode=allow_unicode)
            if encoding is not None:
                assert isinstance(data3, bytes)
                data3 = data3.decode(encoding)
            stream = io.BytesIO()
            if encoding is None:
                try:
                    yaml.dump(value,
                              stream,
                              encoding=encoding,
                              allow_unicode=allow_unicode)
                except TypeError as exc:
                    if verbose:
                        print(exc)
                    data4 = None
                else:
                    raise AssertionError("expected an exception")
            else:
                yaml.dump(value,
                          stream,
                          encoding=encoding,
                          allow_unicode=allow_unicode)
                data4 = stream.getvalue()
                if verbose:
                    print("BYTES:", data4[:50])
                data4 = data4.decode(encoding)

            assert isinstance(data1, str), (type(data1), encoding)
            assert isinstance(data2, str), (type(data2), encoding)