Ejemplo n.º 1
0
    def test_upgrade_project(
        self,
        fix,
        run_global_version_update,
        gather,
        get_errors,
        remove_version,
        subprocess,
    ) -> None:
        arguments = MagicMock()
        arguments.lint = False
        gather.return_value = []
        upgrade.run_fixme_all(arguments)
        fix.assert_not_called()
        subprocess.assert_not_called()

        errors = [
            {
                "line": 2,
                "column": 4,
                "path": "local.py",
                "code": 7,
                "name": "Kind",
                "concise_description": "Error",
                "inference": {},
                "ignore_error": False,
                "external_to_global_root": False,
            }
        ]
        get_errors.return_value = errors
        configuration = upgrade.Configuration(
            "/root/local/.pyre_configuration.local", {"version": 123}
        )
        configuration.get_path()
        upgrade._upgrade_project(arguments, configuration, "/root")
        run_global_version_update.assert_not_called()
        fix.called_once_with(arguments, upgrade.sort_errors(errors))
        subprocess.assert_called_once_with(
            ["hg", "commit", "--message", upgrade._commit_message("local")]
        )

        # Test with lint
        subprocess.reset_mock()
        fix.reset_mock()
        arguments.lint = True
        upgrade._upgrade_project(arguments, configuration, "/root")
        run_global_version_update.assert_not_called()
        fix.called_once_with(arguments, upgrade.sort_errors(errors))
        calls = [
            call(["arc", "lint", "--never-apply-patches", "--output", "none"]),
            call().__bool__(),
            call(["arc", "lint", "--apply-patches", "--output", "none"]),
            call(["hg", "commit", "--message", upgrade._commit_message("local")]),
        ]
        subprocess.assert_has_calls(calls)
Ejemplo n.º 2
0
    def test_run_fixme_single(self, fix, get_errors, remove_version,
                              find_configuration, subprocess) -> None:
        arguments = MagicMock()
        arguments.sandcastle = None
        arguments.submit = True
        arguments.path = Path("local")
        get_errors.return_value = []
        configuration_contents = '{"targets":[]}'
        with patch("builtins.open",
                   mock_open(read_data=configuration_contents)):
            upgrade.run_fixme_single(arguments)
            fix.assert_not_called()
            subprocess.assert_not_called()

        configuration_contents = '{"version": 123}'
        with patch("builtins.open",
                   mock_open(read_data=configuration_contents)):
            upgrade.run_fixme_single(arguments)
            fix.assert_not_called()
            calls = [
                call([
                    "hg", "commit", "--message",
                    upgrade._commit_message("local")
                ]),
                call(["jf", "submit", "--update-fields"]),
            ]
            subprocess.assert_has_calls(calls)

        fix.reset_mock()
        subprocess.reset_mock()
        pyre_errors = [{
            "line": 2,
            "column": 4,
            "path": "local.py",
            "code": 7,
            "name": "Kind",
            "concise_description": "Error",
            "inference": {},
            "ignore_error": False,
            "external_to_global_root": False,
        }]
        get_errors.return_value = pyre_errors
        with patch("builtins.open",
                   mock_open(read_data=configuration_contents)):
            upgrade.run_fixme_single(arguments)
            fix.called_once_with(arguments, errors.sort_errors(pyre_errors))
            calls = [
                call([
                    "hg", "commit", "--message",
                    upgrade._commit_message("local")
                ]),
                call(["jf", "submit", "--update-fields"]),
            ]
            call.assert_has_calls(calls)
