diff --git a/djfractions/__init__.py b/djfractions/__init__.py index f025652..ee1bbd3 100644 --- a/djfractions/__init__.py +++ b/djfractions/__init__.py @@ -1,4 +1,4 @@ -__version__ = "3.0.0" +__version__ = "3.1.0" import fractions import re @@ -101,7 +101,7 @@ def quantity_to_decimal(quantity_string: str) -> Decimal: # get actual fraction-like strings to be N/N with no spaces quantity_string = quantity_string.strip() - quantity_string = re.sub(r'\b(\d+)\s+/\s+(\d+)\b', r'\1/\2', quantity_string) + quantity_string = re.sub(r"\b(\d+)\s+/\s+(\d+)\b", r"\1/\2", quantity_string) if is_number(quantity_string): return Decimal(quantity_string) @@ -141,7 +141,7 @@ def quantity_to_fraction(quantity_string: str) -> fractions.Fraction: """ # get actual fraction-like strings to be N/N with no spaces quantity_string = quantity_string.strip() - quantity_string = re.sub(r'\b(\d+)\s+/\s+(\d+)\b', r'\1/\2', quantity_string) + quantity_string = re.sub(r"\b(\d+)\s+/\s+(\d+)\b", r"\1/\2", quantity_string) if is_number(quantity_string): return fractions.Fraction(quantity_string) diff --git a/djfractions/models/fields.py b/djfractions/models/fields.py index 78e4b1a..1a82901 100644 --- a/djfractions/models/fields.py +++ b/djfractions/models/fields.py @@ -5,7 +5,6 @@ from django.core import checks from django.core.checks.messages import CheckMessage - from django.db.models import Field from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ diff --git a/docs/conf.py b/docs/conf.py index e9f99d2..9090f1f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,12 +10,13 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) cwd = os.getcwd() parent = os.path.dirname(cwd) @@ -26,27 +27,27 @@ # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] +extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'django-fractions' -copyright = '2015, Justin Michalicek' +project = "django-fractions" +copyright = "2015, Justin Michalicek" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -59,174 +60,168 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'django-fractionsdoc' +htmlhelp_basename = "django-fractionsdoc" # -- Options for LaTeX output -------------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'django-fractions.tex', 'django-fractions Documentation', - 'Justin Michalicek', 'manual'), + ("index", "django-fractions.tex", "django-fractions Documentation", "Justin Michalicek", "manual"), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'django-fractions', 'django-fractions Documentation', - ['Justin Michalicek'], 1) -] +man_pages = [("index", "django-fractions", "django-fractions Documentation", ["Justin Michalicek"], 1)] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ @@ -235,19 +230,25 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'django-fractions', 'django-fractions Documentation', - 'Justin Michalicek', 'django-fractions', 'One line description of project.', - 'Miscellaneous'), + ( + "index", + "django-fractions", + "django-fractions Documentation", + "Justin Michalicek", + "django-fractions", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False diff --git a/requirements-dev.txt b/requirements-dev.txt index 97f581c..87bbe16 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,7 @@ bumpversion -Django +django black isort djhtml pyupgrade -django-upgrade \ No newline at end of file +django-upgrade diff --git a/runtests.py b/runtests.py index e91ed0c..1812b6c 100644 --- a/runtests.py +++ b/runtests.py @@ -5,7 +5,7 @@ from django.test.utils import get_runner settings.configure( - SECRET_KEY='fakesecretkey', + SECRET_KEY="fakesecretkey", # Disable some system checks during tests for now # Django 1.11 appears to have gotten more strict about these # and now tests do not run, but since some older, supported @@ -14,7 +14,7 @@ # that the correct exceptions are raised. # fields.E130 = must define decimal_places # fields.E132 = must define max_digits - SILENCED_SYSTEM_CHECKS = ['fields.E130', 'fields.E132'], + SILENCED_SYSTEM_CHECKS=["fields.E130", "fields.E132"], DEBUG=True, USE_TZ=True, DATABASES={ @@ -31,21 +31,20 @@ ], SITE_ID=1, MIDDLEWARE_CLASSES=(), - TEMPLATES = [ - {'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [] - } + TEMPLATES=[ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": {"context_processors": []}, } ], - DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' - + DEFAULT_AUTO_FIELD="django.db.models.BigAutoField", ) try: import django + setup = django.setup except AttributeError: pass @@ -54,13 +53,14 @@ except ImportError: import traceback + traceback.print_exc() raise ImportError("To fix this error, run: pip install -r requirements-test.txt") def run_tests(*test_args): if not test_args: - test_args = ['tests'] + test_args = ["tests"] # Run tests TestRunner = get_runner(settings) @@ -68,9 +68,9 @@ def run_tests(*test_args): failures = test_runner.run_tests(test_args) - #if failures: + # if failures: sys.exit(bool(failures)) -if __name__ == '__main__': +if __name__ == "__main__": run_tests(*sys.argv[1:]) diff --git a/setup.cfg b/setup.cfg index 9f3ef42..0ae38cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [bumpversion] -current_version = 3.0.0 -commit = True -tag = True +current_version = 3.1.0 +commit = False +tag = False [bumpversion:file:djfractions/__init__.py] @@ -16,4 +16,4 @@ exclude = docs/source/conf.py, build, dist -max-line-length = 119 +max-line-length = 120 diff --git a/setup.py b/setup.py index 1a8dd60..da110ec 100755 --- a/setup.py +++ b/setup.py @@ -1,59 +1,45 @@ #!/usr/bin/env python -import os -import sys +from setuptools import setup import djfractions -try: - from setuptools import setup -except ImportError: - from distutils.core import setup - version = djfractions.__version__ -if sys.argv[-1] == 'publish': - os.system('python setup.py sdist upload') - os.system('python setup.py bdist_wheel upload') - sys.exit() - -if sys.argv[-1] == 'tag': - print("Tagging the version on github:") - os.system(f"git tag -a {version} -m 'version {version}'") - os.system("git push --tags") - sys.exit() - -readme = open('README.rst').read() -history = open('HISTORY.rst').read().replace('.. :changelog:', '') +readme = open("README.rst").read() +history = open("HISTORY.rst").read().replace(".. :changelog:", "") setup( - name='django-fractions', + name="django-fractions", version=version, description="""Fraction display and form fields for Django""", long_description=readme, - author='Justin Michalicek', - author_email='jmichalicek@gmail.com', - url='https://github.com/jmichalicek/django-fractions', - packages=['djfractions',], + author="Justin Michalicek", + author_email="jmichalicek@gmail.com", + url="https://github.com/jmichalicek/django-fractions", + packages=[ + "djfractions", + ], include_package_data=True, install_requires=[], - test_suite='runtests.run_tests', + test_suite="runtests.run_tests", license="BSD", zip_safe=False, - keywords='django-fractions', + keywords="django-fractions", classifiers=[ - 'Development Status :: 4 - Beta', - 'Framework :: Django', - 'Framework :: Django :: 3.2', - 'Framework :: Django :: 4.0', - 'Framework :: Django :: 4.1', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Natural Language :: English', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', + "Development Status :: 4 - Beta", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4.0", + "Framework :: Django :: 4.1", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Natural Language :: English", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", ], ) diff --git a/test_project/frac/app/migrations/0001_initial.py b/test_project/frac/app/migrations/0001_initial.py index d565748..515d823 100644 --- a/test_project/frac/app/migrations/0001_initial.py +++ b/test_project/frac/app/migrations/0001_initial.py @@ -1,6 +1,7 @@ # Generated by Django 2.2.16 on 2020-09-05 20:39 from django.db import migrations, models + import djfractions.models.fields diff --git a/test_project/frac/app/models.py b/test_project/frac/app/models.py index d451395..d67658d 100644 --- a/test_project/frac/app/models.py +++ b/test_project/frac/app/models.py @@ -1,4 +1,5 @@ from django.db import models + from djfractions.models import DecimalFractionField diff --git a/tests/models.py b/tests/models.py index 6bda813..8039ba9 100644 --- a/tests/models.py +++ b/tests/models.py @@ -1,4 +1,5 @@ from django.db import models + from djfractions.models import DecimalFractionField diff --git a/tests/test_djfractions.py b/tests/test_djfractions.py index 1af9d80..830bf08 100644 --- a/tests/test_djfractions.py +++ b/tests/test_djfractions.py @@ -1,11 +1,11 @@ +import fractions +from decimal import Decimal + from django.core.exceptions import ValidationError +from django.template import Context, Template from django.test import TestCase -from django.template import Template, Context - -from decimal import Decimal -import fractions -from djfractions import quantity_to_decimal, get_fraction_unicode_entity, quantity_to_fraction +from djfractions import get_fraction_unicode_entity, quantity_to_decimal, quantity_to_fraction from djfractions.forms import DecimalFractionField, FractionField @@ -15,58 +15,58 @@ class QuantityToDecimalTest(TestCase): """ def test_single_integer(self): - self.assertEqual(Decimal(1), quantity_to_decimal('1')) - self.assertEqual(Decimal(2), quantity_to_decimal('2')) - self.assertEqual(Decimal(10), quantity_to_decimal('10')) + self.assertEqual(Decimal(1), quantity_to_decimal("1")) + self.assertEqual(Decimal(2), quantity_to_decimal("2")) + self.assertEqual(Decimal(10), quantity_to_decimal("10")) def test_simple_decimal(self): - self.assertEqual(Decimal('.25'), quantity_to_decimal('.25')) - self.assertEqual(Decimal('1.25'), quantity_to_decimal('1.25')) - self.assertEqual(Decimal('.3'), quantity_to_decimal('.3')) + self.assertEqual(Decimal(".25"), quantity_to_decimal(".25")) + self.assertEqual(Decimal("1.25"), quantity_to_decimal("1.25")) + self.assertEqual(Decimal(".3"), quantity_to_decimal(".3")) def test_simple_fraction(self): - self.assertEqual(Decimal('.25'), quantity_to_decimal('1/4').quantize(Decimal('0.00'))) - self.assertEqual(Decimal('.5'), quantity_to_decimal('1/2').quantize(Decimal('0.0'))) - self.assertEqual(Decimal('.3'), quantity_to_decimal('1/3').quantize(Decimal('0.0'))) - self.assertEqual(Decimal('.67'), quantity_to_decimal('2/3').quantize(Decimal('0.00'))) + self.assertEqual(Decimal(".25"), quantity_to_decimal("1/4").quantize(Decimal("0.00"))) + self.assertEqual(Decimal(".5"), quantity_to_decimal("1/2").quantize(Decimal("0.0"))) + self.assertEqual(Decimal(".3"), quantity_to_decimal("1/3").quantize(Decimal("0.0"))) + self.assertEqual(Decimal(".67"), quantity_to_decimal("2/3").quantize(Decimal("0.00"))) def test_mixed_number(self): - self.assertEqual(Decimal('1.25'), quantity_to_decimal('1 1/4')) - self.assertEqual(Decimal('1.33'), quantity_to_decimal('1 1/3').quantize(Decimal('0.01'))) - self.assertEqual(Decimal('1.25'), quantity_to_decimal('1 and 1/4')) - self.assertEqual(Decimal('1.25'), quantity_to_decimal('1-1/4')) + self.assertEqual(Decimal("1.25"), quantity_to_decimal("1 1/4")) + self.assertEqual(Decimal("1.33"), quantity_to_decimal("1 1/3").quantize(Decimal("0.01"))) + self.assertEqual(Decimal("1.25"), quantity_to_decimal("1 and 1/4")) + self.assertEqual(Decimal("1.25"), quantity_to_decimal("1-1/4")) def test_mixed_number(self): - self.assertEqual(Decimal('-1.25'), quantity_to_decimal('-1 1/4')) - self.assertEqual(Decimal('-1.33'), quantity_to_decimal('-1 1/3').quantize(Decimal('0.01'))) - self.assertEqual(Decimal('-1.25'), quantity_to_decimal('-1 and 1/4')) - self.assertEqual(Decimal('-1.25'), quantity_to_decimal('-1-1/4')) + self.assertEqual(Decimal("-1.25"), quantity_to_decimal("-1 1/4")) + self.assertEqual(Decimal("-1.33"), quantity_to_decimal("-1 1/3").quantize(Decimal("0.01"))) + self.assertEqual(Decimal("-1.25"), quantity_to_decimal("-1 and 1/4")) + self.assertEqual(Decimal("-1.25"), quantity_to_decimal("-1-1/4")) class QuantityToFractionTest(TestCase): def test_single_integer(self): - self.assertEqual(fractions.Fraction(1, 1), quantity_to_fraction('1')) - self.assertEqual(fractions.Fraction(2, 1), quantity_to_fraction('2')) + self.assertEqual(fractions.Fraction(1, 1), quantity_to_fraction("1")) + self.assertEqual(fractions.Fraction(2, 1), quantity_to_fraction("2")) def test_simple_decimal(self): - self.assertEqual(fractions.Fraction(1, 4), quantity_to_fraction('.25')) - self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction('1.25')) + self.assertEqual(fractions.Fraction(1, 4), quantity_to_fraction(".25")) + self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction("1.25")) def test_simple_fraction(self): - self.assertEqual(fractions.Fraction(1, 4), quantity_to_fraction('1/4')) - self.assertEqual(fractions.Fraction(1, 3), quantity_to_fraction('1/3')) - self.assertEqual(fractions.Fraction(3, 2), quantity_to_fraction('3/2')) + self.assertEqual(fractions.Fraction(1, 4), quantity_to_fraction("1/4")) + self.assertEqual(fractions.Fraction(1, 3), quantity_to_fraction("1/3")) + self.assertEqual(fractions.Fraction(3, 2), quantity_to_fraction("3/2")) def test_mixed_number(self): - self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction('1 1/4')) - self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction('1 and 1/4')) - self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction('1-1/4')) + self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction("1 1/4")) + self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction("1 and 1/4")) + self.assertEqual(fractions.Fraction(5, 4), quantity_to_fraction("1-1/4")) def test_negative_numbers(self): - self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction('-1 1/4')) - self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction('-1-1/4')) - self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction('-1 - 1/4')) - self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction('-1 and 1/4')) + self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction("-1 1/4")) + self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction("-1-1/4")) + self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction("-1 - 1/4")) + self.assertEqual(fractions.Fraction(-5, 4), quantity_to_fraction("-1 and 1/4")) class DisplayFractionTagTest(TestCase): @@ -90,78 +90,78 @@ def setUp(self): ) def test_whole_number(self): - c = Context({'frac': 1}) + c = Context({"frac": 1}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '1') + self.assertEqual(rendered.strip(), "1") def test_simple_fraction(self): - c = Context({'frac': 0.5}) + c = Context({"frac": 0.5}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '12') + self.assertEqual(rendered.strip(), "12") - c = Context({'frac': Decimal('.5')}) + c = Context({"frac": Decimal(".5")}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '12') + self.assertEqual(rendered.strip(), "12") def test_complex_number(self): - c = Context({'frac': 1.5}) + c = Context({"frac": 1.5}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '1 12') + self.assertEqual(rendered.strip(), "1 12") def test_limit_denominator(self): - c = Context({'frac': 1 / 3.0, 'limit_denominator': 3, 'mixed_numbers': True, 'coerce_thirds': True}) + c = Context({"frac": 1 / 3.0, "limit_denominator": 3, "mixed_numbers": True, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '13') + self.assertEqual(rendered.strip(), "13") def test_allow_mixed_numbers_with_improper_fraction(self): - c = Context({'frac': 1.5, 'limit_denominator': None, 'mixed_numbers': True, 'coerce_thirds': True}) + c = Context({"frac": 1.5, "limit_denominator": None, "mixed_numbers": True, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '1 12') + self.assertEqual(rendered.strip(), "1 12") - c = Context({'frac': 1.5, 'limit_denominator': None, 'mixed_numbers': False, 'coerce_thirds': True}) + c = Context({"frac": 1.5, "limit_denominator": None, "mixed_numbers": False, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '32') + self.assertEqual(rendered.strip(), "32") def test_allow_mixed_numbers_with_whole_number_int(self): - c = Context({'frac': 4, 'limit_denominator': None, 'mixed_numbers': True, 'coerce_thirds': True}) + c = Context({"frac": 4, "limit_denominator": None, "mixed_numbers": True, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '4') + self.assertEqual(rendered.strip(), "4") - c = Context({'frac': 4, 'limit_denominator': None, 'mixed_numbers': False, 'coerce_thirds': True}) + c = Context({"frac": 4, "limit_denominator": None, "mixed_numbers": False, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '41') + self.assertEqual(rendered.strip(), "41") def test_allow_mixed_numbers_with_whole_number_float(self): - c = Context({'frac': 4.0, 'limit_denominator': None, 'mixed_numbers': True, 'coerce_thirds': True}) + c = Context({"frac": 4.0, "limit_denominator": None, "mixed_numbers": True, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '4') + self.assertEqual(rendered.strip(), "4") - c = Context({'frac': 4.0, 'limit_denominator': None, 'mixed_numbers': False, 'coerce_thirds': True}) + c = Context({"frac": 4.0, "limit_denominator": None, "mixed_numbers": False, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '41') + self.assertEqual(rendered.strip(), "41") def test_allow_mixed_numbers_with_whole_number_decimal(self): - c = Context({'frac': Decimal('4.0'), 'limit_denominator': None, 'mixed_numbers': True, 'coerce_thirds': True}) + c = Context({"frac": Decimal("4.0"), "limit_denominator": None, "mixed_numbers": True, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '4') + self.assertEqual(rendered.strip(), "4") - c = Context({'frac': Decimal('4.0'), 'limit_denominator': None, 'mixed_numbers': False, 'coerce_thirds': True}) + c = Context({"frac": Decimal("4.0"), "limit_denominator": None, "mixed_numbers": False, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '41') + self.assertEqual(rendered.strip(), "41") def test_zero_allow_mixed_numbers(self): - c = Context({'frac': 0}) + c = Context({"frac": 0}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '0') + self.assertEqual(rendered.strip(), "0") def test_zero_no_mixed_numbers(self): - c = Context({'frac': 0, 'limit_denominator': None, 'mixed_numbers': False, 'coerce_thirds': True}) + c = Context({"frac": 0, "limit_denominator": None, "mixed_numbers": False, "coerce_thirds": True}) rendered = self.all_params_template.render(c) - self.assertEqual(rendered.strip(), '01') + self.assertEqual(rendered.strip(), "01") class DisplayImproperFractionTagTest(TestCase): @@ -178,39 +178,39 @@ def setUp(self): ) def test_improper_fraction_float(self): - c = Context({'frac': 1.5}) + c = Context({"frac": 1.5}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '32') + self.assertEqual(rendered.strip(), "32") def test_improper_fraction_decimal(self): - c = Context({'frac': Decimal('1.5')}) + c = Context({"frac": Decimal("1.5")}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '32') + self.assertEqual(rendered.strip(), "32") def test_whole_number_integer(self): - c = Context({'frac': 4}) + c = Context({"frac": 4}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '41') + self.assertEqual(rendered.strip(), "41") def test_whole_number_float(self): - c = Context({'frac': 4.0}) + c = Context({"frac": 4.0}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '41') + self.assertEqual(rendered.strip(), "41") def test_whole_number_decimal(self): - c = Context({'frac': Decimal('4')}) + c = Context({"frac": Decimal("4")}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '41') + self.assertEqual(rendered.strip(), "41") def test_proper_fraction_float(self): - c = Context({'frac': 0.5}) + c = Context({"frac": 0.5}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '12') + self.assertEqual(rendered.strip(), "12") def test_proper_fraction_decimal(self): - c = Context({'frac': Decimal('.5')}) + c = Context({"frac": Decimal(".5")}) rendered = self.template.render(c) - self.assertEqual(rendered.strip(), '12') + self.assertEqual(rendered.strip(), "12") class DecimalFractionFieldTest(TestCase): @@ -221,18 +221,18 @@ def test_prepare_value_int(self): """ field = DecimalFractionField() result = field.prepare_value(1) - self.assertEqual('1', result) + self.assertEqual("1", result) def test_prepare_value_string(self): """ Test string fractions are returns as is """ field = DecimalFractionField() - result = field.prepare_value('1/4') - self.assertEqual('1/4', result) + result = field.prepare_value("1/4") + self.assertEqual("1/4", result) - result = field.prepare_value('1 1/4') - self.assertEqual('1 1/4', result) + result = field.prepare_value("1 1/4") + self.assertEqual("1 1/4", result) def test_prepare_value_decimal(self): """ @@ -240,8 +240,8 @@ def test_prepare_value_decimal(self): converted to a string fraction """ field = DecimalFractionField() - result = field.prepare_value(Decimal('.5')) - self.assertEqual('1/2', result) + result = field.prepare_value(Decimal(".5")) + self.assertEqual("1/2", result) def test_prepare_value_float(self): """ @@ -250,7 +250,7 @@ def test_prepare_value_float(self): """ field = DecimalFractionField() result = field.prepare_value(float(0.5)) - self.assertEqual('1/2', result) + self.assertEqual("1/2", result) def test_prepare_value_limit_denominator(self): """ @@ -259,7 +259,7 @@ def test_prepare_value_limit_denominator(self): """ field = DecimalFractionField(limit_denominator=3) result = field.prepare_value(Decimal(1 / 3.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) def test_prepare_value_coerce_thirds(self): """ @@ -268,25 +268,25 @@ def test_prepare_value_coerce_thirds(self): """ field = DecimalFractionField(coerce_thirds=True) result = field.prepare_value(Decimal(1 / 3.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) result = field.prepare_value(Decimal(1 / 3.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) result = field.prepare_value(Decimal(2 / 3.0)) - self.assertEqual('2/3', result) + self.assertEqual("2/3", result) result = field.prepare_value(Decimal(2 / 6.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) result = field.prepare_value(Decimal(4 / 6.0)) - self.assertEqual('2/3', result) + self.assertEqual("2/3", result) result = field.prepare_value(Decimal(4 / 3.0)) - self.assertEqual('1 1/3', result) + self.assertEqual("1 1/3", result) result = field.prepare_value(Decimal(5 / 3.0)) - self.assertEqual('1 2/3', result) + self.assertEqual("1 2/3", result) def test_to_python_decimal(self): """ @@ -320,43 +320,43 @@ def test_to_python_int(self): def test_to_python_int_string(self): field = DecimalFractionField() - value = '2' + value = "2" result = field.to_python(value) - self.assertEqual(Decimal('2'), result) + self.assertEqual(Decimal("2"), result) def test_to_python_float_string(self): field = DecimalFractionField() - value = '0.5' + value = "0.5" result = field.to_python(value) self.assertEqual(Decimal(value), result) def test_to_python_fraction_string(self): field = DecimalFractionField() - value = '1/2' + value = "1/2" result = field.to_python(value) - self.assertEqual(Decimal('.5'), result) + self.assertEqual(Decimal(".5"), result) def test_to_python_mixed_fraction_string(self): field = DecimalFractionField() - value = '1 1/2' + value = "1 1/2" result = field.to_python(value) - self.assertEqual(Decimal(3 / 2.0).quantize(Decimal('0.000')), result.quantize(Decimal('0.000'))) + self.assertEqual(Decimal(3 / 2.0).quantize(Decimal("0.000")), result.quantize(Decimal("0.000"))) def test_to_python_hyphenated_mixed_fraction_string(self): field = DecimalFractionField() - value = '1-1/2' + value = "1-1/2" result = field.to_python(value) - self.assertEqual(Decimal(3 / 2.0).quantize(Decimal('0.000')), result.quantize(Decimal('0.000'))) + self.assertEqual(Decimal(3 / 2.0).quantize(Decimal("0.000")), result.quantize(Decimal("0.000"))) - value = '1 - 1/2' + value = "1 - 1/2" result = field.to_python(value) - self.assertEqual(Decimal(3 / 2.0).quantize(Decimal('0.000')), result.quantize(Decimal('0.000'))) + self.assertEqual(Decimal(3 / 2.0).quantize(Decimal("0.000")), result.quantize(Decimal("0.000"))) def test_to_python_anded_mixed_fraction_string(self): field = DecimalFractionField() - value = '1 and 1/2' + value = "1 and 1/2" result = field.to_python(value) - self.assertEqual(Decimal(3 / 2.0).quantize(Decimal('0.000')), result.quantize(Decimal('0.000'))) + self.assertEqual(Decimal(3 / 2.0).quantize(Decimal("0.000")), result.quantize(Decimal("0.000"))) def test_to_python_method_validation_errors(self): """ @@ -364,13 +364,13 @@ def test_to_python_method_validation_errors(self): """ field = DecimalFractionField() with self.assertRaises(ValidationError): - field.clean('abcd') + field.clean("abcd") with self.assertRaises(ValidationError): - field.clean('1 1 1/3') + field.clean("1 1 1/3") with self.assertRaises(ValidationError): - field.clean('1 1') + field.clean("1 1") def test_decimal_places_validation_errors(self): """ @@ -382,11 +382,11 @@ def test_decimal_places_validation_errors(self): with self.assertRaises(ValidationError): # too many non-decimal digits - field.clean('10') + field.clean("10") with self.assertRaises(ValidationError): # too many decimal digits - field.clean('1/100') + field.clean("1/100") def test_validate_inf_raises_error(self): field = DecimalFractionField() @@ -400,124 +400,124 @@ def test_validate_negative_inf_raises_error(self): def test_round_decimal_value_method(self): field = DecimalFractionField(max_digits=5, decimal_places=2) - self.assertEqual(Decimal('100.01'), field.round_decimal_value(Decimal('100.011'))) - self.assertEqual(Decimal('1.01'), field.round_decimal_value(Decimal('1.011'))) - self.assertEqual(Decimal('10001'), field.round_decimal_value(Decimal('10000.6'))) + self.assertEqual(Decimal("100.01"), field.round_decimal_value(Decimal("100.011"))) + self.assertEqual(Decimal("1.01"), field.round_decimal_value(Decimal("1.011"))) + self.assertEqual(Decimal("10001"), field.round_decimal_value(Decimal("10000.6"))) class GetFractionUnicodeEntityTest(TestCase): def test_one_half(self): f = fractions.Fraction(1, 2) entity = get_fraction_unicode_entity(f) - self.assertEqual('½', entity) + self.assertEqual("½", entity) - entity = get_fraction_unicode_entity(Decimal('.5')) - self.assertEqual('½', entity) + entity = get_fraction_unicode_entity(Decimal(".5")) + self.assertEqual("½", entity) def test_one_third(self): f = fractions.Fraction(1, 3) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅓', entity) + self.assertEqual("⅓", entity) def test_two_thirds(self): f = fractions.Fraction(2, 3) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅔', entity) + self.assertEqual("⅔", entity) def test_one_fourth(self): f = fractions.Fraction(1, 4) entity = get_fraction_unicode_entity(f) - self.assertEqual('¼', entity) + self.assertEqual("¼", entity) - entity = get_fraction_unicode_entity(Decimal('.25')) - self.assertEqual('¼', entity) + entity = get_fraction_unicode_entity(Decimal(".25")) + self.assertEqual("¼", entity) def test_three_fourths(self): f = fractions.Fraction(3, 4) entity = get_fraction_unicode_entity(f) - self.assertEqual('¾', entity) + self.assertEqual("¾", entity) - entity = get_fraction_unicode_entity(Decimal('.75')) - self.assertEqual('¾', entity) + entity = get_fraction_unicode_entity(Decimal(".75")) + self.assertEqual("¾", entity) def test_one_fifth(self): f = fractions.Fraction(1, 5) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅕', entity) + self.assertEqual("⅕", entity) - entity = get_fraction_unicode_entity(Decimal('.2')) - self.assertEqual('⅕', entity) + entity = get_fraction_unicode_entity(Decimal(".2")) + self.assertEqual("⅕", entity) def test_two_fifths(self): f = fractions.Fraction(2, 5) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅖', entity) + self.assertEqual("⅖", entity) - entity = get_fraction_unicode_entity(Decimal('.4')) - self.assertEqual('⅖', entity) + entity = get_fraction_unicode_entity(Decimal(".4")) + self.assertEqual("⅖", entity) def test_three_fifths(self): f = fractions.Fraction(3, 5) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅗', entity) + self.assertEqual("⅗", entity) - entity = get_fraction_unicode_entity(Decimal('.6')) - self.assertEqual('⅗', entity) + entity = get_fraction_unicode_entity(Decimal(".6")) + self.assertEqual("⅗", entity) def test_four_fifths(self): f = fractions.Fraction(4, 5) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅘', entity) + self.assertEqual("⅘", entity) - entity = get_fraction_unicode_entity(Decimal('.8')) - self.assertEqual('⅘', entity) + entity = get_fraction_unicode_entity(Decimal(".8")) + self.assertEqual("⅘", entity) def test_one_sixth(self): f = fractions.Fraction(1, 6) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅙', entity) + self.assertEqual("⅙", entity) def test_five_sixths(self): f = fractions.Fraction(5, 6) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅚', entity) + self.assertEqual("⅚", entity) def test_one_seventh(self): f = fractions.Fraction(1, 7) entity = get_fraction_unicode_entity(f) - self.assertEqual('&frac17;', entity) + self.assertEqual("&frac17;", entity) def test_one_eighth(self): f = fractions.Fraction(1, 8) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅛', entity) + self.assertEqual("⅛", entity) - entity = get_fraction_unicode_entity(Decimal('.125')) - self.assertEqual('⅛', entity) + entity = get_fraction_unicode_entity(Decimal(".125")) + self.assertEqual("⅛", entity) def test_three_eighths(self): f = fractions.Fraction(3, 8) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅜', entity) + self.assertEqual("⅜", entity) - entity = get_fraction_unicode_entity(Decimal('.375')) - self.assertEqual('⅜', entity) + entity = get_fraction_unicode_entity(Decimal(".375")) + self.assertEqual("⅜", entity) def test_five_eighths(self): f = fractions.Fraction(5, 8) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅝', entity) + self.assertEqual("⅝", entity) - entity = get_fraction_unicode_entity(Decimal('.625')) - self.assertEqual('⅝', entity) + entity = get_fraction_unicode_entity(Decimal(".625")) + self.assertEqual("⅝", entity) def test_seven_eighths(self): f = fractions.Fraction(7, 8) entity = get_fraction_unicode_entity(f) - self.assertEqual('⅞', entity) + self.assertEqual("⅞", entity) - entity = get_fraction_unicode_entity(Decimal('.875')) - self.assertEqual('⅞', entity) + entity = get_fraction_unicode_entity(Decimal(".875")) + self.assertEqual("⅞", entity) class FractionFieldTest(TestCase): @@ -528,18 +528,18 @@ def test_prepare_value_int(self): """ field = FractionField() result = field.prepare_value(1) - self.assertEqual('1', result) + self.assertEqual("1", result) def test_prepare_value_string(self): """ Test string fractions are returns as is """ field = FractionField() - result = field.prepare_value('1/4') - self.assertEqual('1/4', result) + result = field.prepare_value("1/4") + self.assertEqual("1/4", result) - result = field.prepare_value('1 1/4') - self.assertEqual('1 1/4', result) + result = field.prepare_value("1 1/4") + self.assertEqual("1 1/4", result) def test_prepare_value_decimal(self): """ @@ -547,8 +547,8 @@ def test_prepare_value_decimal(self): converted to a string fraction """ field = FractionField() - result = field.prepare_value(Decimal('.5')) - self.assertEqual('1/2', result) + result = field.prepare_value(Decimal(".5")) + self.assertEqual("1/2", result) def test_prepare_value_float(self): """ @@ -557,15 +557,15 @@ def test_prepare_value_float(self): """ field = FractionField() result = field.prepare_value(float(0.5)) - self.assertEqual('1/2', result) + self.assertEqual("1/2", result) def test_prepare_value_fraction(self): """ Test that a :class:`fractions.Fraction` is properly converted to a string fraction """ field = FractionField() - result = field.prepare_value(fractions.Fraction('1/2')) - self.assertEqual('1/2', result) + result = field.prepare_value(fractions.Fraction("1/2")) + self.assertEqual("1/2", result) def test_prepare_value_limit_denominator(self): """ @@ -574,7 +574,7 @@ def test_prepare_value_limit_denominator(self): """ field = FractionField(limit_denominator=3) result = field.prepare_value(Decimal(1 / 3.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) def test_prepare_value_coerce_thirds(self): """ @@ -583,25 +583,25 @@ def test_prepare_value_coerce_thirds(self): """ field = FractionField(coerce_thirds=True) result = field.prepare_value(Decimal(1 / 3.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) result = field.prepare_value(Decimal(1 / 3.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) result = field.prepare_value(Decimal(2 / 3.0)) - self.assertEqual('2/3', result) + self.assertEqual("2/3", result) result = field.prepare_value(Decimal(2 / 6.0)) - self.assertEqual('1/3', result) + self.assertEqual("1/3", result) result = field.prepare_value(Decimal(4 / 6.0)) - self.assertEqual('2/3', result) + self.assertEqual("2/3", result) result = field.prepare_value(Decimal(4 / 3.0)) - self.assertEqual('1 1/3', result) + self.assertEqual("1 1/3", result) result = field.prepare_value(Decimal(5 / 3.0)) - self.assertEqual('1 2/3', result) + self.assertEqual("1 2/3", result) def test_to_python_decimal(self): """ @@ -635,57 +635,57 @@ def test_to_python_int(self): def test_to_python_int_string(self): field = FractionField() - value = '2' + value = "2" result = field.to_python(value) - self.assertEqual(fractions.Fraction('2'), result) + self.assertEqual(fractions.Fraction("2"), result) def test_to_python_float_string(self): field = FractionField() - value = '0.5' + value = "0.5" result = field.to_python(value) self.assertEqual(fractions.Fraction(value), result) def test_to_python_fraction_string(self): field = FractionField() - value = '1/2' + value = "1/2" result = field.to_python(value) - self.assertEqual(fractions.Fraction('.5'), result) + self.assertEqual(fractions.Fraction(".5"), result) def test_to_python_mixed_fraction_string(self): field = FractionField() - value = '1 1/2' + value = "1 1/2" result = field.to_python(value) - self.assertEqual(fractions.Fraction('3/2'), result) + self.assertEqual(fractions.Fraction("3/2"), result) def test_to_python_hyphenated_mixed_fraction_string(self): field = FractionField() - value = '1-1/2' + value = "1-1/2" result = field.to_python(value) - self.assertEqual(fractions.Fraction('3/2'), result) + self.assertEqual(fractions.Fraction("3/2"), result) - value = '1 - 1/2' + value = "1 - 1/2" result = field.to_python(value) - self.assertEqual(fractions.Fraction('3/2'), result) + self.assertEqual(fractions.Fraction("3/2"), result) def test_to_python_anded_mixed_fraction_string(self): field = FractionField() - value = '1 and 1/2' + value = "1 and 1/2" result = field.to_python(value) - self.assertEqual(fractions.Fraction('3/2'), result) + self.assertEqual(fractions.Fraction("3/2"), result) def test_to_python_validation_errors(self): field = FractionField() with self.assertRaises(ValidationError): - field.to_python('abcd') + field.to_python("abcd") with self.assertRaises(ValidationError): - field.to_python('1 1 1/3') + field.to_python("1 1 1/3") with self.assertRaises(ValidationError): - field.to_python('1 1') + field.to_python("1 1") def test_max_value_set(self): - field = FractionField(max_value=fractions.Fraction('999/1000')) + field = FractionField(max_value=fractions.Fraction("999/1000")) with self.assertRaises(ValidationError): field.run_validators(fractions.Fraction(1, 1)) diff --git a/tests/test_models.py b/tests/test_models.py index 11d7c9c..147570d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,14 +1,14 @@ +import decimal +import fractions + from django.core import checks from django.db import models from django.test import TestCase -import decimal -import fractions - -from djfractions.models import DecimalFractionField import djfractions.forms +from djfractions.models import DecimalFractionField -from .models import TestModel, BadTestModel +from .models import BadTestModel, TestModel class DecimalFractionFieldTest(TestCase): @@ -46,7 +46,7 @@ def test_formfield_method_returns_correct_type(self): """ Test that FractionDecimalField returns a forms.FractionField """ - dff = DecimalFractionField(name='frac', max_digits=10, decimal_places=5) + dff = DecimalFractionField(name="frac", max_digits=10, decimal_places=5) self.assertIsInstance(dff.formfield(), djfractions.forms.FractionField) def test_max_digits_arg_is_required(self): @@ -54,10 +54,10 @@ def test_max_digits_arg_is_required(self): Test that the max_digits arg is required and raises and exception if not there """ - dff = BadTestModel._meta.get_field('missing_max_digits') + dff = BadTestModel._meta.get_field("missing_max_digits") errors = dff.check() self.assertEqual( - [checks.Error("DecimalFractionFields must define a 'max_digits' attribute.", obj=dff, id='fields.E132')], + [checks.Error("DecimalFractionFields must define a 'max_digits' attribute.", obj=dff, id="fields.E132")], errors, ) @@ -65,12 +65,12 @@ def test_decimal_places_arg_is_required(self): """ Test that the decimal_places arg is required and raises an exception if not there """ - dff = BadTestModel._meta.get_field('missing_decimal_places') + dff = BadTestModel._meta.get_field("missing_decimal_places") errors = dff.check() self.assertEqual( [ checks.Error( - "DecimalFractionFields must define a 'decimal_places' attribute.", obj=dff, id='fields.E130' + "DecimalFractionFields must define a 'decimal_places' attribute.", obj=dff, id="fields.E130" ) ], errors,