예제 #1
0
def test_unsafe():
    dummy = Dummy()

    with pytest.raises(yaml.representer.RepresenterError):
        yaml.dump_all([dummy])

    with pytest.raises(yaml.representer.RepresenterError):
        yaml.dump(dummy, Dumper=yDumper)

    # reverse monkey patch and try again
    monkey_patch_pyyaml_reverse()

    with tempfile.TemporaryFile(suffix='.yaml', mode='w+t') as f:
        yaml.dump_all([dummy], stream=f)
        f.seek(0)  # rewind

        doc_unsafe = yaml.load(f)
        assert type(doc_unsafe) is Dummy

        monkey_patch_pyyaml()
        with pytest.raises(yaml.constructor.ConstructorError):
            f.seek(0)  # rewind
            safe_yaml_load(f)

        with pytest.raises(yaml.constructor.ConstructorError):
            f.seek(0)  # rewind
            yaml.load(f)
예제 #2
0
def patch_yaml():
    monkey_patch_pyyaml()
    yield
    monkey_patch_pyyaml_reverse()