mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 00:19:53 +03:00
Wrote the runautopep8.py script in order to ease running of autopep8. Fixed typo in development.txt
This commit is contained in:
parent
f5b5e318a6
commit
09caf49f6f
|
@ -82,7 +82,7 @@ To start hacking type.
|
|||
|
||||
Before pushing run.
|
||||
|
||||
autopep8 -r --in-place ./rest_framework/
|
||||
./rest_framework/runtests/runautopep8.py
|
||||
|
||||
To run the tests.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
autopep>=0.8.5
|
||||
autopep8>=0.8.5
|
||||
pep>=1.4.1
|
||||
coverage>=3.6
|
||||
django-discover-runner>=0.2.2
|
||||
|
|
49
rest_framework/runtests/runautopep8.py
Normal file
49
rest_framework/runtests/runautopep8.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import codecs
|
||||
import os
|
||||
import sys
|
||||
from autopep8 import fix_file, LineEndingWrapper
|
||||
|
||||
|
||||
class Options(object):
|
||||
in_place = True
|
||||
ignore = []
|
||||
select = []
|
||||
max_line_length = 97
|
||||
verbose = True
|
||||
aggressive = False
|
||||
pep8_passes = 100
|
||||
diff = False
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
|
||||
|
||||
|
||||
def main(filenames):
|
||||
output = codecs.getwriter('utf-8')(sys.stdout.buffer
|
||||
if sys.version_info[0] >= 3
|
||||
else sys.stdout)
|
||||
|
||||
output = LineEndingWrapper(output)
|
||||
|
||||
while filenames:
|
||||
name = filenames.pop(0)
|
||||
if os.path.isdir(name):
|
||||
for root, directories, children in os.walk(name):
|
||||
filenames += [os.path.join(root, f) for f in children
|
||||
if f.endswith('.py') and
|
||||
not f.startswith('.')]
|
||||
for d in directories:
|
||||
if d.startswith('.'):
|
||||
directories.remove(d)
|
||||
else:
|
||||
print('[file:%s]' % name)
|
||||
try:
|
||||
fix_file(name, Options(), output)
|
||||
except IOError as error:
|
||||
print(str(error))
|
||||
|
||||
if __name__ == '__main__':
|
||||
filenames = [os.path.join(
|
||||
os.path.join(os.path.dirname(__file__), "../.."), './rest_framework/'),
|
||||
os.path.join(os.path.join(os.path.dirname(__file__), "../.."), './setup.py')]
|
||||
|
||||
main(filenames)
|
|
@ -124,7 +124,8 @@ punctuation_re = re.compile('^(?P<lead>(?:%s)*)(?P<middle>.*?)(?P<trail>(?:%s)*)
|
|||
simple_email_re = re.compile(r'^\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+$')
|
||||
link_target_attribute_re = re.compile(r'(<a [^>]*?)target=[^\s>]+')
|
||||
html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
|
||||
hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL)
|
||||
hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([
|
||||
re.escape(x) for x in DOTS]), re.DOTALL)
|
||||
trailing_empty_content_re = re.compile(
|
||||
r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z')
|
||||
|
||||
|
|
|
@ -266,7 +266,8 @@ class HyperlinkedForeignKeyTests(TestCase):
|
|||
instance = ForeignKeySource.objects.get(pk=1)
|
||||
serializer = ForeignKeySourceSerializer(instance, data=data)
|
||||
self.assertFalse(serializer.is_valid())
|
||||
self.assertEquals(serializer.errors, {'target': [u'Incorrect type. Expected url string, received int.']})
|
||||
self.assertEquals(serializer.errors, {'target': [
|
||||
u'Incorrect type. Expected url string, received int.']})
|
||||
|
||||
def test_reverse_foreign_key_update(self):
|
||||
data = {'url': '/foreignkeytarget/2/', 'name': u'target-2',
|
||||
|
|
|
@ -199,7 +199,8 @@ class PKForeignKeyTests(TestCase):
|
|||
instance = ForeignKeySource.objects.get(pk=1)
|
||||
serializer = ForeignKeySourceSerializer(instance, data=data)
|
||||
self.assertFalse(serializer.is_valid())
|
||||
self.assertEquals(serializer.errors, {'target': [u'Incorrect type. Expected pk value, received str.']})
|
||||
self.assertEquals(serializer.errors, {'target': [
|
||||
u'Incorrect type. Expected pk value, received str.']})
|
||||
|
||||
def test_reverse_foreign_key_update(self):
|
||||
data = {'id': 2, 'name': u'target-2', 'sources': [1, 3]}
|
||||
|
|
|
@ -43,7 +43,8 @@ class CommentSerializer(serializers.Serializer):
|
|||
|
||||
|
||||
class BookSerializer(serializers.ModelSerializer):
|
||||
isbn = serializers.RegexField(regex=r'^[0-9]{13}$', error_messages={'invalid': 'isbn has to be exact 13 numbers'})
|
||||
isbn = serializers.RegexField(
|
||||
regex=r'^[0-9]{13}$', error_messages={'invalid': 'isbn has to be exact 13 numbers'})
|
||||
|
||||
class Meta:
|
||||
model = Book
|
||||
|
@ -280,7 +281,8 @@ class ValidationTests(TestCase):
|
|||
}
|
||||
serializer = ActionItemSerializer(data=data)
|
||||
self.assertEquals(serializer.is_valid(), False)
|
||||
self.assertEquals(serializer.errors, {'title': [u'Ensure this value has at most 200 characters (it has 201).']})
|
||||
self.assertEquals(serializer.errors, {'title': [
|
||||
u'Ensure this value has at most 200 characters (it has 201).']})
|
||||
|
||||
def test_default_modelfield_max_length_exceeded(self):
|
||||
data = {
|
||||
|
@ -289,7 +291,8 @@ class ValidationTests(TestCase):
|
|||
}
|
||||
serializer = ActionItemSerializer(data=data)
|
||||
self.assertEquals(serializer.is_valid(), False)
|
||||
self.assertEquals(serializer.errors, {'info': [u'Ensure this value has at most 12 characters (it has 13).']})
|
||||
self.assertEquals(serializer.errors, {'info': [
|
||||
u'Ensure this value has at most 12 characters (it has 13).']})
|
||||
|
||||
|
||||
class CustomValidationTests(TestCase):
|
||||
|
@ -919,7 +922,8 @@ class NestedSerializerContextTests(TestCase):
|
|||
|
||||
def _callable(self, instance):
|
||||
if not 'context_item' in self.context:
|
||||
raise RuntimeError("context isn't getting passed into 2nd level nested serializer")
|
||||
raise RuntimeError(
|
||||
"context isn't getting passed into 2nd level nested serializer")
|
||||
return "success"
|
||||
|
||||
class AlbumSerializer(serializers.ModelSerializer):
|
||||
|
@ -932,7 +936,8 @@ class NestedSerializerContextTests(TestCase):
|
|||
|
||||
def _callable(self, instance):
|
||||
if not 'context_item' in self.context:
|
||||
raise RuntimeError("context isn't getting passed into 1st level nested serializer")
|
||||
raise RuntimeError(
|
||||
"context isn't getting passed into 1st level nested serializer")
|
||||
return "success"
|
||||
|
||||
class AlbumCollection(object):
|
||||
|
|
|
@ -10,7 +10,8 @@ class TestSettings(TestCase):
|
|||
def test_non_import_errors(self):
|
||||
"""Make sure other errors aren't suppressed."""
|
||||
settings = APISettings(
|
||||
{'DEFAULT_MODEL_SERIALIZER_CLASS': 'rest_framework.tests.extras.bad_import.ModelSerializer'}, DEFAULTS,
|
||||
{'DEFAULT_MODEL_SERIALIZER_CLASS':
|
||||
'rest_framework.tests.extras.bad_import.ModelSerializer'}, DEFAULTS,
|
||||
IMPORT_STRINGS)
|
||||
with self.assertRaises(ValueError):
|
||||
settings.DEFAULT_MODEL_SERIALIZER_CLASS
|
||||
|
@ -18,7 +19,8 @@ class TestSettings(TestCase):
|
|||
def test_import_error_message_maintained(self):
|
||||
"""Make sure real import errors are captured and raised sensibly."""
|
||||
settings = APISettings(
|
||||
{'DEFAULT_MODEL_SERIALIZER_CLASS': 'rest_framework.tests.extras.not_here.ModelSerializer'}, DEFAULTS,
|
||||
{'DEFAULT_MODEL_SERIALIZER_CLASS':
|
||||
'rest_framework.tests.extras.not_here.ModelSerializer'}, DEFAULTS,
|
||||
IMPORT_STRINGS)
|
||||
with self.assertRaises(ImportError) as cm:
|
||||
settings.DEFAULT_MODEL_SERIALIZER_CLASS
|
||||
|
|
Loading…
Reference in New Issue
Block a user