def test_construct_bool_true(self, value, parse):
        mark = Mark(None, None, 4, 5, None, None)
        node = ScalarNode(None, value, start_mark=mark)
        res = Constructor("bool").construct_yaml_bool(node)

        assert res.value == parse
        assert res.loc.line == 5
        assert res.loc.column == 6
        assert res.loc.stream_name == "bool"
    def test_construct_int(self, value, parse):
        mark = Mark(None, None, 3, 7, None, None)
        node = ScalarNode(None, value, start_mark=mark)
        res = Constructor("int").construct_yaml_int(node)

        assert res.value == parse
        assert res.loc.line == 4
        assert res.loc.column == 8
        assert res.loc.stream_name == "int"
    def test_construct_str(self, value):
        mark = Mark(None, None, 0, 0, None, None)
        node = ScalarNode(None, value, start_mark=mark)
        res = Constructor("str").construct_yaml_str(node)

        assert res.value == value
        assert res.loc.line == 1
        assert res.loc.column == 1
        assert res.loc.stream_name == "str"
    def test_construct_null(self, value):
        mark = Mark(None, None, 1, 2, None, None)
        node = ScalarNode(None, value, start_mark=mark)
        res = Constructor("null").construct_yaml_null(node)

        assert res.value is None
        assert res.loc.line == 2
        assert res.loc.column == 3
        assert res.loc.stream_name == "null"
    def test_construct_float_nan_only(self, value):
        mark = Mark(None, None, 7, 1, None, None)
        node = ScalarNode(None, value, start_mark=mark)
        res = Constructor("float").construct_yaml_float(node)

        assert math.isnan(res.value)
        assert res.loc.line == 8
        assert res.loc.column == 2
        assert res.loc.stream_name == "float"
    def test_construct_float_no_nan(self, value, parse):
        mark = Mark(None, None, 2, 8, None, None)
        node = ScalarNode(None, value, start_mark=mark)
        res = Constructor("float").construct_yaml_float(node)

        assert res.value == parse
        assert res.loc.line == 3
        assert res.loc.column == 9
        assert res.loc.stream_name == "float"
 def test_construct_map_duplicate(self):
     mark = Mark(None, None, 8, 8, None, None)
     children = [
         (
             ScalarNode("tag:yaml.org,2002:str", "node1", start_mark=mark),
             ScalarNode("tag:yaml.org,2002:str", "node1", start_mark=mark),
         ),
         (
             ScalarNode("tag:yaml.org,2002:str", "node1", start_mark=mark),
             ScalarNode("tag:yaml.org,2002:str", "node1", start_mark=mark),
         )
     ]
     node = MappingNode("tag:yaml.org,2002:map", children, start_mark=mark)
     with pytest.raises(ConstructorError):
         res, = Constructor("map").construct_yaml_map(node)
    def test_construct_seq(self):
        mark = Mark(None, None, 4, 3, None, None)
        children = [
            ScalarNode("tag:yaml.org,2002:int", str(i), start_mark=mark)
            for i in range(4)
        ]
        node = SequenceNode(None, children, start_mark=mark)
        # Sequences are single-element generators (lazy parsing) that we need
        # to exhaust. Simplest way of doing this is to assign to a single
        # element tuple and let the python do all the iterator funky-ness.
        res, = Constructor("seq").construct_yaml_seq(node)

        assert [0, 1, 2, 3] == [child.value for child in res.value]
        assert res.loc.line == 5
        assert res.loc.column == 4
        assert res.loc.stream_name == "seq"
    def test_construct_map(self):
        mark = Mark(None, None, 8, 8, None, None)
        children = [(
            ScalarNode("tag:yaml.org,2002:str", str(i), start_mark=mark),
            ScalarNode("tag:yaml.org,2002:int", str(i), start_mark=mark),
        ) for i in range(2)]
        node = MappingNode(None, children, start_mark=mark)
        res, = Constructor("map").construct_yaml_map(node)

        assert {
            "0": 0,
            "1": 1
        } == {k.value: v.value
              for k, v in res.value.items()}
        assert res.loc.line == 9
        assert res.loc.column == 9
        assert res.loc.stream_name == "map"