Skip to content

Commit

Permalink
Simplified sub-class finding code in general tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
benkonrath committed Jul 2, 2017
1 parent 789dad6 commit 7855fff
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import importlib
import pkgutil
import sys

from django import forms
from django.db import models
Expand All @@ -16,9 +15,9 @@
class GeneralTests(TestCase):

@staticmethod
def _find_subclasses_for_package(base_class, package):
def _find_localflavor_subclasses(base_class):
classes = []
for importer, modname, ispkg in pkgutil.walk_packages(path=package.__path__, prefix=package.__name__ + '.',
for importer, modname, ispkg in pkgutil.walk_packages(path=localflavor.__path__, prefix=localflavor.__name__ + '.',
onerror=lambda x: None):
if ispkg:
continue
Expand All @@ -27,7 +26,7 @@ def _find_subclasses_for_package(base_class, package):
if f.startswith('_'):
continue
item = getattr(module, f)
if package.__name__ in six.text_type(item):
if localflavor.__name__ in six.text_type(item):
try:
if issubclass(item, base_class):
classes.append(item)
Expand All @@ -40,7 +39,7 @@ def test_model_field_deconstruct_methods_with_default_options(self):
# This test can only check the choices and max_length options. Specific tests are required for model fields
# with options that users can set. See to the IBAN tests for an example.

model_classes = self._find_subclasses_for_package(models.Field, localflavor)
model_classes = self._find_localflavor_subclasses(models.Field)
self.assertTrue(len(model_classes) > 0, 'No localflavor models.Field classes were found.')

for cls in model_classes:
Expand All @@ -63,7 +62,7 @@ def test_model_field_deconstruct_methods_with_default_options(self):
self.assertEqual(getattr(test_instance, attr), getattr(new_instance, attr))

def test_forms_char_field_empty_value_allows_none(self):
form_classes = self._find_subclasses_for_package(forms.CharField, localflavor)
form_classes = self._find_localflavor_subclasses(forms.CharField)
self.assertTrue(len(form_classes) > 0, 'No localflavor forms.CharField classes were found.')

for cls in form_classes:
Expand Down

0 comments on commit 7855fff

Please sign in to comment.