Ejemplo n.º 3
0
    def test_run_fixme_all(
        self,
        fix,
        run_global_version_update,
        get_errors,
        remove_version,
        find_configuration,
        gather,
        subprocess,
    ) -> None:
        arguments = MagicMock()
        arguments.lint = False
        gather.return_value = [
            upgrade.Configuration("local/.pyre_configuration.local", {"version": 123})
        ]
        get_errors.return_value = []
        upgrade.run_fixme_all(arguments)
        run_global_version_update.assert_not_called()
        fix.assert_not_called()
        subprocess.assert_called_once_with(
            ["hg", "commit", "--message", upgrade._commit_message("local")]
        )

        fix.reset_mock()
        subprocess.reset_mock()
        errors = [
            {
                "line": 2,
                "column": 4,
                "path": "local.py",
                "code": 7,
                "name": "Kind",
                "concise_description": "Error",
                "inference": {},
                "ignore_error": False,
                "external_to_global_root": False,
            }
        ]
        get_errors.return_value = errors
        upgrade.run_fixme_all(arguments)
        run_global_version_update.assert_not_called()
        fix.called_once_with(arguments, upgrade.sort_errors(errors))
        subprocess.assert_called_once_with(
            ["hg", "commit", "--message", upgrade._commit_message("local")]
        )

        # Test configuraton with no version set
        fix.reset_mock()
        subprocess.reset_mock()
        gather.return_value = [
            upgrade.Configuration("local/.pyre_configuration.local", {})
        ]
        upgrade.run_fixme_all(arguments)
        fix.assert_not_called()
        subprocess.assert_not_called()

        # Test with given hash
        fix.reset_mock()
        subprocess.reset_mock()
        gather.return_value = [
            upgrade.Configuration("local/.pyre_configuration.local", {"version": 123})
        ]
        arguments.hash = "abc"
        arguments.submit = True
        upgrade.run_fixme_all(arguments)
        run_global_version_update.assert_called_once_with(arguments)
        fix.called_once_with(arguments, upgrade.sort_errors(errors))
        calls = [
            call(["hg", "commit", "--message", upgrade._commit_message("local")]),
            call(["jf", "submit", "--update-fields", "--no-deps"]),
        ]
        subprocess.assert_has_calls(calls)

        # Test with linting
        fix.reset_mock()
        subprocess.reset_mock()
        run_global_version_update.reset_mock()
        arguments.lint = True
        upgrade.run_fixme_all(arguments)
        run_global_version_update.assert_called_once_with(arguments)
        fix.called_once_with(arguments, upgrade.sort_errors(errors))
        calls = [
            call(["hg", "commit", "--message", upgrade._commit_message("local")]),
            call(["jf", "submit", "--update-fields", "--no-deps"]),
        ]
        subprocess.assert_has_calls(calls)
Ejemplo n.º 4
0
    def test_upgrade_project(
        self,
        fix,
        run_global_version_update,
        errors_from_stdin,
        gather,
        get_errors,
        remove_version,
        subprocess,
    ) -> None:
        arguments = MagicMock()
        arguments.lint = False
        arguments.from_stdin = False
        gather.return_value = []
        upgrade.run_fixme_all(arguments)
        fix.assert_not_called()
        subprocess.assert_not_called()

        pyre_errors = [{
            "line": 2,
            "column": 4,
            "path": "local.py",
            "code": 7,
            "name": "Kind",
            "concise_description": "Error",
            "inference": {},
            "ignore_error": False,
            "external_to_global_root": False,
        }]
        get_errors.return_value = pyre_errors
        configuration = upgrade.Configuration(
            Path("/root/local/.pyre_configuration.local"), {"version": 123})
        configuration.get_path()
        upgrade._upgrade_project(arguments, configuration, Path("/root"))
        run_global_version_update.assert_not_called()
        fix.called_once_with(arguments, errors.sort_errors(pyre_errors))
        subprocess.assert_called_once_with(
            ["hg", "commit", "--message",
             upgrade._commit_message("local")])

        # Test with lint
        subprocess.reset_mock()
        fix.reset_mock()
        arguments.from_stdin = False
        arguments.lint = True
        upgrade._upgrade_project(arguments, configuration, Path("/root"))
        errors_from_stdin.assert_not_called()
        run_global_version_update.assert_not_called()
        fix.called_once_with(arguments, errors.sort_errors(pyre_errors))
        calls = [
            call([
                "arc",
                "lint",
                "--never-apply-patches",
                "--enforce-lint-clean",
                "--output",
                "none",
            ]),
            call().__bool__(),
            call(["arc", "lint", "--apply-patches", "--output", "none"]),
            call([
                "hg", "commit", "--message",
                upgrade._commit_message("local")
            ]),
        ]
        subprocess.assert_has_calls(calls)

        # Test with from_stdin and lint
        subprocess.reset_mock()
        fix.reset_mock()
        get_errors.reset_mock()
        arguments.from_stdin = True
        arguments.lint = True
        errors_from_stdin.return_value = pyre_errors
        get_errors.return_value = pyre_errors
        upgrade._upgrade_project(arguments, configuration, Path("/root"))
        # Called in the first round to get initial errors
        errors_from_stdin.assert_called()
        # Called in the second round to get new errors after applying lint.
        get_errors.assert_called_once()
        run_global_version_update.assert_not_called()
        fix.called_once_with(arguments, errors.sort_errors(pyre_errors))
        calls = [
            call([
                "arc",
                "lint",
                "--never-apply-patches",
                "--enforce-lint-clean",
                "--output",
                "none",
            ]),
            call().__bool__(),
            call(["arc", "lint", "--apply-patches", "--output", "none"]),
            call([
                "hg", "commit", "--message",
                upgrade._commit_message("local")
            ]),
        ]
        subprocess.assert_has_calls(calls)