def test_load_yaml_raises_on_wrong_file_permissions(tmpdir): task_file = tmpdir.join("mydata.yml") task_file.write('irrelevant') task_file.chmod(stat.S_IWUSR) with pytest.raises(OSError): FS.load_yaml(str(task_file))
def test_load_yaml_raises_on_invalid_yaml(tmpdir): content = 'this: is: invalid' task_file = tmpdir.join("mydata.yml") task_file.write(content) with pytest.raises(TypeError): FS.load_yaml(str(task_file))
def test_load_yaml_succeeds_on_valid_yaml(tmpdir): content = ['hello', {'this': 'is valid yaml'}] task_file = tmpdir.join("mydata.yml") task_file.write(yaml.dump(content)) assert content == FS.load_yaml(str(task_file))
def build_meta(role_path: str) -> Optional['Meta']: try: content = FS.load_yaml(Meta.main_path(role_path)) return Meta(content, role_path) if content is not None else None except TypeError as e: logger.warning(str(e)) except OSError as e: logger.debug(str(e))
def data(self) -> List[dict]: if self._data is None: try: self._data = FS.load_yaml(self.path) if self._data is None: self._data = [] except (TypeError, OSError) as e: logger.warning(str(e)) self._data = [] return self._data
def build_task(task_path: str) -> List[dict]: try: content = FS.load_yaml(task_path) except (TypeError, OSError) as e: raise RuntimeError('role task {}: load/parse failure. Details: {}'.format(task_path, str(e))) else: if content is None: return [] if type(content) != list: raise ValueError( 'role task {}: expected content to be a list, got: {}'.format(task_path, type(content))) return content
def test_load_yaml_succeeds_on_tags(tmpdir): def default_ctor(loader, tag_suffix, node): return tag_suffix + ' ' + node.value yaml.add_multi_constructor('', default_ctor) content = yaml.load("""\ data_contains: !vault | $ANSIBLE_VAULT;1.1;AES256 1234567890ABCDEFGHIJKLMNO """) task_file = tmpdir.join("mydata.yml") task_file.write(yaml.dump(content)) assert content == FS.load_yaml(str(task_file))
def test_load_yaml_raises_on_missing_file(tmpdir): task_file = tmpdir.join('mydata.yml') with pytest.raises(OSError): FS.load_yaml(str(task_file))
def build(path: str) -> 'Playbook': try: content = FS.load_yaml(path) return Playbook(content, path) if content is not None else None except (TypeError, OSError) as e: raise RuntimeError(e)
def build(path: str): try: content = FS.load_yaml(path) return Tasklist(content, path) except (OSError, TypeError) as e: logger.error(e)