Skip to content

Commit 70bf8cf

Browse files
committed
Add flake8 test, fix coverage in tox
1 parent 3c5a675 commit 70bf8cf

File tree

9 files changed

+118
-95
lines changed

9 files changed

+118
-95
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ pip-log.txt
2323
*.log
2424

2525
# Unit test / coverage reports
26+
htmlcov/
27+
.tox/
2628
.coverage
27-
.tox
29+
.coverage.*
30+
.cache
2831
nosetests.xml
32+
coverage.xml
33+
*,cover
2934

3035
# Translations
3136
*.mo

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2017, Dylan Verheul
3+
Copyright (c) 2017, Dylan Verheul and individual contributors
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

bootstrap3/forms.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020

2121
FORM_GROUP_CLASS = 'form-group'
2222

23+
WIDGETS_NO_REQUIRED = (
24+
AdminFileWidget,
25+
HiddenInput,
26+
FileInput,
27+
CheckboxInput,
28+
CheckboxSelectMultiple
29+
)
30+
2331

2432
def render_formset(formset, **kwargs):
2533
"""
@@ -167,10 +175,7 @@ def is_widget_required_attribute(widget):
167175
return False
168176
if not widget.is_required:
169177
return False
170-
if isinstance(
171-
widget, (
172-
AdminFileWidget, HiddenInput, FileInput,
173-
CheckboxInput, CheckboxSelectMultiple)):
178+
if isinstance(widget, WIDGETS_NO_REQUIRED):
174179
return False
175180
return True
176181

bootstrap3/templatetags/bootstrap3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,20 +451,20 @@ def bootstrap_field(*args, **kwargs):
451451
addon_before
452452
Text that should be prepended to the form field. Can also be an icon, e.g.
453453
``'<span class="glyphicon glyphicon-calendar"></span>'``
454-
454+
455455
See the `Bootstrap docs <http://getbootstrap.com/components/#input-groups-basic>` for more examples.
456456
457457
addon_after
458458
Text that should be appended to the form field. Can also be an icon, e.g.
459459
``'<span class="glyphicon glyphicon-calendar"></span>'``
460-
460+
461461
See the `Bootstrap docs <http://getbootstrap.com/components/#input-groups-basic>` for more examples.
462462
463463
addon_before_class
464464
Class used on the span when ``addon_before`` is used.
465465
466466
One of the following values:
467-
467+
468468
* ``'input-group-addon'``
469469
* ``'input-group-btn'``
470470
@@ -474,7 +474,7 @@ def bootstrap_field(*args, **kwargs):
474474
Class used on the span when ``addon_after`` is used.
475475
476476
One of the following values:
477-
477+
478478
* ``'input-group-addon'``
479479
* ``'input-group-btn'``
480480

bootstrap3/tests.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from django import forms
77
from django.contrib.admin.widgets import AdminSplitDateTime
8-
from django.contrib.gis import forms as gisforms
98
from django.contrib.messages import constants as DEFAULT_MESSAGE_LEVELS
109
from django.forms.formsets import formset_factory
1110
from django.template import engines
@@ -30,13 +29,11 @@
3029
('Audio', (
3130
('vinyl', 'Vinyl'),
3231
('cd', 'CD'),
33-
)
34-
),
32+
)),
3533
('Video', (
3634
('vhs', 'VHS Tape'),
3735
('dvd', 'DVD'),
38-
)
39-
),
36+
)),
4037
('unknown', 'Unknown'),
4138
)
4239

@@ -466,7 +463,7 @@ def test_input_group(self):
466463

467464
def test_input_group_addon_button(self):
468465
res = render_template_with_form(
469-
'{% bootstrap_field form.subject addon_before="$" addon_before_class="input-group-btn" addon_after=".00" addon_after_class="input-group-btn" %}')
466+
'{% bootstrap_field form.subject addon_before="$" addon_before_class="input-group-btn" addon_after=".00" addon_after_class="input-group-btn" %}') # noqa
470467
self.assertIn('class="input-group"', res)
471468
self.assertIn('class="input-group-btn">$', res)
472469
self.assertIn('class="input-group-btn">.00', res)
@@ -508,8 +505,6 @@ def test_label(self):
508505
def test_attributes_consistency(self):
509506
form = TestForm()
510507
attrs = form.fields['addon'].widget.attrs.copy()
511-
context = dict(form=form)
512-
field_alone = render_form_field("addon", context)
513508
self.assertEqual(attrs, form.fields['addon'].widget.attrs)
514509

515510

@@ -707,9 +702,14 @@ def test_button_with_icon(self):
707702
res = render_template_with_form(
708703
"{% bootstrap_button 'test' icon='info-sign' button_type='submit' %}"
709704
)
710-
self.assertEqual(
711-
res.strip(),
712-
'<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-info-sign"></span> test</button>'
705+
self.assertHTMLEqual(
706+
res,
707+
'<button'
708+
' class="btn btn-default"'
709+
' type="submit">'
710+
'<span'
711+
' class="glyphicon glyphicon-info-sign"></span>'
712+
' test</button>'
713713
)
714714

715715

@@ -720,7 +720,6 @@ def test_placeholder_set_from_label(self):
720720

721721

722722
class ShowAddonsTest(TestCase):
723-
724723
def assertFieldHasAddons(self, field):
725724
"""Asserts that a given field has an after and before addon."""
726725
addon_before = "bf"

demo/demo/forms.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django import forms
55
from django.forms.formsets import BaseFormSet, formset_factory
66

7-
87
from bootstrap3.tests import TestForm
98

109
RADIO_CHOICES = (
@@ -16,13 +15,11 @@
1615
('Audio', (
1716
('vinyl', 'Vinyl'),
1817
('cd', 'CD'),
19-
)
20-
),
18+
)),
2119
('Video', (
2220
('vhs', 'VHS Tape'),
2321
('dvd', 'DVD'),
24-
)
25-
),
22+
)),
2623
('unknown', 'Unknown'),
2724
)
2825

@@ -39,6 +36,7 @@ def clean(self):
3936
super(ContactBaseFormSet, self).clean()
4037
raise forms.ValidationError("This error was added to show the non form errors styling")
4138

39+
4240
ContactFormSet = formset_factory(TestForm, formset=ContactBaseFormSet,
4341
extra=2,
4442
max_num=4,

demo/demo/wsgi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"""
1616
import os
1717

18+
from django.core.wsgi import get_wsgi_application
19+
1820
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
1921
# if running multiple sites in the same mod_wsgi process. To fix this, use
2022
# mod_wsgi daemon mode with each site in its own daemon process, or use
@@ -24,7 +26,7 @@
2426
# This application object is used by any WSGI server configured to use this
2527
# file. This includes Django's development server, if the WSGI_APPLICATION
2628
# setting points here.
27-
from django.core.wsgi import get_wsgi_application
29+
2830
application = get_wsgi_application()
2931

3032
# Apply WSGI middleware here.

0 commit comments

Comments
 (0)