Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _test/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

# cannot do "from .roundtrip" because of pytest, so mypy cannot find this
from roundtrip import ( # type: ignore
YAML,
dedent,
na_round_trip,
round_trip,
round_trip_dump,
round_trip_load,
save_and_run,
YAML,
)


Expand Down
43 changes: 43 additions & 0 deletions _test/test_z_check_debug_leftovers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest # type: ignore # NOQA
from roundtrip import dedent, round_trip_dump, round_trip_load # type: ignore

from ruyaml.emitter import Emitter


class TestLeftOverDebug:
# idea here is to capture round_trip_output via pytest stdout capture
Expand Down Expand Up @@ -38,3 +40,44 @@ def test_01(self, capsys: Any) -> None:
round_trip_dump(d, sys.stdout)
out, err = capsys.readouterr()
assert out == s

def test_02(self, capsys: Any) -> None:
s = dedent(
"""
- 1
- { f: 3.14 , g: 42 }
- { }
- [ 3.14 , 42 ]
- [ ]
"""
)
d = round_trip_load(s)

current_map_start = Emitter.flow_map_start
current_map_end = Emitter.flow_map_end
current_map_separator = Emitter.flow_map_separator
current_seq_start = Emitter.flow_seq_start
current_seq_end = Emitter.flow_seq_end
current_seq_separator = Emitter.flow_seq_separator

Emitter.flow_map_start = '{ '
Emitter.flow_map_end = ' }'
Emitter.flow_map_separator = ' ,'

Emitter.flow_seq_start = '[ '
Emitter.flow_seq_end = ' ]'
Emitter.flow_seq_separator = ' ,'

try:
round_trip_dump(d, sys.stdout)
finally:
Emitter.flow_map_start = current_map_start
Emitter.flow_map_end = current_map_end
Emitter.flow_map_separator = current_map_separator

Emitter.flow_seq_start = current_seq_start
Emitter.flow_seq_end = current_seq_end
Emitter.flow_seq_separator = current_seq_separator

out, err = capsys.readouterr()
assert out == s
2 changes: 1 addition & 1 deletion _test/test_z_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

import sys
import os
import sys
import warnings # NOQA
from pathlib import Path
from typing import Any, List, Optional, Tuple
Expand Down
6 changes: 3 additions & 3 deletions lib/ruyaml/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from ruyaml.error import MarkedYAMLError, ReusedAnchorWarning
from ruyaml.events import (
AliasEvent,
MappingStartEvent,
MappingEndEvent,
MappingStartEvent,
ScalarEvent,
SequenceStartEvent,
SequenceEndEvent,
StreamStartEvent,
SequenceStartEvent,
StreamEndEvent,
StreamStartEvent,
)
from ruyaml.nodes import MappingNode, ScalarNode, SequenceNode

Expand Down
58 changes: 37 additions & 21 deletions lib/ruyaml/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,45 @@
from collections.abc import Hashable, MutableMapping, MutableSequence # type: ignore
from datetime import timedelta as TimeDelta

# fmt: off
from ruyaml.error import (MarkedYAMLError, MarkedYAMLFutureWarning,
MantissaNoDotYAML1_1Warning)
from ruyaml.nodes import * # NOQA
from ruyaml.nodes import (SequenceNode, MappingNode, ScalarNode)
from ruyaml.compat import (builtins_module, # NOQA
nprint, nprintf, version_tnf)
from ruyaml.compat import ordereddict
from ruyaml.comments import * # NOQA
from ruyaml.comments import (
C_KEY_EOL,
C_KEY_POST,
C_KEY_PRE,
C_VALUE_EOL,
C_VALUE_POST,
C_VALUE_PRE,
CommentedKeyMap,
CommentedKeySeq,
CommentedMap,
CommentedOrderedMap,
CommentedSeq,
CommentedSet,
TaggedScalar,
)
from ruyaml.compat import builtins_module # NOQA
from ruyaml.compat import nprint, nprintf, ordereddict, version_tnf

from ruyaml.tag import Tag
from ruyaml.comments import * # NOQA
from ruyaml.comments import (CommentedMap, CommentedOrderedMap, CommentedSet,
CommentedKeySeq, CommentedSeq, TaggedScalar,
CommentedKeyMap,
C_KEY_PRE, C_KEY_EOL, C_KEY_POST,
C_VALUE_PRE, C_VALUE_EOL, C_VALUE_POST,
)
from ruyaml.scalarstring import (SingleQuotedScalarString, DoubleQuotedScalarString,
LiteralScalarString, FoldedScalarString,
PlainScalarString, ScalarString)
from ruyaml.scalarint import ScalarInt, BinaryInt, OctalInt, HexInt, HexCapsInt
from ruyaml.scalarfloat import ScalarFloat
# fmt: off
from ruyaml.error import (
MantissaNoDotYAML1_1Warning,
MarkedYAMLError,
MarkedYAMLFutureWarning,
)
from ruyaml.nodes import * # NOQA
from ruyaml.nodes import MappingNode, ScalarNode, SequenceNode
from ruyaml.scalarbool import ScalarBoolean
from ruyaml.scalarfloat import ScalarFloat
from ruyaml.scalarint import BinaryInt, HexCapsInt, HexInt, OctalInt, ScalarInt
from ruyaml.scalarstring import (
DoubleQuotedScalarString,
FoldedScalarString,
LiteralScalarString,
PlainScalarString,
ScalarString,
SingleQuotedScalarString,
)
from ruyaml.tag import Tag
from ruyaml.timestamp import TimeStamp
from ruyaml.util import create_timestamp, timestamp_regexp

Expand Down
4 changes: 2 additions & 2 deletions lib/ruyaml/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def expect_first_flow_mapping_key(self) -> None:
if isinstance(self.event, MappingEndEvent):
self.indent = self.indents.pop()
popped = self.flow_context.pop()
assert popped == '{' # empty flow mapping
assert popped == self.flow_map_start # empty flow mapping
self.write_indicator(self.flow_map_end, False)
if self.event.comment and self.event.comment[0]:
# eol comment on empty mapping
Expand All @@ -621,7 +621,7 @@ def expect_flow_mapping_key(self) -> None:
# self.write_pre_comment(self.event)
self.indent = self.indents.pop()
popped = self.flow_context.pop()
assert popped in ['{', '']
assert popped in [self.flow_map_start, '']
if self.canonical:
self.write_indicator(self.flow_map_separator, False)
self.write_indent()
Expand Down
3 changes: 1 addition & 2 deletions lib/ruyaml/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import glob
import warnings
from importlib import import_module
from io import BytesIO, StringIO
from typing import TYPE_CHECKING, Any, List, Optional, Text, Union
import warnings

import ruyaml
from ruyaml.comments import C_PRE, CommentedMap, CommentedSeq
Expand All @@ -21,7 +21,6 @@
from ruyaml.events import * # NOQA
from ruyaml.loader import BaseLoader # NOQA
from ruyaml.loader import Loader # NOQA
from ruyaml.loader import Loader as UnsafeLoader
from ruyaml.loader import RoundTripLoader, SafeLoader # NOQA
from ruyaml.nodes import * # NOQA
from ruyaml.representer import (
Expand Down
Loading