Merge pull request #543 from mweinelt/common-yaml-formatter
Use custom YAML subclass to be compatible with ruamel_yaml>=0.17
This commit is contained in:
18
whipper/common/yaml.py
Normal file
18
whipper/common/yaml.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from ruamel.yaml import YAML as ruamel_YAML
|
||||||
|
from ruamel.yaml.compat import StringIO
|
||||||
|
|
||||||
|
# https://yaml.readthedocs.io/en/latest/example.html#output-of-dump-as-a-string
|
||||||
|
class YAML(ruamel_YAML):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__()
|
||||||
|
self.width = 4000
|
||||||
|
self.default_flow_style = False
|
||||||
|
|
||||||
|
def dump(self, data, stream=None, **kw):
|
||||||
|
inefficient = False
|
||||||
|
if stream is None:
|
||||||
|
inefficient = True
|
||||||
|
stream = StringIO()
|
||||||
|
ruamel_YAML.dump(self, data, stream, **kw)
|
||||||
|
if inefficient:
|
||||||
|
return stream.getvalue()
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import time
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
import re
|
import re
|
||||||
import ruamel.yaml as yaml
|
|
||||||
from ruamel.yaml.comments import CommentedMap as OrderedDict
|
from ruamel.yaml.comments import CommentedMap as OrderedDict
|
||||||
|
|
||||||
import whipper
|
import whipper
|
||||||
|
|
||||||
from whipper.common import common
|
from whipper.common import common
|
||||||
|
from whipper.common.yaml import YAML
|
||||||
from whipper.result import result
|
from whipper.result import result
|
||||||
|
|
||||||
|
|
||||||
@@ -148,11 +148,12 @@ class WhipperLogger(result.Logger):
|
|||||||
data["EOF"] = "End of status report"
|
data["EOF"] = "End of status report"
|
||||||
riplog["Conclusive status report"] = data
|
riplog["Conclusive status report"] = data
|
||||||
|
|
||||||
|
yaml = YAML(
|
||||||
|
typ="rt",
|
||||||
|
pure=True
|
||||||
|
)
|
||||||
riplog = yaml.dump(
|
riplog = yaml.dump(
|
||||||
riplog,
|
riplog
|
||||||
default_flow_style=False,
|
|
||||||
width=4000,
|
|
||||||
Dumper=yaml.RoundTripDumper
|
|
||||||
)
|
)
|
||||||
# Add a newline after the "Log creation date" line
|
# Add a newline after the "Log creation date" line
|
||||||
riplog = re.sub(
|
riplog = re.sub(
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import hashlib
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import unittest
|
import unittest
|
||||||
import ruamel.yaml
|
|
||||||
|
|
||||||
|
from whipper.common.yaml import YAML
|
||||||
from whipper.result.result import TrackResult, RipResult
|
from whipper.result.result import TrackResult, RipResult
|
||||||
from whipper.result.logger import WhipperLogger
|
from whipper.result.logger import WhipperLogger
|
||||||
|
|
||||||
@@ -163,16 +163,14 @@ class LoggerTestCase(unittest.TestCase):
|
|||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
|
||||||
yaml = ruamel.yaml.YAML()
|
yaml = YAML(
|
||||||
|
typ='rt',
|
||||||
|
pure=True
|
||||||
|
)
|
||||||
parsedLog = yaml.load(actual)
|
parsedLog = yaml.load(actual)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
actual,
|
actual,
|
||||||
ruamel.yaml.dump(
|
yaml.dump(parsedLog)
|
||||||
parsedLog,
|
|
||||||
default_flow_style=False,
|
|
||||||
width=4000,
|
|
||||||
Dumper=ruamel.yaml.RoundTripDumper
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
log_body = "\n".join(actualLines[:-1]).encode()
|
log_body = "\n".join(actualLines[:-1]).encode()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user