Exemplo n.º 1
0
 def test_upgrade_configuration(
     self, run_fixme, get_errors, remove_version, call
 ) -> None:
     arguments = MagicMock()
     get_errors.return_value = []
     upgrade.run_fixme_all(arguments, [])
     run_fixme.assert_not_called()
     call.assert_not_called()
     errors = [
         {
             "line": 2,
             "column": 4,
             "path": "local.py",
             "code": 7,
             "name": "Kind",
             "description": "Error",
             "inference": {},
             "ignore_error": False,
             "external_to_global_root": False,
         }
     ]
     get_errors.return_value = errors
     configuration = upgrade.Configuration(
         "/root/local/.pyre_configuration.local", {}
     )
     configuration.get_path()
     upgrade._upgrade_configuration(arguments, configuration, "/root")
     run_fixme.called_once_with(arguments, _result(errors))
     call.assert_called_once_with(
         ["hg", "commit", "--message", "[typing] Update pyre version for local"]
     )
Exemplo n.º 2
0
    def test_get_errors(self, run, call) -> None:
        configuration = upgrade.Configuration("path", {})
        configuration.get_errors()
        call.assert_not_called()
        assert run.call_count == 1

        call.reset_mock()
        run.reset_mock()

        configuration.targets = ["//target/..."]
        configuration.get_errors()
        assert call.call_count == 1
        assert run.call_count == 1
Exemplo n.º 3
0
    def test_run_fixme_single(self, run_fixme, get_errors, remove_version,
                              find_configuration, call) -> None:
        arguments = MagicMock()
        arguments.path = "local"
        get_errors.return_value = []
        configuration_contents = '{"targets":[]}'
        with patch("builtins.open",
                   mock_open(read_data=configuration_contents)):
            upgrade.run_fixme_single(arguments, [])
            run_fixme.assert_not_called()
            call.assert_not_called()

        configuration_contents = '{"version": 123}'
        with patch("builtins.open",
                   mock_open(read_data=configuration_contents)):
            upgrade.run_fixme_single(arguments, [])
            run_fixme.assert_not_called()
            call.assert_called_once_with([
                "hg", "commit", "--message",
                upgrade._commit_message("local")
            ])

        run_fixme.reset_mock()
        call.reset_mock()
        errors = [{
            "line": 2,
            "column": 4,
            "path": "local.py",
            "code": 7,
            "name": "Kind",
            "description": "Error",
            "inference": {},
            "ignore_error": False,
            "external_to_global_root": False,
        }]
        get_errors.return_value = errors
        with patch("builtins.open",
                   mock_open(read_data=configuration_contents)):
            upgrade.run_fixme_single(arguments, [])
            run_fixme.called_once_with(arguments, _result(errors))
            call.assert_called_once_with([
                "hg", "commit", "--message",
                upgrade._commit_message("local")
            ])
Exemplo n.º 4
0
    def test_run_fixme_all(
        self,
        run_fixme,
        run_global_version_update,
        get_errors,
        remove_version,
        find_configuration,
        gather,
        call,
    ) -> None:
        arguments = MagicMock()
        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()
        run_fixme.assert_not_called()
        call.assert_called_once_with(
            ["hg", "commit", "--message",
             upgrade._commit_message("local")])

        run_fixme.reset_mock()
        call.reset_mock()
        errors = [{
            "line": 2,
            "column": 4,
            "path": "local.py",
            "code": 7,
            "name": "Kind",
            "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()
        run_fixme.called_once_with(arguments, _result(errors))
        call.assert_called_once_with(
            ["hg", "commit", "--message",
             upgrade._commit_message("local")])

        run_fixme.reset_mock()
        call.reset_mock()
        gather.return_value = [
            upgrade.Configuration("local/.pyre_configuration.local", {})
        ]
        upgrade.run_fixme_all(arguments, [])
        run_fixme.assert_not_called()
        call.assert_not_called()

        run_fixme.reset_mock()
        call.reset_mock()
        gather.return_value = [
            upgrade.Configuration("local/.pyre_configuration.local",
                                  {"version": 123})
        ]
        arguments.hash = "abc"
        upgrade.run_fixme_all(arguments, [])
        run_global_version_update.assert_called_once_with(arguments, [])
        run_fixme.called_once_with(arguments, _result(errors))
        call.assert_called_once_with(
            ["hg", "commit", "--message",
             upgrade._commit_message("local")])