# Path: srsly/tests/ruamel_yaml/roundtrip.py
# 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


import sys
import pytest  # NOQA
    import srsly.ruamel_yaml.comments
from .roundtrip import save_and_run  # NOQA
    from srsly.ruamel_yaml import YAML
    from srsly.ruamel_yaml.compat import StringIO

    class Monster(srsly.ruamel_yaml.YAMLObject):
        yaml_tag = u'!Monster'

        def __init__(self, name, hp, ac, attacks):
            self.name = name
            self.hp = hp
            self.ac = ac
            self.attacks = attacks

        def __repr__(self):
            return "%s(name=%r, hp=%r, ac=%r, attacks=%r)" % (
                self.__class__.__name__, self.name, self.hp, self.ac, self.attacks)

    data = srsly.ruamel_yaml.load(dedent("""\\
        --- !Monster
        name: Cave spider
        hp: [2,6]    # 2d6
        ac: 16
        attacks: [BITE, HURT]
    """), Loader=srsly.ruamel_yaml.Loader)
    # normal dump, keys will be sorted
    assert srsly.ruamel_yaml.dump(data) == dedent("""\\
        !Monster
        ac: 16
        attacks: [BITE, HURT]
        hp: [2, 6]
        name: Cave spider
    """)
    '''

# Path: srsly/tests/ruamel_yaml/roundtrip.py
# 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


# Path: srsly/tests/ruamel_yaml/test_yamlobject.py
import sys
import pytest  # NOQA
    import srsly.ruamel_yaml.comments
from .roundtrip import save_and_run  # NOQA
    from srsly.ruamel_yaml import YAML
    from srsly.ruamel_yaml.compat import StringIO


    class Monster(srsly.ruamel_yaml.YAMLObject):
        yaml_tag = u'!Monster'

        def __init__(self, name, hp, ac, attacks):
            self.name = name
            self.hp = hp
            self.ac = ac
            self.attacks = attacks

        def __repr__(self):
            return "%s(name=%r, hp=%r, ac=%r, attacks=%r)" % (
                self.__class__.__name__, self.name, self.hp, self.ac, self.attacks)

    data = srsly.ruamel_yaml.load(dedent("""\\
        --- !Monster
        name: Cave spider
        hp: [2,6]    # 2d6
        ac: 16
        attacks: [BITE, HURT]
    """), Loader=srsly.ruamel_yaml.Loader)
    # normal dump, keys will be sorted
    assert srsly.ruamel_yaml.dump(data) == dedent("""\\
        !Monster
        ac: 16
        attacks: [BITE, HURT]
        hp: [2, 6]
        name: Cave spider
    """)
    '''

    assert save_and_run(program_src, tmpdir) == 1