LibCST
LibCST copied to clipboard
Using `FullyQualifiedNameProvider` in a `CodemodTest` raises `ValueError`
Hey! Pretty sure this is a test setup error on my part, but I'm trying to write a test for my codemod command using CodemodTest. The obvious code from the documentation throws an exception. Would it be possible to add an example showing how to correctly setup the cache?
from typing import Type
from pathlib import Path
from libcst.codemod import CodemodTest, Codemod, CodemodContext
from libcst.metadata import FullRepoManager, FullyQualifiedNameProvider, QualifiedNameProvider
from foo.codemod.constant import SetConstantCommand
class TestSetConstantCommand(CodemodTest):
TRANSFORM: Type[Codemod] = SetConstantCommand
def test_noop(self) -> None:
before = """
foo = "bar"
"""
after = """
foo = "bar"
"""
self.assertCodemod(
before,
after,
qualified_name="what",
value="now",
imports=[],
)
self = <libcst.metadata.name_provider.FullyQualifiedNameProvider object at 0x7f8bafb33f50>, cache = None
def __init__(self, cache: object = None) -> None:
super().__init__()
self._computed: MutableMapping["CSTNode", MaybeLazyMetadataT] = {}
if self.gen_cache and cache is None:
# The metadata provider implementation is responsible to store and use cache.
> raise ValueError(
f"Cache is required for initializing {self.__class__.__name__}."
)
E ValueError: Cache is required for initializing FullyQualifiedNameProvider.
../venv/lib/python3.12/site-packages/libcst/metadata/base_provider.py:80: ValueError