mirror of
https://gitee.com/openharmony/third_party_pyyaml
synced 2024-11-23 15:30:46 +00:00
3b30a99471
Signed-off-by: xuyong <xuyong59@huawei.com>
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
|
|
import yaml, test_emitter
|
|
|
|
def test_loader_error(error_filename, verbose=False):
|
|
try:
|
|
list(yaml.load_all(open(error_filename, 'rb'), yaml.FullLoader))
|
|
except yaml.YAMLError, exc:
|
|
if verbose:
|
|
print "%s:" % exc.__class__.__name__, exc
|
|
else:
|
|
raise AssertionError("expected an exception")
|
|
|
|
test_loader_error.unittest = ['.loader-error']
|
|
|
|
def test_loader_error_string(error_filename, verbose=False):
|
|
try:
|
|
list(yaml.load_all(open(error_filename, 'rb').read(), yaml.FullLoader))
|
|
except yaml.YAMLError, exc:
|
|
if verbose:
|
|
print "%s:" % exc.__class__.__name__, exc
|
|
else:
|
|
raise AssertionError("expected an exception")
|
|
|
|
test_loader_error_string.unittest = ['.loader-error']
|
|
|
|
def test_loader_error_single(error_filename, verbose=False):
|
|
try:
|
|
yaml.load(open(error_filename, 'rb').read(), yaml.FullLoader)
|
|
except yaml.YAMLError, exc:
|
|
if verbose:
|
|
print "%s:" % exc.__class__.__name__, exc
|
|
else:
|
|
raise AssertionError("expected an exception")
|
|
|
|
test_loader_error_single.unittest = ['.single-loader-error']
|
|
|
|
def test_emitter_error(error_filename, verbose=False):
|
|
events = list(yaml.load(open(error_filename, 'rb'),
|
|
Loader=test_emitter.EventsLoader))
|
|
try:
|
|
yaml.emit(events)
|
|
except yaml.YAMLError, exc:
|
|
if verbose:
|
|
print "%s:" % exc.__class__.__name__, exc
|
|
else:
|
|
raise AssertionError("expected an exception")
|
|
|
|
test_emitter_error.unittest = ['.emitter-error']
|
|
|
|
def test_dumper_error(error_filename, verbose=False):
|
|
code = open(error_filename, 'rb').read()
|
|
try:
|
|
import yaml
|
|
from StringIO import StringIO
|
|
exec code
|
|
except yaml.YAMLError, exc:
|
|
if verbose:
|
|
print "%s:" % exc.__class__.__name__, exc
|
|
else:
|
|
raise AssertionError("expected an exception")
|
|
|
|
test_dumper_error.unittest = ['.dumper-error']
|
|
|
|
if __name__ == '__main__':
|
|
import test_appliance
|
|
test_appliance.run(globals())
|
|
|