Beispiel #1
0
    def test_stoplackd(self):
        # set up
        self.view.run_command("blackd_start")
        self.assertTrue(
            sublack.check_blackd_on_http(self.port),
            "ensure blackd is running for the test",
        )

        # already running, normal way
        sublime.run_command("blackd_stop")
        self.assertRaises(
            requests.ConnectionError,
            lambda: requests.post(
                "http://localhost:" + self.port, "server should be down"
            ),
        )
        self.assertEqual(
            self.view.get_status(sublack.STATUS_KEY),
            sublack.BLACKD_STOPPED,
            "should tell it stops",
        )

        # already stopped
        sublime.run_command("blackd_stop")
        self.assertEqual(
            self.view.get_status(sublack.STATUS_KEY),
            sublack.BLACKD_STOP_FAILED,
            "status tell stop failed",
        )
Beispiel #2
0
    def test_startblackd(self):
        # First normal Run
        self.view.run_command("blackd_start")
        self.assertTrue(sublack.check_blackd_on_http(self.port),
                        "should have been formatted")
        self.assertEqual(
            self.view.get_status(sublack.STATUS_KEY),
            sublack.BLACKD_STARTED.format(self.port),
            "sould tell it starts",
        )

        # already running aka port in use
        with patch("sublime.message_dialog"):
            self.view.run_command("blackd_start")
        self.assertEqual(
            self.view.get_status(sublack.STATUS_KEY),
            sublack.BLACKD_ALREADY_RUNNING.format(self.port),
            "sould tell it fails",
        )