Beispiel #1
0
    def test_load_boolean(self):
        yaml = 'result: true'
        expected = {'result': True}

        result = ryaml.safe_load(yaml)

        assert result == expected
Beispiel #2
0
    def test_load_simple(self):
        yaml = "result: 42"
        expected = {'result': 42}

        result = ryaml.safe_load(yaml)

        assert result == expected
Beispiel #3
0
    def test_load_float(self):
        yaml = 'result: 1.2'
        expected = {'result': 1.2}

        result = ryaml.safe_load(yaml)

        assert result == expected
Beispiel #4
0
    def test_load_null(self):
        yaml = 'result:'
        expected = {'result': None}

        result = ryaml.safe_load(yaml)

        assert result == expected
Beispiel #5
0
    def test_load_nested_dict(self):
        yaml = ('result:\n' '  number: 42')
        expected = {'result': {'number': 42}}

        result = ryaml.safe_load(yaml)

        assert result == expected
Beispiel #6
0
    def test_load_value_is_array(self):
        yaml = ('array:\n' '- 1\n' '- 2\n' '- 3')
        expected = {'array': [1, 2, 3]}

        result = ryaml.safe_load(yaml)

        assert result == expected
Beispiel #7
0
    def test_load_key_is_number(self):
        yaml = "42: is a number"
        expected = {42: 'is a number'}

        result = ryaml.safe_load(yaml)

        assert result == expected
Beispiel #8
0
print('Starting benchmark...')

# YAML
# Decode speed
start = datetime.now()
decoded = yaml.load(data, Loader=CSafeLoader)
end = datetime.now()
print("{} decode time: {}".format(yaml.__name__, end - start))

# Encode speed
start = datetime.now()
yaml.safe_dump(decoded)
end = datetime.now()

print("{} encode time: {}".format(yaml.__name__, end - start))

# rYAML
# Decode speed
start = datetime.now()
decoded = ryaml.safe_load(data)
end = datetime.now()
print("{} decode time: {}".format(ryaml.__name__, end - start))

# Encode speed
start = datetime.now()
ryaml.safe_dump(decoded)
end = datetime.now()

print("{} encode time: {}".format(ryaml.__name__, end - start))