コード例 #1
0
ファイル: test_input_output.py プロジェクト: tompaton/ruyaml
def test_unicode_input_errors(unicode_filename, verbose=False):
    with open(unicode_filename, 'rb') as fp:
        data = fp.read().decode('utf-8')
    for input in [
            data.encode('latin1', 'ignore'),
            data.encode('utf-16-be'),
            data.encode('utf-16-le'),
            codecs.BOM_UTF8 + data.encode('utf-16-be'),
            codecs.BOM_UTF16_BE + data.encode('utf-16-le'),
            codecs.BOM_UTF16_LE + data.encode('utf-8') + b'!',
    ]:
        try:
            yaml.load(input)
        except yaml.YAMLError as exc:
            if verbose:
                print(exc)
        else:
            raise AssertionError('expected an exception')
        try:
            yaml.load(BytesIO(input))
        except yaml.YAMLError as exc:
            if verbose:
                print(exc)
        else:
            raise AssertionError('expected an exception')
コード例 #2
0
ファイル: test_errors.py プロジェクト: tompaton/ruyaml
def test_loader_error_single(error_filename, verbose=False):
    try:
        with open(error_filename, 'rb') as fp0:
            yaml.load(fp0.read())
    except yaml.YAMLError as exc:
        if verbose:
            print('%s:' % exc.__class__.__name__, exc)
    else:
        raise AssertionError('expected an exception')
コード例 #3
0
def test_load_cyaml():
    print("???????????????????????", platform.python_implementation())
    import ruyaml

    if sys.version_info >= (3, 8):
        return
    assert ruyaml.__with_libyaml__
    from ruyaml.cyaml import CLoader

    ruyaml.load('abc: 1', Loader=CLoader)
コード例 #4
0
def rt(s):
    import ruyaml

    res = ruyaml.dump(
        ruyaml.load(s, Loader=ruyaml.RoundTripLoader),
        Dumper=ruyaml.RoundTripDumper,
    )
    return res.strip() + '\n'
コード例 #5
0
ファイル: test_add_xxx.py プロジェクト: tompaton/ruyaml
def test_yaml_obj():
    import ruyaml  # NOQA

    ruyaml.add_representer(Obj1, YAMLObj1.to_yaml)
    ruyaml.add_multi_constructor(YAMLObj1.yaml_tag, YAMLObj1.from_yaml)
    x = ruyaml.load('!obj:x.2\na: 1', Loader=ruyaml.Loader)
    print(x)
    assert ruyaml.dump(x) == """!obj:x.2 "{'a': 1}"\n"""
コード例 #6
0
ファイル: test_add_xxx.py プロジェクト: tompaton/ruyaml
def test_dice_implicit_resolver():
    import ruyaml  # NOQA

    pattern = re.compile(r'^\d+d\d+$')
    ruyaml.add_implicit_resolver(u'!dice', pattern)
    assert (ruyaml.dump(dict(treasure=Dice(10, 20)),
                        default_flow_style=False) == 'treasure: 10d20\n')
    assert ruyaml.load('damage: 5d10',
                       Loader=ruyaml.Loader) == dict(damage=Dice(5, 10))
コード例 #7
0
ファイル: test_emitter.py プロジェクト: tompaton/ruyaml
def test_emitter_events(events_filename, verbose=False):
    with open(events_filename, 'rb') as fp0:
        events = list(yaml.load(fp0, Loader=EventsLoader))
    output = yaml.emit(events)
    if verbose:
        print('OUTPUT:')
        print(output)
    new_events = list(yaml.parse(output))
    _compare_events(events, new_events)
コード例 #8
0
    def test_roundtrip_flow_mapping(self):
        import ruyaml

        s = dedent("""\
        - {a: 1, b: hallo}
        - {j: fka, k: 42}
        """)
        data = ruyaml.load(s, Loader=ruyaml.RoundTripLoader)
        output = ruyaml.dump(data, Dumper=ruyaml.RoundTripDumper)
        assert s == output
