PyYAML/tests/smoke/pyyaml_object.py
Štěpán Šigut 26b6c33011 Import CI tests from RHEL
This is from RHEL distgit tests/PyYAML, directory Sanity/Smoke.

The original commit hash: fd668cd6d20ca9c46d9bfa5ccf34f3a925317b25

Only necessary files were kept.

Co-Authored-By: Lukas Zachar <lzachar@redhat.com>
Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
2024-04-11 17:05:14 +02:00

25 lines
535 B
Python

import yaml
class Hero:
def __init__(self, name, hp, sp):
self.name = name
self.hp = hp
self.sp = sp
def __repr__(self):
return "%s(name=%r, hp=%r, sp=%r)" % (
self.__class__.__name__, self.name, self.hp, self.sp)
STRING = """
!!python/object:__main__.Hero
name: Welthyr Syxgon
hp: 1200
sp: 0
"""
try:
yaml.load(STRING, Loader=yaml.SafeLoader)
raise RuntimeError("Didn't raise exception")
except yaml.constructor.ConstructorError:
pass
print(yaml.unsafe_load(STRING))