Esempio n. 1
0
    def test_nop_visit(self):
        obj = Base(None, None)
        obj.not_called = Mock()

        obj.visit("missing_method")

        obj.not_called.assert_not_called()
Esempio n. 2
0
    def test_visit(self):
        obj = Base(None, None)
        obj.called = Mock()

        obj.visit("called", "with", keyword="args")

        obj.called.assert_called_once_with("with", keyword="args")
Esempio n. 3
0
    def test_build_creates_new_instance(self, data):
        obj = Base.build(Node(data, Location("stream", 1, 2)))

        assert obj.data == data
        assert obj.loc.stream_name == "stream"
        assert obj.loc.line == 1
        assert obj.loc.column == 2
Esempio n. 4
0
    def test_non_empty_visit(self):
        obj1 = Base(None, None)
        obj1.called = Mock()
        obj2 = Base(None, None)
        obj2.not_called = Mock()

        ListWrapper([obj1, obj2], None).visit("called", "with", keyword="args")

        obj1.called.assert_called_once_with("with", keyword="args")
        obj2.not_called.assert_not_called()
Esempio n. 5
0
    def test_visit(self):
        obj1 = Base(None, None)
        obj1.called = Mock()
        obj2 = Base(None, None)
        obj2.not_called = Mock()

        MapWrapper({"a": obj1, "b": obj2}, None).visit(
            "called", "with", keyword="args",
        )

        obj1.called.assert_called_once_with("with", keyword="args")
        obj2.not_called.assert_not_called()
Esempio n. 6
0
 def test_str(self, data):
     assert str(data) == str(Base(data, Location("s", 4, 5)))
Esempio n. 7
0
 def test_bare(self, data):
     assert Base(data, None).bare == data
Esempio n. 8
0
 def test_abort(self):
     with pytest.raises(ParseError, match="Error MsG"):
         Base.abort("Error MsG", None)
Esempio n. 9
0
 def test_validate_is_always_ok(self, data):
     Base.validate(data)
Esempio n. 10
0
 def test_normalize_is_noop(self, data):
     assert Base.normalize(data) == data
Esempio n. 11
0
    def test_bare(self):
        obj = ListWrapper([Base("a", None), Base("b", None)], None)

        assert obj.bare == ["a", "b"]
Esempio n. 12
0
 def test_test_non_string_key(self):
     with pytest.raises(KeyError):
         assert MapWrapper({Base(1, None): "v"}, None)[1]
Esempio n. 13
0
 def test_bare(self):
     assert MapWrapper({"a": Base("b", None)}, None).bare == {"a": "b"}