def test_nop_visit(self): obj = Base(None, None) obj.not_called = Mock() obj.visit("missing_method") obj.not_called.assert_not_called()
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")
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
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()
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()
def test_str(self, data): assert str(data) == str(Base(data, Location("s", 4, 5)))
def test_bare(self, data): assert Base(data, None).bare == data
def test_abort(self): with pytest.raises(ParseError, match="Error MsG"): Base.abort("Error MsG", None)
def test_validate_is_always_ok(self, data): Base.validate(data)
def test_normalize_is_noop(self, data): assert Base.normalize(data) == data
def test_bare(self): obj = ListWrapper([Base("a", None), Base("b", None)], None) assert obj.bare == ["a", "b"]
def test_test_non_string_key(self): with pytest.raises(KeyError): assert MapWrapper({Base(1, None): "v"}, None)[1]
def test_bare(self): assert MapWrapper({"a": Base("b", None)}, None).bare == {"a": "b"}