-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
guibog
committed
Feb 29, 2024
1 parent
0a12be2
commit 2128c8b
Showing
7 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
|
||
import pytest | ||
import io | ||
import ruyaml # NOQA | ||
from .roundtrip import round_trip, dedent | ||
|
||
from ruyaml import YAML | ||
from ruyaml.util import load_yaml_guess_indent | ||
from ruyaml.scalarbool import ScalarBoolean | ||
from ruyaml.comments import CommentedSeq | ||
from ruyaml.representer import RoundTripRepresenter, ScalarNode | ||
from ruyaml.constructor import RoundTripConstructor | ||
from typing import Text, Any, Dict, List # NOQA | ||
|
||
|
||
class ScalarNodePositioned(ScalarNode): | ||
lc_position = None | ||
|
||
|
||
class ScalarBooleanStable(ScalarBoolean): | ||
|
||
def __new__(cls: Any, boolval, origrepr, anchor=None) -> Any: | ||
b = ScalarBoolean.__new__(cls, boolval, anchor=anchor) | ||
b.original_bool_repr = origrepr | ||
return b | ||
|
||
|
||
#def represent_list2(self, data): | ||
# dedede | ||
# RoundTripRepresenter.add_representer(CommentedSeq, represent_list2) | ||
|
||
|
||
class BetterRoundTripConstructor(RoundTripConstructor): | ||
keep_bool_repr = True | ||
|
||
|
||
class BetterRoundTripRepresenter(RoundTripRepresenter): | ||
def represent_bool(self, data, anchor=None): | ||
ret = self.represent_scalar('tag:yaml.org,2002:bool', data.original_bool_repr, anchor=anchor) | ||
return ret | ||
|
||
def TOTO_represent_sequence(self, tag, data): | ||
node = super().represent_sequence(tag, data) | ||
print(44, self, tag, data, node) | ||
# print(45, data.lc, data.lc.data) | ||
local_block_seq_ident = -1 | ||
|
||
|
||
#BetterRoundTripConstructor.add_constructor('tag:yaml.org,2002:bool', BetterRoundTripConstructor.construct_yaml_bool) | ||
#BetterRoundTripRepresenter.add_representer(ScalarBooleanStable, BetterRoundTripRepresenter.represent_bool) | ||
|
||
|
||
def round_trip_stabler( | ||
inp, | ||
outp=None, | ||
): | ||
if outp is None: | ||
outp = inp | ||
doutp = dedent(outp) | ||
yaml = ruyaml.YAML() | ||
yaml.preserve_quotes = True | ||
yaml.preserve_block_seqs_indents = True | ||
data = yaml.load(doutp) | ||
buf = io.StringIO() | ||
yaml.dump(data, stream=buf) | ||
res = buf.getvalue() | ||
assert res == doutp | ||
|
||
|
||
class TestStability: | ||
|
||
def test_blockseq1(self): | ||
round_trip( | ||
""" | ||
a: | ||
- a1 | ||
- a2 | ||
""" | ||
) | ||
|
||
@pytest.mark.xfail(strict=True) | ||
def test_blockseq2(self): | ||
round_trip( | ||
""" | ||
a: | ||
- a1 | ||
- a2 | ||
""" | ||
) | ||
|
||
@pytest.mark.xfail(strict=True) | ||
def test_blockseq3(self): | ||
round_trip( | ||
""" | ||
a: | ||
- a1 | ||
- a2 | ||
b: | ||
- b1 | ||
- b2 | ||
""" | ||
) | ||
|
||
class TestStabilityStabler: | ||
|
||
def test_blockseq1(self): | ||
round_trip_stabler( | ||
""" | ||
a: | ||
- a1 | ||
- a2 | ||
""" | ||
) | ||
|
||
def test_blockseq2(self): | ||
round_trip_stabler( | ||
""" | ||
a: | ||
- a1 | ||
- a2 | ||
""" | ||
) | ||
|
||
def test_blockseq3(self): | ||
round_trip_stabler( | ||
""" | ||
a: | ||
- a1 | ||
- a2 | ||
b: | ||
- b1 | ||
- b2 | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters