|
1 | 1 | import pytest
|
| 2 | +from importlib.util import find_spec |
2 | 3 | from tests.utils import EnumTypeMixin, IGNORE_ORA_01843
|
3 | 4 | from django.test import TestCase
|
4 | 5 | from django.db import connection
|
@@ -726,67 +727,26 @@ def test_clean(self):
|
726 | 727 | self.assertTrue("text" in ve.message_dict)
|
727 | 728 | self.assertTrue("extern" in ve.message_dict)
|
728 | 729 |
|
729 |
| - def do_rest_framework_missing(self): |
| 730 | + @pytest.mark.skipif( |
| 731 | + find_spec("rest_framework") is not None, reason="rest_framework is installed" |
| 732 | + ) |
| 733 | + def test_rest_framework_missing(self): |
730 | 734 | with self.assertRaises(ImportError):
|
731 | 735 | from django_enum.drf import EnumField
|
732 | 736 |
|
733 |
| - def test_rest_framework_missing(self): |
734 |
| - import sys |
735 |
| - from importlib import reload |
736 |
| - from unittest.mock import patch |
737 |
| - |
738 |
| - if "rest_framework.fields" in sys.modules: |
739 |
| - with patch.dict(sys.modules, {"rest_framework.fields": None}): |
740 |
| - reload(sys.modules["django_enum.drf"]) |
741 |
| - self.do_rest_framework_missing() |
742 |
| - reload(sys.modules["django_enum.drf"]) |
743 |
| - else: |
744 |
| - self.do_rest_framework_missing() # pragma: no cover |
745 |
| - |
746 |
| - def do_django_filters_missing(self): |
747 |
| - |
| 737 | + @pytest.mark.skipif( |
| 738 | + find_spec("django_filters") is not None, reason="django-filter is installed" |
| 739 | + ) |
| 740 | + def test_django_filters_missing(self): |
748 | 741 | with self.assertRaises(ImportError):
|
749 | 742 | from django_enum.filters import EnumFilter
|
750 | 743 |
|
751 |
| - |
752 |
| - def test_django_filters_missing(self): |
753 |
| - import sys |
754 |
| - from importlib import reload |
755 |
| - from unittest.mock import patch |
756 |
| - |
757 |
| - if "django_filters" in sys.modules: |
758 |
| - with patch.dict(sys.modules, {"django_filters": None}): |
759 |
| - reload(sys.modules["django_enum.filters"]) |
760 |
| - self.do_django_filters_missing() |
761 |
| - reload(sys.modules["django_enum.filters"]) |
762 |
| - else: |
763 |
| - self.do_django_filters_missing() # pragma: no cover |
764 |
| - |
765 |
| - def do_enum_properties_missing(self): |
766 |
| - |
| 744 | + @pytest.mark.skipif( |
| 745 | + find_spec("enum_properties") is not None, reason="enum-properties is installed" |
| 746 | + ) |
| 747 | + def test_enum_properties_missing(self): |
767 | 748 | with self.assertRaises(ImportError):
|
768 |
| - from django_enum.choices import ( |
769 |
| - DjangoEnumPropertiesMeta, |
770 |
| - DjangoSymmetricMixin, |
771 |
| - FloatChoices, |
772 |
| - IntegerChoices, |
773 |
| - TextChoices, |
774 |
| - ) |
| 749 | + from django_enum.choices import TextChoices |
775 | 750 |
|
776 | 751 | self.do_test_integer_choices()
|
777 | 752 | self.do_test_text_choices()
|
778 |
| - |
779 |
| - def test_enum_properties_missing(self): |
780 |
| - import sys |
781 |
| - from importlib import reload |
782 |
| - from unittest.mock import patch |
783 |
| - |
784 |
| - if "enum_properties" in sys.modules: |
785 |
| - with patch.dict(sys.modules, {"enum_properties": None}): |
786 |
| - from django_enum import choices |
787 |
| - |
788 |
| - reload(sys.modules["django_enum.choices"]) |
789 |
| - self.do_enum_properties_missing() |
790 |
| - reload(sys.modules["django_enum.choices"]) |
791 |
| - else: |
792 |
| - self.do_enum_properties_missing() # pragma: no cover |
0 commit comments