コード例 #1
0
ファイル: test_api_change.py プロジェクト: ware/ruamel-yaml
    def test_dump_path(self, tmpdir):
        from ruamel.yaml import YAML

        fn = Path(str(tmpdir)) / 'test.yaml'
        yaml = YAML()
        data = yaml.map()
        data['a'] = 1
        data['b'] = 2
        yaml.dump(data, fn)
        assert fn.read_text() == 'a: 1\nb: 2\n'
コード例 #2
0
ファイル: test_api_change.py プロジェクト: ware/ruamel-yaml
    def test_dump_file(self, tmpdir):
        from ruamel.yaml import YAML

        fn = Path(str(tmpdir)) / 'test.yaml'
        yaml = YAML()
        data = yaml.map()
        data['a'] = 1
        data['b'] = 2
        with open(str(fn), 'w') as fp:
            yaml.dump(data, fp)
        assert fn.read_text() == 'a: 1\nb: 2\n'
コード例 #3
0
ファイル: test_api_change.py プロジェクト: ware/ruamel-yaml
    def test_transform(self, tmpdir):
        from ruamel.yaml import YAML

        def tr(s):
            return s.replace(' ', '  ')

        fn = Path(str(tmpdir)) / 'test.yaml'
        yaml = YAML()
        data = yaml.map()
        data['a'] = 1
        data['b'] = 2
        yaml.dump(data, fn, transform=tr)
        assert fn.read_text() == 'a:  1\nb:  2\n'
コード例 #4
0
ファイル: test_api_change.py プロジェクト: ware/ruamel-yaml
    def test_multi_document_load(self, tmpdir):
        """this went wrong on 3.7 because of StopIteration, PR 37 and Issue 211"""
        from ruamel.yaml import YAML

        fn = Path(str(tmpdir)) / 'test.yaml'
        fn.write_text(
            textwrap.dedent(u"""\
            ---
            - a
            ---
            - b
            ...
            """))
        yaml = YAML()
        assert list(yaml.load_all(fn)) == [['a'], ['b']]
コード例 #5
0
ファイル: test_api_change.py プロジェクト: ware/ruamel-yaml
    def test_dump_too_many_args(self, tmpdir):
        from ruamel.yaml import YAML

        fn = Path(str(tmpdir)) / 'test.yaml'
        yaml = YAML()
        data = yaml.map()
        data['a'] = 1
        data['b'] = 2
        with pytest.raises(TypeError):
            yaml.dump(data, fn, True)
コード例 #6
0
ファイル: roundtrip.py プロジェクト: ware/ruamel-yaml
def save_and_run(program,
                 base_dir=None,
                 output=None,
                 file_name=None,
                 optimized=False):
    """
    safe and run a python program, thereby circumventing any restrictions on module level
    imports
    """
    from subprocess import check_output, STDOUT, CalledProcessError

    if not hasattr(base_dir, 'hash'):
        base_dir = Path(str(base_dir))
    if file_name is None:
        file_name = 'safe_and_run_tmp.py'
    file_name = base_dir / file_name
    file_name.write_text(dedent(program))

    try:
        cmd = [sys.executable]
        if optimized:
            cmd.append('-O')
        cmd.append(str(file_name))
        print('running:', *cmd)
        res = check_output(cmd, stderr=STDOUT, universal_newlines=True)
        if output is not None:
            if '__pypy__' in sys.builtin_module_names:
                res = res.splitlines(True)
                res = [line for line in res if 'no version info' not in line]
                res = ''.join(res)
            print('result:  ', res, end='')
            print('expected:', output, end='')
            assert res == output
    except CalledProcessError as exception:
        print("##### Running '{} {}' FAILED #####".format(
            sys.executable, file_name))
        print(exception.output)
        return exception.returncode
    return 0
コード例 #7
0
# coding: utf-8

from __future__ import print_function, unicode_literals

import sys
import pytest  # NOQA
import warnings  # NOQA

from ruamel.std.pathlib import Path

base_path = Path('data')  # that is ruamel.yaml.data
PY2 = sys.version_info[0] == 2


class YAMLData(object):
    yaml_tag = '!YAML'

    def __init__(self, s):
        self._s = s

    # Conversion tables for input. E.g. "<TAB>" is replaced by "\t"
    # fmt: off
    special = {
        'SPC': ' ',
        'TAB': '\t',
        '---': '---',
        '...': '...',
    }
    # fmt: on

    @property
コード例 #8
0
print('ruamel.yaml version', version)
# print('cwd:', os.getcwd())
# current working directory is the one with `conf.py` !


class ryd2rst:
    pass


if False:
    try:
        from ryd.__main__ import RYDCmd
        from ruamel.std.pathlib import Path

        oldargv = sys.argv
        for fn in Path('.').glob('*.ryd'):
            sys.argv = ['ryd', 'convert', '--no-pdf', str(fn)]
            rc = RYDCmd()
            rc.parse_args()
            print(sys.argv, '->', rc.run())
        sys.argv = oldargv

    except Exception as e:
        print('ryd exception', e)

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None