Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Add flake8 to CircleCI and enable for the test folder (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbampton authored and Marc-Andre-Rivet committed Dec 14, 2018
1 parent 29b72b2 commit fa82eeb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ jobs:
name: npm run lint
command: npm run lint

- run:
name: python run lint
command: |
. venv/bin/activate
flake8 --ignore=E501,F401,F841,F811 test
- run:
name: Build
command: |
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ selenium
pandas
dash_table_experiments
xlrd
flake8
6 changes: 3 additions & 3 deletions test/IntegrationTests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import absolute_import
import os
import multiprocessing
import os
import platform
import threading
import time
import unittest
import percy
import threading
import platform
import flask
import requests

Expand Down
8 changes: 4 additions & 4 deletions test/test_dash_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
class TestDashImport(unittest.TestCase):
def setUp(self):
with open('dash.py', 'w') as f:
pass
pass

def tearDown(self):
try:
os.remove('dash.py')
os.remove('dash.pyc')
except OSError:
pass

def test_dash_import(self):
"""Test that program exits if the wrong dash module was imported"""

with self.assertRaises(SystemExit) as cm:
import dash_core_components

Expand Down
51 changes: 23 additions & 28 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,15 @@ def test_tabs_in_vertical_mode(self):
dcc.Tab(label='Tab three', value='tab-3', id='tab-3', children=[
html.Div('Tab Three Content')
]),
], vertical=True),
], vertical=True),
html.Div(id='tabs-content')
])

self.startServer(app=app)
self.wait_for_text_to_equal('#tab-3', 'Tab three')

self.snapshot('Tabs - vertical mode')

def test_tabs_without_children(self):
app = dash.Dash(__name__)

Expand All @@ -518,18 +519,18 @@ def test_tabs_without_children(self):
dcc.Tabs(id="tabs", value='tab-2', children=[
dcc.Tab(label='Tab one', value='tab-1', id='tab-1'),
dcc.Tab(label='Tab two', value='tab-2', id='tab-2'),
]),
]),
html.Div(id='tabs-content')
])

@app.callback(dash.dependencies.Output('tabs-content', 'children'),
[dash.dependencies.Input('tabs', 'value')])
[dash.dependencies.Input('tabs', 'value')])
def render_content(tab):
if(tab == 'tab-1'):
if tab == 'tab-1':
return html.Div([
html.H3('Test content 1')
], id='test-tab-1')
elif(tab == 'tab-2'):
elif tab == 'tab-2':
return html.Div([
html.H3('Test content 2')
], id='test-tab-2')
Expand Down Expand Up @@ -565,7 +566,6 @@ def test_tabs_render_without_selected(self):
{'id': 'two', 'value': 2},
]


menu = html.Div([
html.Div('one', id='one'),
html.Div('two', id='two')
Expand All @@ -583,7 +583,6 @@ def test_tabs_render_without_selected(self):
])
], id='tabs-two', style={'display': 'none'})


app.layout = html.Div([
menu,
tabs_one,
Expand All @@ -593,7 +592,7 @@ def test_tabs_render_without_selected(self):
for i in ('one', 'two'):

@app.callback(Output('tabs-{}'.format(i), 'style'),
[Input(i, 'n_clicks')])
[Input(i, 'n_clicks')])
def on_click(n_clicks):
if n_clicks is None:
raise PreventUpdate
Expand All @@ -602,18 +601,17 @@ def on_click(n_clicks):
return {'display': 'block'}
return {'display': 'none'}


@app.callback(Output('graph-{}'.format(i), 'figure'),
[Input(i, 'n_clicks')])
[Input(i, 'n_clicks')])
def on_click(n_clicks):
if n_clicks is None:
raise PreventUpdate

return {
'data': [
{
'x': [1,2,3,4],
'y': [4,3,2,1]
'x': [1, 2, 3, 4],
'y': [4, 3, 2, 1]
}
]
}
Expand Down Expand Up @@ -655,9 +653,8 @@ def test_tabs_without_value(self):
html.Div(id='tabs-content')
])


