From ce8f087dde5faa533dc457444990ff97ce215452 Mon Sep 17 00:00:00 2001 From: Steven Troxler Date: Thu, 17 Oct 2024 12:06:38 -0700 Subject: [PATCH] Use PyrePysaLogic.Testing in Pysa unit tests Summary: Several of the Pysa unit tests reach into Pyre internals. It's not worth trying to eliminate this (changedPathsTest in particular is testing chnangedPaths, which is inhrently pretty exposed to the low-level logic of ModuleTracker) but for good hygiene it's nice to thread them through PyrePysaLogic.Testing so we can see exactly what Pysa relies on. Reviewed By: yangdanny97 Differential Revision: D64538838 fbshipit-source-id: aee5c1872fee7ac6e34e528a4f6820c8c767478d --- source/analysis/pyrePysaLogic.ml | 4 ++++ source/interprocedural/test/changedPathsTest.ml | 14 +++++++++----- source/interprocedural/test/fetchCallablesTest.ml | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/source/analysis/pyrePysaLogic.ml b/source/analysis/pyrePysaLogic.ml index 1546c585a06..97e09b087f1 100644 --- a/source/analysis/pyrePysaLogic.ml +++ b/source/analysis/pyrePysaLogic.ml @@ -54,4 +54,8 @@ let undecorated_signature_of_global { AttributeResolution.Global.undecorated_sig module Testing = struct module AnalysisError = AnalysisError + module ModuleTracker = ModuleTracker + module ArtifactPath = ArtifactPath + module EnvironmentControls = EnvironmentControls + module SourceCodeApi = SourceCodeApi end diff --git a/source/interprocedural/test/changedPathsTest.ml b/source/interprocedural/test/changedPathsTest.ml index 4c7f8f7bc30..e6dcf0a10a2 100644 --- a/source/interprocedural/test/changedPathsTest.ml +++ b/source/interprocedural/test/changedPathsTest.ml @@ -9,6 +9,7 @@ open Core open OUnit2 open Pyre open Test +module PyrePysaLogic = Analysis.PyrePysaLogic type locally_changed_file = { relative: string; @@ -36,7 +37,7 @@ let test_compute_locally_changed_files context = ~scheduler ~scheduler_policies ~configuration - ~module_paths:(Analysis.ModuleTracker.module_paths module_tracker) + ~module_paths:(PyrePysaLogic.Testing.ModuleTracker.module_paths module_tracker) in configuration, module_tracker in @@ -50,17 +51,20 @@ let test_compute_locally_changed_files context = in List.iter files ~f:write_new_file; let new_module_tracker = - Analysis.EnvironmentControls.create configuration |> Analysis.ModuleTracker.create + PyrePysaLogic.Testing.EnvironmentControls.create configuration + |> PyrePysaLogic.Testing.ModuleTracker.create in let actual = Interprocedural.ChangedPaths.compute_locally_changed_paths ~scheduler ~scheduler_policies ~configuration - ~old_module_paths:(Analysis.ModuleTracker.module_paths old_module_tracker) - ~new_module_paths:(Analysis.ModuleTracker.module_paths new_module_tracker) + ~old_module_paths:(PyrePysaLogic.Testing.ModuleTracker.module_paths old_module_tracker) + ~new_module_paths:(PyrePysaLogic.Testing.ModuleTracker.module_paths new_module_tracker) |> List.filter_map ~f:(fun path -> - PyrePath.get_relative_to_root ~root:local_root ~path:(ArtifactPath.raw path)) + PyrePath.get_relative_to_root + ~root:local_root + ~path:(PyrePysaLogic.Testing.ArtifactPath.raw path)) in assert_equal ~printer:(List.to_string ~f:Fn.id) diff --git a/source/interprocedural/test/fetchCallablesTest.ml b/source/interprocedural/test/fetchCallablesTest.ml index 41c5200b287..d57d952498c 100644 --- a/source/interprocedural/test/fetchCallablesTest.ml +++ b/source/interprocedural/test/fetchCallablesTest.ml @@ -8,6 +8,7 @@ open OUnit2 open Core open Interprocedural +module PyrePysaLogic = Analysis.PyrePysaLogic let test_callables context = let assert_callables ?(additional_sources = []) ?(source_filename = "test.py") source ~expected = @@ -20,7 +21,9 @@ let test_callables context = Test.ScratchProject.pyre_pysa_read_only_api scratch_project ) in let source = - Analysis.SourceCodeApi.source_of_qualifier source_code_api (Ast.Reference.create "test") + PyrePysaLogic.Testing.SourceCodeApi.source_of_qualifier + source_code_api + (Ast.Reference.create "test") |> Option.value_exn in FetchCallables.from_source ~configuration ~pyre_api ~source