Skip to content

Commit

Permalink
Fixed E128 flake8 warnings in tests/.
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Apr 8, 2016
1 parent df8d8d4 commit 92053ac
Show file tree
Hide file tree
Showing 148 changed files with 2,077 additions and 2,252 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh

[flake8]
exclude = build,.git,./django/utils/lru_cache.py,./django/utils/six.py,./django/conf/app_template/*,./django/dispatch/weakref_backports.py,./tests/.env,./xmlrunner,tests/view_tests/tests/py3_test_debug.py,tests/template_tests/annotated_tag_function.py
ignore = E128,W601
ignore = W601
max-line-length = 119

[isort]
Expand Down
3 changes: 1 addition & 2 deletions tests/admin_changelist/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

class CustomPaginator(Paginator):
def __init__(self, queryset, page_size, orphans=0, allow_empty_first_page=True):
super(CustomPaginator, self).__init__(queryset, 5, orphans=2,
allow_empty_first_page=allow_empty_first_page)
super(CustomPaginator, self).__init__(queryset, 5, orphans=2, allow_empty_first_page=allow_empty_first_page)


class EventAdmin(admin.ModelAdmin):
Expand Down
15 changes: 5 additions & 10 deletions tests/admin_changelist/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def test_result_list_empty_changelist_value(self):
'<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
'<td class="field-parent nowrap">-</td></tr></tbody>' % link
)
self.assertNotEqual(table_output.find(row_html), -1,
'Failed to find expected row element: %s' % table_output)
self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

def test_result_list_set_empty_value_display_on_admin_site(self):
"""
Expand All @@ -152,8 +151,7 @@ def test_result_list_set_empty_value_display_on_admin_site(self):
'<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
'<td class="field-parent nowrap">???</td></tr></tbody>' % link
)
self.assertNotEqual(table_output.find(row_html), -1,
'Failed to find expected row element: %s' % table_output)
self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

def test_result_list_set_empty_value_display_in_model_admin(self):
"""
Expand All @@ -172,8 +170,7 @@ def test_result_list_set_empty_value_display_in_model_admin(self):
'<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
'<td class="field-age_display">&amp;dagger;</td><td class="field-age">-empty-</td></tr></tbody>' % link
)
self.assertNotEqual(table_output.find(row_html), -1,
'Failed to find expected row element: %s' % table_output)
self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

def test_result_list_html(self):
"""
Expand All @@ -194,8 +191,7 @@ def test_result_list_html(self):
'<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
'<td class="field-parent nowrap">Parent object</td></tr></tbody>' % link
)
self.assertNotEqual(table_output.find(row_html), -1,
'Failed to find expected row element: %s' % table_output)
self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

def test_result_list_editable_html(self):
"""
Expand Down Expand Up @@ -894,8 +890,7 @@ def test_add_row_selection(self):
Ensure that the status line for selected rows gets updated correctly (#22038)
"""
self.admin_login(username='super', password='secret')
self.selenium.get('%s%s' % (self.live_server_url,
reverse('admin:auth_user_changelist')))
self.selenium.get(self.live_server_url + reverse('admin:auth_user_changelist'))

form_id = '#changelist-form'

Expand Down
30 changes: 13 additions & 17 deletions tests/admin_custom_urls/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ def test_admin_URLs_no_clash(self):
"""
# Should get the change_view for model instance with PK 'add', not show
# the add_view
url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label,
args=(quote('add'),))
url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label, args=(quote('add'),))
response = self.client.get(url)
self.assertContains(response, 'Change action')

# Should correctly get the change_view for the model instance with the
# funny-looking PK (the one with a 'path/to/html/document.html' value)
url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label,
args=(quote("path/to/html/document.html"),))
url = reverse(
'admin_custom_urls:%s_action_change' % Action._meta.app_label,
args=(quote("path/to/html/document.html"),)
)
response = self.client.get(url)
self.assertContains(response, 'Change action')
self.assertContains(response, 'value="path/to/html/document.html"')
Expand All @@ -95,12 +96,11 @@ def test_post_save_add_redirect(self):
"""
post_data = {'name': 'John Doe'}
self.assertEqual(Person.objects.count(), 0)
response = self.client.post(
reverse('admin_custom_urls:admin_custom_urls_person_add'), post_data)
response = self.client.post(reverse('admin_custom_urls:admin_custom_urls_person_add'), post_data)
persons = Person.objects.all()
self.assertEqual(len(persons), 1)
self.assertRedirects(
response, reverse('admin_custom_urls:admin_custom_urls_person_history', args=[persons[0].pk]))
redirect_url = reverse('admin_custom_urls:admin_custom_urls_person_history', args=[persons[0].pk])
self.assertRedirects(response, redirect_url)

def test_post_save_change_redirect(self):
"""
Expand All @@ -112,11 +112,9 @@ def test_post_save_change_redirect(self):
Person.objects.create(name='John Doe')
self.assertEqual(Person.objects.count(), 1)
person = Person.objects.all()[0]
post_data = {'name': 'Jack Doe'}
response = self.client.post(
reverse('admin_custom_urls:admin_custom_urls_person_change', args=[person.pk]), post_data)
self.assertRedirects(
response, reverse('admin_custom_urls:admin_custom_urls_person_delete', args=[person.pk]))
post_url = reverse('admin_custom_urls:admin_custom_urls_person_change', args=[person.pk])
response = self.client.post(post_url, {'name': 'Jack Doe'})
self.assertRedirects(response, reverse('admin_custom_urls:admin_custom_urls_person_delete', args=[person.pk]))

def test_post_url_continue(self):
"""
Expand All @@ -125,9 +123,7 @@ def test_post_url_continue(self):
"""
post_data = {'name': 'SuperFast', '_continue': '1'}
self.assertEqual(Car.objects.count(), 0)
response = self.client.post(
reverse('admin_custom_urls:admin_custom_urls_car_add'), post_data)
response = self.client.post(reverse('admin_custom_urls:admin_custom_urls_car_add'), post_data)
cars = Car.objects.all()
self.assertEqual(len(cars), 1)
self.assertRedirects(
response, reverse('admin_custom_urls:admin_custom_urls_car_history', args=[cars[0].pk]))
self.assertRedirects(response, reverse('admin_custom_urls:admin_custom_urls_car_history', args=[cars[0].pk]))
83 changes: 28 additions & 55 deletions tests/admin_docs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ def test_index(self):
self.client.logout()
response = self.client.get(reverse('django-admindocs-docroot'), follow=True)
# Should display the login screen
self.assertContains(response,
'<input type="hidden" name="next" value="/admindocs/" />', html=True)
self.assertContains(response, '<input type="hidden" name="next" value="/admindocs/" />', html=True)
self.client.force_login(self.superuser)
response = self.client.get(reverse('django-admindocs-docroot'))
self.assertContains(response, '<h1>Documentation</h1>', html=True)
self.assertContains(response,
'<h1 id="site-name"><a href="/admin/">Django '
'administration</a></h1>')
self.assertContains(response, '<h1 id="site-name"><a href="/admin/">Django administration</a></h1>')

def test_bookmarklets(self):
response = self.client.get(reverse('django-admindocs-bookmarklets'))
Expand All @@ -77,26 +74,26 @@ def test_templatefilter_index(self):

def test_view_index(self):
response = self.client.get(reverse('django-admindocs-views-index'))
self.assertContains(response,
self.assertContains(
response,
'<h3><a href="/admindocs/views/django.contrib.admindocs.views.BaseAdminDocsView/">/admindocs/</a></h3>',
html=True)
html=True
)
self.assertContains(response, 'Views by namespace test')
self.assertContains(response, 'Name: <code>test:func</code>.')

def test_view_detail(self):
response = self.client.get(
reverse('django-admindocs-views-detail',
args=['django.contrib.admindocs.views.BaseAdminDocsView']))
url = reverse('django-admindocs-views-detail', args=['django.contrib.admindocs.views.BaseAdminDocsView'])
response = self.client.get(url)
# View docstring
self.assertContains(response, 'Base view for admindocs views.')

def test_view_detail_illegal_import(self):
"""
#23601 - Ensure the view exists in the URLconf.
"""
response = self.client.get(
reverse('django-admindocs-views-detail',
args=['urlpatterns_reverse.nonimported_module.view']))
url = reverse('django-admindocs-views-detail', args=['urlpatterns_reverse.nonimported_module.view'])
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertNotIn("urlpatterns_reverse.nonimported_module", sys.modules)

Expand All @@ -109,22 +106,20 @@ def test_model_index(self):
)

def test_template_detail(self):
response = self.client.get(reverse('django-admindocs-templates',
args=['admin_doc/template_detail.html']))
self.assertContains(response,
'<h1>Template: "admin_doc/template_detail.html"</h1>', html=True)
response = self.client.get(reverse('django-admindocs-templates', args=['admin_doc/template_detail.html']))
self.assertContains(response, '<h1>Template: "admin_doc/template_detail.html"</h1>', html=True)

def test_missing_docutils(self):
utils.docutils_is_available = False
try:
response = self.client.get(reverse('django-admindocs-docroot'))
self.assertContains(response,
self.assertContains(
response,
'<h3>The admin documentation system requires Python\'s '
'<a href="http://docutils.sf.net/">docutils</a> library.</h3>',
html=True)
self.assertContains(response,
'<h1 id="site-name"><a href="/admin/">Django '
'administration</a></h1>')
html=True
)
self.assertContains(response, '<h1 id="site-name"><a href="/admin/">Django administration</a></h1>')
finally:
utils.docutils_is_available = True

Expand Down Expand Up @@ -200,18 +195,12 @@ def test_parse_rst(self):
``django.contrib.admindocs.utils.parse_rst`` should use
``cmsreference`` as the default role.
"""
markup = ('<p><a class="reference external" href="/admindocs/%s">'
'title</a></p>\n')
self.assertEqual(utils.parse_rst('`title`', 'model'),
markup % 'models/title/')
self.assertEqual(utils.parse_rst('`title`', 'view'),
markup % 'views/title/')
self.assertEqual(utils.parse_rst('`title`', 'template'),
markup % 'templates/title/')
self.assertEqual(utils.parse_rst('`title`', 'filter'),
markup % 'filters/#title')
self.assertEqual(utils.parse_rst('`title`', 'tag'),
markup % 'tags/#title')
markup = '<p><a class="reference external" href="/admindocs/%s">title</a></p>\n'
self.assertEqual(utils.parse_rst('`title`', 'model'), markup % 'models/title/')
self.assertEqual(utils.parse_rst('`title`', 'view'), markup % 'views/title/')
self.assertEqual(utils.parse_rst('`title`', 'template'), markup % 'templates/title/')
self.assertEqual(utils.parse_rst('`title`', 'filter'), markup % 'filters/#title')
self.assertEqual(utils.parse_rst('`title`', 'tag'), markup % 'tags/#title')

def test_publish_parts(self):
"""
Expand All @@ -220,8 +209,7 @@ def test_publish_parts(self):
``cmsreference``. See #6681.
"""
import docutils
self.assertNotEqual(docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE,
'cmsreference')
self.assertNotEqual(docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE, 'cmsreference')
source = 'reST, `interpreted text`, default role.'
markup = '<p>reST, <cite>interpreted text</cite>, default role.</p>\n'
parts = docutils.core.publish_parts(source=source, writer_name="html4css1")
Expand Down Expand Up @@ -286,21 +274,9 @@ def test_method_data_types(self):
by a method
"""
company = Company.objects.create(name="Django")
person = Person.objects.create(
first_name="Human",
last_name="User",
company=company
)

self.assertEqual(
get_return_data_type(person.get_status_count.__name__),
'Integer'
)

self.assertEqual(
get_return_data_type(person.get_groups_list.__name__),
'List'
)
person = Person.objects.create(first_name="Human", last_name="User", company=company)
self.assertEqual(get_return_data_type(person.get_status_count.__name__), 'Integer')
self.assertEqual(get_return_data_type(person.get_groups_list.__name__), 'List')

def test_descriptions_render_correctly(self):
"""
Expand Down Expand Up @@ -361,10 +337,7 @@ def test_model_with_no_backward_relations_render_only_relevant_fields(self):
A model with ``related_name`` of `+` should not show backward relationship
links in admin docs
"""
response = self.client.get(
reverse('django-admindocs-models-detail',
args=['admin_docs', 'family']))

response = self.client.get(reverse('django-admindocs-models-detail', args=['admin_docs', 'family']))
fields = response.context_data.get('fields')
self.assertEqual(len(fields), 2)

Expand Down
7 changes: 4 additions & 3 deletions tests/admin_inlines/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class EditablePKBookStackedInline(admin.StackedInline):


class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline,
NonAutoPKBookTabularInline, NonAutoPKBookStackedInline,
EditablePKBookTabularInline, EditablePKBookStackedInline]
inlines = [
BookInline, NonAutoPKBookTabularInline, NonAutoPKBookStackedInline,
EditablePKBookTabularInline, EditablePKBookStackedInline,
]


class InnerInline(admin.StackedInline):
Expand Down
Loading

0 comments on commit 92053ac

Please sign in to comment.