@app.callback(Output('tabs-content', 'children'),
[Input('tabs-without-value', 'value')])
[Input('tabs-without-value', 'value')])
def render_content(tab):
if tab == 'tab-1':
return html.H3('Default selected Tab content 1')
Expand All @@ -682,7 +679,7 @@ def test_graph_does_not_resize_in_tabs(self):
])

@app.callback(Output('tabs-content-example', 'children'),
[Input('tabs-example', 'value')])
[Input('tabs-example', 'value')])
def render_content(tab):
if tab == 'tab-1-example':
return html.Div([
Expand Down Expand Up @@ -744,7 +741,6 @@ def render_content(tab):

self.snapshot("Tabs with Graph - clicked tab 1 (graph should not resize)")


def test_location_link(self):
app = dash.Dash(__name__)

Expand Down Expand Up @@ -889,7 +885,7 @@ def test_link_scroll(self):
call_count = Value('i', 0)

@app.callback(Output('page-content', 'children'),
[Input('test-url', 'pathname')])
[Input('test-url', 'pathname')])
def display_page(pathname):
call_count.value = call_count.value + 1
return 'You are on page {}'.format(pathname)
Expand All @@ -898,7 +894,7 @@ def display_page(pathname):

time.sleep(2)

#callback is called twice when defined
# callback is called twice when defined
self.assertEqual(
call_count.value,
2
Expand All @@ -917,11 +913,11 @@ def display_page(pathname):
self.wait_for_text_to_equal(
'#page-content', 'You are on page /test-link')

#test if rendered Link's <a> tag has a href attribute
# test if rendered Link's <a> tag has a href attribute
link_href = test_link.get_attribute("href")
self.assertEqual(link_href, 'http://localhost:8050/test-link')

#test if callback is only fired once (offset of 2)
# test if callback is only fired once (offset of 2)
self.assertEqual(
call_count.value,
3
Expand Down Expand Up @@ -1030,7 +1026,7 @@ def test_datepickerrange_updatemodes(self):
@app.callback(
dash.dependencies.Output('date-picker-range-output', 'children'),
[dash.dependencies.Input('date-picker-range', 'start_date'),
dash.dependencies.Input('date-picker-range', 'end_date')])
dash.dependencies.Input('date-picker-range', 'end_date')])
def update_output(start_date, end_date):
return '{} - {}'.format(start_date, end_date)

Expand Down Expand Up @@ -1062,7 +1058,7 @@ def test_interval(self):
])

@app.callback(Output('output', 'children'),
[Input('interval', 'n_intervals')])
[Input('interval', 'n_intervals')])
def update_text(n):
return "{}".format(n)

Expand Down Expand Up @@ -1093,7 +1089,7 @@ def test_if_interval_can_be_restarted(self):
@app.callback(
Output('interval', 'max_intervals'),
[Input('start', 'n_clicks_timestamp'),
Input('stop', 'n_clicks_timestamp')])
Input('stop', 'n_clicks_timestamp')])
def start_stop(start, stop):
if start < stop:
return 0
Expand Down Expand Up @@ -1494,9 +1490,9 @@ def update_output(input, state):
return 'input="{}", state="{}"'.format(input, state)

self.startServer(app)
output = lambda: self.driver.find_element_by_id('output')
input = lambda: self.driver.find_element_by_id('input')
state = lambda: self.driver.find_element_by_id('state')
output = lambda: self.driver.find_element_by_id('output') # noqa: E731
input = lambda: self.driver.find_element_by_id('input') # noqa: E731
state = lambda: self.driver.find_element_by_id('state') # noqa: E731

# callback gets called with initial input
wait_for(lambda: call_count.value == 1)
Expand Down Expand Up @@ -1559,7 +1555,6 @@ def update_output(value):
call_count.value,
# an initial call to retrieve the first value
1 +
# one for each hello world character
# one for each hello world character # noqa: W504
len('hello world')
)

0 comments on commit fa82eeb

Please sign in to comment.