PythonVisitorContext { public PythonFile pythonFile() { return pythonFile; } PythonVisitorContext(FileInput rootTree, PythonFile pythonFile, @Nullable File workingDirectory, @Nullable String packageName);  PythonVisitorContext(FileInput rootTree, PythonFile pythonFile, @Nullable File workingDirectory, String packageName, ProjectLevelSymbolTable projectLevelSymbolTable);  PythonVisitorContext(PythonFile pythonFile, RecognitionException parsingException); FileInput rootTree(); PythonFile pythonFile(); RecognitionException parsingException(); void addIssue(PreciseIssue issue); List<PreciseIssue> getIssues(); @CheckForNull File workingDirectory();  }
@Test public void fullyQualifiedModuleName() { FileInput fileInput = PythonTestUtils.parse("def foo(): pass"); PythonFile pythonFile = pythonFile("my_module.py"); new PythonVisitorContext(fileInput, pythonFile, null, "my_package"); FunctionDef functionDef = (FunctionDef) PythonTestUtils.getAllDescendant(fileInput, t -> t.is(Tree.Kind.FUNCDEF)).get(0); assertThat(functionDef.name().symbol().fullyQualifiedName()).isEqualTo("my_package.my_module.foo"); new PythonVisitorContext(fileInput, pythonFile, null, ""); assertThat(functionDef.name().symbol().fullyQualifiedName()).isEqualTo("my_module.foo"); Mockito.when(pythonFile.fileName()).thenReturn("my_module"); new PythonVisitorContext(fileInput, pythonFile, null, "my_package"); functionDef = (FunctionDef) PythonTestUtils.getAllDescendant(fileInput, t -> t.is(Tree.Kind.FUNCDEF)).get(0); assertThat(functionDef.name().symbol().fullyQualifiedName()).isEqualTo("my_package.my_module.foo"); }
@Test public void initModuleFullyQualifiedName() { FileInput fileInput = PythonTestUtils.parse("def fn(): pass"); PythonFile pythonFile = pythonFile("__init__.py"); new PythonVisitorContext(fileInput, pythonFile, null, "foo.bar"); FunctionDef functionDef = (FunctionDef) PythonTestUtils.getAllDescendant(fileInput, t -> t.is(Tree.Kind.FUNCDEF)).get(0); assertThat(functionDef.name().symbol().fullyQualifiedName()).isEqualTo("foo.bar.fn"); new PythonVisitorContext(fileInput, pythonFile, null, ""); assertThat(functionDef.name().symbol().fullyQualifiedName()).isEqualTo("fn"); }