Ejemplo n.º 1
0
 def assert_init(
     valid_configurations: List[str],
     valid_local_configurations: List[str],
     path: str,
     expected_project_root: Optional[str],
     expected_local_root: Optional[str],
     expected_command: Optional[List[str]],
 ) -> None:
     valid_files = [
         os.path.join(file, ".pyre_configuration")
         for file in valid_configurations
     ]
     valid_local_files = [
         os.path.join(file, ".pyre_configuration.local")
         for file in valid_local_configurations
     ]
     isfile.side_effect = lambda x: x in (valid_files +
                                          valid_local_files)
     if not expected_project_root or not expected_command:
         with self.assertRaises(PyreServerException):
             pyre_ast = PyreAst(path)
     else:
         pyre_ast = PyreAst(path)
         self.assertEqual(pyre_ast._project_configuration,
                          expected_project_root)
         self.assertEqual(pyre_ast._local_configuration,
                          expected_local_root)
Ejemplo n.º 2
0
 def assert_typed_ast(
     file_types: Mapping[Location, Annotation],
     existing_ast: ast.AST,
     expected_ast: ast.AST,
 ) -> None:
     pyre_ast = PyreAst("/config_root")
     pyre_ast._local_configuration = "/config_root"
     pyre_ast._project_configuration = "/config_root"
     expected_ast: ast.AST = AddTypeAttribute().visit(expected_ast)
     with patch.object(PyreAst, "_query_file_types", return_value=file_types):
         typed_ast = pyre_ast.typed_ast(existing_ast, "/config_root/file.py")
         self.maxDiff = None
         self.assertEqual(
             ast.dump(expected_ast, include_attributes=True),
             ast.dump(typed_ast, include_attributes=True),
         )
Ejemplo n.º 3
0
 def assert_file_types(
         json_response: str,
         expected_file_types: Mapping[Location, Annotation]) -> None:
     pyre_ast = PyreAst("/config_root")
     pyre_ast._command = ["pyre", "-l", "/config_root"]
     # Configure process stdout file
     process_mock = Mock()
     mock_stdout = json_response.encode("utf-8")
     process_mock.communicate.return_value = (mock_stdout, "")
     subprocess_popen.return_value = process_mock
     # Check query output
     file_types = pyre_ast._query_file_types("/config_root/file.py")
     message = "Expected: %s\nGot: %s" % (
         self.print_file_types(expected_file_types),
         self.print_file_types(file_types),
     )
     self.assertEqual(expected_file_types, file_types, message)
Ejemplo n.º 4
0
 def assert_file_types(
         json_response: str,
         expected_file_types: Mapping[Location, Annotation]) -> None:
     pyre_ast = PyreAst("/config_root")
     pyre_ast._local_configuration = "/config_root"
     # Configure process stdout file
     process_mock = Mock()
     mock_stdout = NamedTemporaryFile()
     mock_stdout.write(json_response.encode("utf-8"))
     mock_stdout.seek(0)
     process_mock.configure_mock(stdout=mock_stdout,
                                 stderr=NamedTemporaryFile())
     subprocess_popen.return_value = process_mock
     # Check query output
     file_types = pyre_ast._query_file_types("/config_root/file.py")
     message = "Expected: %s\nGot: %s" % (
         self.print_file_types(expected_file_types),
         self.print_file_types(file_types),
     )
     self.assertEqual(expected_file_types, file_types, message)
Ejemplo n.º 5
0
 def __init__(self, tree: ast.Module, lines: List[str], repository: str,
              filename: str) -> None:
     self.tree = PyreAst(repository).typed_ast(tree, filename)
     self.lines = lines
     self.filename = Path(filename).resolve()