Skip to content

Commit

Permalink
Use PyrePysaLogic.Testing in Pysa unit tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stroxler authored and facebook-github-bot committed Oct 17, 2024
1 parent 1b48644 commit ce8f087
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions source/analysis/pyrePysaLogic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions source/interprocedural/test/changedPathsTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Core
open OUnit2
open Pyre
open Test
module PyrePysaLogic = Analysis.PyrePysaLogic

type locally_changed_file = {
relative: string;
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion source/interprocedural/test/fetchCallablesTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit ce8f087

Please sign in to comment.