コード例 #9
0
ファイル: test_errors.py プロジェクト: tompaton/ruyaml
def test_emitter_error(error_filename, verbose=False):
    with open(error_filename, 'rb') as fp0:
        events = list(yaml.load(fp0, 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')
コード例 #10
0
def round_trip_load(inp, preserve_quotes=None, version=None):
    import ruyaml  # NOQA

    dinp = dedent(inp)
    return ruyaml.load(
        dinp,
        Loader=ruyaml.RoundTripLoader,
        preserve_quotes=preserve_quotes,
        version=version,
    )
コード例 #11
0
ファイル: test_input_output.py プロジェクト: tompaton/ruyaml
def test_unicode_input(unicode_filename, verbose=False):
    with open(unicode_filename, 'rb') as fp:
        data = fp.read().decode('utf-8')
    value = ' '.join(data.split())
    output = yaml.load(data)
    assert output == value, (output, value)
    output = yaml.load(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(BytesIO(input))
        assert output == value, (output, value)
コード例 #12
0
ファイル: test_json_numbers.py プロジェクト: tompaton/ruyaml
def load(s, typ=float):
    import ruyaml

    x = '{"low": %s }' % (s)
    print('input: [%s]' % (s), repr(x))
    # just to check it is loadable json
    res = json.loads(x)
    assert isinstance(res['low'], typ)
    ret_val = ruyaml.load(x, ruyaml.RoundTripLoader)
    print(ret_val)
    return ret_val['low']
コード例 #13
0
ファイル: test_numpy.py プロジェクト: tompaton/ruyaml
def Xtest_numpy():
    import ruyaml

    if numpy is None:
        return
    data = numpy.arange(10)
    print('data', type(data), data)

    yaml_str = ruyaml.dump(data)
    datb = ruyaml.load(yaml_str)
    print('datb', type(datb), datb)

    print('\nYAML', yaml_str)
    assert data == datb
コード例 #14
0
    def test_added_inline_list(self):
        import ruyaml

        s1 = dedent("""
        a:
        - b
        - c
        - d
        """)
        s = 'a: [b, c, d]\n'
        data = ruyaml.load(s1, Loader=ruyaml.RoundTripLoader)
        val = data['a']
        val.fa.set_flow_style()
        # print(type(val), '_yaml_format' in dir(val))
        output = ruyaml.dump(data, Dumper=ruyaml.RoundTripDumper)
        assert s == output
コード例 #15
0
ファイル: test_recursive.py プロジェクト: tompaton/ruyaml
def test_recursive(recursive_filename, verbose=False):
    context = globals().copy()
    with open(recursive_filename, 'rb') as fp0:
        exec(fp0.read(), context)
    value1 = context['value']
    output1 = None
    value2 = None
    output2 = None
    try:
        output1 = yaml.dump(value1)
        value2 = yaml.load(output1)
        output2 = yaml.dump(value2)
        assert output1 == output2, (output1, output2)
    finally:
        if verbose:
            print('VALUE1:', value1)
            print('VALUE2:', value2)
            print('OUTPUT1:')
            print(output1)
            print('OUTPUT2:')
            print(output2)
コード例 #16
0
def test_representer_types(code_filename, verbose=False):
    yaml = YAML(typ='safe', pure=True)
    test_constructor._make_objects()
    for allow_unicode in [False, True]:
        for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
            with open(code_filename, 'rb') as fp0:
                native1 = test_constructor._load_code(fp0.read())
            native2 = None
            try:
                output = yaml.dump(
                    native1,
                    Dumper=test_constructor.MyDumper,
                    allow_unicode=allow_unicode,
                    encoding=encoding,
                )
                native2 = yaml.load(output, Loader=test_constructor.MyLoader)
                try:
                    if native1 == native2:
                        continue
                except TypeError:
                    pass
                value1 = test_constructor._serialize_value(native1)
                value2 = test_constructor._serialize_value(native2)
                if verbose:
                    print('SERIALIZED NATIVE1:')
                    print(value1)
                    print('SERIALIZED NATIVE2:')
                    print(value2)
                assert value1 == value2, (native1, native2)
            finally:
                if verbose:
                    print('NATIVE1:')
                    pprint.pprint(native1)
                    print('NATIVE2:')
                    pprint.pprint(native2)
                    print('OUTPUT:')
                    print(output)
コード例 #17
0
        mock_yaml.load.side_effect = [course_yml]
        # this is not okay I assume, I just added args
        helm_args = ['provided args']
        helm_instance = mock_helm(helm_args)
        helm_instance.client_version = '0.0.0'

        instance = reckoner.course.Course(None)
        self.assertTrue(
            instance.plot(['a-chart-that-is-not-defined', 'fake-chart']))


test_course = "./tests/test_course.yml"
git_repo_path = "./test"

with open(test_course, 'r') as yaml_stream:
    course_yaml_dict = ruyaml.load(yaml_stream, Loader=ruyaml.Loader)
test_release_names = list(course_yaml_dict['charts'].keys())
test_repositories = ['stable', 'incubator'],
test_minimum_versions = ['helm', 'reckoner']
test_repository_dict = {
    'name': 'test_repo',
    'url': 'https://kubernetes-charts.storage.googleapis.com'
}
test_reckoner_version = "1.0.0"
test_namespace = 'test'

test_release_name = 'spotify-docker-gc-again'
test_chart_name = 'spotify-docker-gc'

test_git_repository_chart = 'centrifugo'
test_git_repository = {
コード例 #18
0
ファイル: test_add_xxx.py プロジェクト: tompaton/ruyaml
def test_dice_constructor_with_loader():
    import ruyaml  # NOQA

    ruyaml.add_constructor(u'!dice', dice_constructor, Loader=ruyaml.Loader)
    data = ruyaml.load('initial hit points: !dice 8d4', Loader=ruyaml.Loader)
    assert str(data) == "{'initial hit points': Dice(8,4)}"
コード例 #19
0
def from_yaml_file(f):
    """
    Read a yaml file and convert to Python objects (including rpcq messages).
    """
    return from_json(to_json(yaml.load(f, Loader=yaml.Loader)))
コード例 #20
0
ファイル: canonical.py プロジェクト: tompaton/ruyaml
def canonical_load(stream):
    return ruyaml.load(stream, Loader=CanonicalLoader)