diff --git a/runtests.py b/runtests.py index 5e8460c85..b24a2635d 100755 --- a/runtests.py +++ b/runtests.py @@ -1,37 +1,37 @@ #! /usr/bin/env python -from __future__ import print_function +from __future__ import print_function # pragma nocover -import os -import subprocess -import sys +import os # pragma nocover +import subprocess # pragma nocover +import sys # pragma nocover -import pytest +import pytest # pragma nocover -PYTEST_ARGS = { +PYTEST_ARGS = { # pragma nocover 'default': ['tests', '--tb=short', '-s', '-rw'], 'fast': ['tests', '--tb=short', '-q', '-s', '-rw'], } -FLAKE8_ARGS = ['rest_framework', 'tests'] +FLAKE8_ARGS = ['rest_framework', 'tests'] # pragma nocover -ISORT_ARGS = ['--recursive', '--check-only', '-o' 'uritemplate', '-p', 'tests', 'rest_framework', 'tests'] +ISORT_ARGS = ['--recursive', '--check-only', '-o' 'uritemplate', '-p', 'tests', 'rest_framework', 'tests'] # pragma nocover -sys.path.append(os.path.dirname(__file__)) +sys.path.append(os.path.dirname(__file__)) # pragma nocover -def exit_on_failure(ret, message=None): +def exit_on_failure(ret, message=None): # pragma nocover if ret: sys.exit(ret) -def flake8_main(args): +def flake8_main(args): # pragma nocover print('Running flake8 code linting') ret = subprocess.call(['flake8'] + args) print('flake8 failed' if ret else 'flake8 passed') return ret -def isort_main(args): +def isort_main(args): # pragma nocover print('Running isort code checking') ret = subprocess.call(['isort'] + args) @@ -43,22 +43,22 @@ def isort_main(args): return ret -def split_class_and_function(string): +def split_class_and_function(string): # pragma nocover class_string, function_string = string.split('.', 1) return "%s and %s" % (class_string, function_string) -def is_function(string): +def is_function(string): # pragma nocover # `True` if it looks like a test function is included in the string. return string.startswith('test_') or '.test_' in string -def is_class(string): +def is_class(string): # pragma nocover # `True` if first character is uppercase - assume it's a class name. return string[0] == string[0].upper() -if __name__ == "__main__": +if __name__ == "__main__": # pragma nocover try: sys.argv.remove('--nolint') except ValueError: diff --git a/setup.py b/setup.py index 54acad01b..0f0ef8497 100755 --- a/setup.py +++ b/setup.py @@ -1,26 +1,26 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import os -import re -import shutil -import sys -from io import open +import os # pragma nocover +import re # pragma nocover +import shutil # pragma nocover +import sys # pragma nocover +from io import open # pragma nocover -from setuptools import setup, find_packages +from setuptools import setup, find_packages # pragma nocover -try: +try: # pragma nocover from pypandoc import convert_file def read_md(f): return convert_file(f, 'rst') -except ImportError: +except ImportError: # pragma nocover print("warning: pypandoc module not found, could not convert Markdown to RST") - def read_md(f): + def read_md(f): # pragma nocover return open(f, 'r', encoding='utf-8').read() -def get_version(package): +def get_version(package): # pragma nocover """ Return package version as listed in `__version__` in `init.py`. """ @@ -28,10 +28,10 @@ def get_version(package): return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1) -version = get_version('rest_framework') +version = get_version('rest_framework') # pragma nocover -if sys.argv[-1] == 'publish': +if sys.argv[-1] == 'publish': # pragma nocover try: import pypandoc except ImportError: @@ -50,7 +50,7 @@ if sys.argv[-1] == 'publish': sys.exit() -setup( +setup( # pragma nocover name='djangorestframework', version=version, url='http://www.django-rest-framework.org', diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 8b5628ef2..c4e536eda 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -5,7 +5,7 @@ from django.utils import six from django.utils.translation import ugettext_lazy as _ from rest_framework.exceptions import ( - ErrorDetail, Throttled, _get_error_details + ErrorDetail, Throttled, _get_error_details, ValidationError ) @@ -37,6 +37,11 @@ class ExceptionTestCase(TestCase): ErrorDetail ) + def test_validation_error_no_detail(self): + exception = ValidationError(detail=None) + assert exception.get_full_details() == [{ + 'message': 'Invalid input.', 'code': 'invalid'}] + def test_get_full_details_with_throttling(self): exception = Throttled() assert exception.get_full_details() == {