From 16f62d709c2150abca46c111d07c5d7052111370 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 19 Mar 2021 23:06:08 +0100 Subject: More improvements to to_yaml --- lesana/templating.py | 7 +++++-- tests/test_templating.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lesana/templating.py b/lesana/templating.py index 8ff9fcb..95c6146 100644 --- a/lesana/templating.py +++ b/lesana/templating.py @@ -28,8 +28,11 @@ def to_yaml(data): data = ruamel.yaml.scalarstring.LiteralScalarString(data + "\n") elif isinstance(data, decimal.Decimal): data = str(data) + elif data is None: + return 'null' yaml = ruamel.yaml.YAML() s_io = io.StringIO() - yaml.dump(data, s_io) - res = s_io.getvalue().strip('...\n').strip() + yaml.dump({'data': data}, s_io) + res = s_io.getvalue() + res = res.lstrip('{data:').lstrip().strip() return res diff --git a/tests/test_templating.py b/tests/test_templating.py index aadcf66..57d7f7a 100644 --- a/tests/test_templating.py +++ b/tests/test_templating.py @@ -52,6 +52,8 @@ class testFilters(unittest.TestCase): res = templating.to_yaml(s) self.assertTrue(res.startswith("|\n")) self.assertNotIn('\n', res.lstrip("|\n")) + for line in res.lstrip("|\n").split('\n'): + self.assertTrue(line.startswith(" ")) if __name__ == '__main__': -- cgit v1.2.3