Repository: wagtail/wagtail
File: wagtail/search/tests/test_mysql_backend.py (Python)

Code before:
        self.assertSetEqual(
            {r.title for r in results},
            {"JavaScript: The good parts"},
        )

    def test_lexeme_validation(self):
        from wagtail.search.backends.database.mysql.query import Lexeme

        with self.assertRaises(ValueError):
            Lexeme("")

        Lexeme("hello")  # no error

        with self.assertRaises(ValueError):
            Lexeme("hello world")

        with self.assertRaises(ValueError):
            Lexeme("rimsky@korsakov")

    @skip(
        "The MySQL backend doesn't support choosing individual fields for the search, only (body, title) or (autocomplete) fields may be searched."
    )
    def test_search_on_individual_field(self):
        return super().test_search_on_individual_field()

    @skip("The MySQL backend doesn't support boosting.")
    def test_search_boosting_on_related_fields(self):
        return super().test_search_boosting_on_related_fields()

    @skip("The MySQL backend doesn't support boosting.")
    def test_boost(self):
        return super().test_boost()

    @skip("The MySQL backend doesn't score annotations.")
    def test_annotate_score(self):
        return super().test_annotate_score()

    @skip("The MySQL backend doesn't score annotations.")
    def test_annotate_score_with_slice(self):
        return super().test_annotate_score_with_slice()

    @skip("The MySQL backend doesn't guarantee correct ranking of results.")
    def test_ranking(self):
        return super().test_ranking()


Review comment (suggestion):
I'd prefer `assertRaisesMessage` for exceptions that we raise ourselves, to help catch any unintended mistakes in the message (e.g. missing/extra spaces). I'll add them in as I merge, hope that's OK!

Code after:
        self.assertSetEqual(
            {r.title for r in results},
            {"JavaScript: The good parts"},
        )

    def test_lexeme_validation(self):
        from wagtail.search.backends.database.mysql.query import Lexeme

        with self.assertRaisesMessage(ValueError, "Lexeme value cannot be empty."):
            Lexeme("")

        Lexeme("hello")  # no error

        with self.assertRaises(
            ValueError,
            "Lexeme value 'hello world' must consist of alphanumeric characters "
            "and '_' only.",
        ):
            Lexeme("hello world")

        with self.assertRaises(
            ValueError,
            "Lexeme value 'hello world' must consist of alphanumeric characters "
            "and '_' only.",
        ):
            Lexeme("rimsky@korsakov")

    @skip(
        "The MySQL backend doesn't support choosing individual fields for the search, only (body, title) or (autocomplete) fields may be searched."
    )
    def test_search_on_individual_field(self):
        return super().test_search_on_individual_field()

    @skip("The MySQL backend doesn't support boosting.")
    def test_search_boosting_on_related_fields(self):
        return super().test_search_boosting_on_related_fields()

    @skip("The MySQL backend doesn't support boosting.")
    def test_boost(self):
        return super().test_boost()

    @skip("The MySQL backend doesn't score annotations.")
    def test_annotate_score(self):
        return super().test_annotate_score()

    @skip("The MySQL backend doesn't score annotations.")
    def test_annotate_score_with_slice(self):
        return super().test_annotate_score_with_slice()

    @skip("The MySQL backend doesn't guarantee correct ranking of results.")
    def test_ranking(self):