messing around with the `find_needle` plugin in <t...
# plugins
r
messing around with the
find_needle
plugin in the testing docs and pushed an example here: https://github.com/njgrisafi/pants-example/tree/find-needle getting a test error:
Copy code
request = HydrateSourcesRequest(field=<class 'pants.engine.target.Sources'>(alias='sources', address=//:t1, value={repr(self.value)}, default={repr(self.default)}), for_sources_types=(<class 'pants.engine.target.Sources'>,), enable_codegen=False)

    def mock_hydrate_sources(request: HydrateSourcesRequest) -> HydratedSources:
        # Our rule only looks at `HydratedSources.snapshot.files`, so we mock all other fields. We
        # include the file `needle.txt` for the target `:t2`, but no other targets.
        files = (
            ("needle.txt", "foo.txt")
            if request.field.address.target_name == "t2"
            else ("foo.txt", "bar.txt")
        )
>       mock_snapshot = Snapshot(EMPTY_DIGEST, files=files, dirs=())
E       TypeError: PySnapshot.__new__()() takes at most 0 arguments (3 given)
Any ideas why this is?
f
Snapshot can only be directly initialized to be empty. There is a “private but exposed for testing”
_create_for_testing
class method that you can use.
cc @hundreds-father-404 — not sure how widely we wanted to expose that testing method though
h
Ah, you used to be able to create Snapshots directly. That changed back in 2.4(?) now that the type is defined in Rust, rather than in Python This example needs to be reworked. Thanks for catching this and reporting
👍 1