From dd39dbe85eed1716273d9ffecb3c19dc7c00c20c Mon Sep 17 00:00:00 2001 From: Barnabus Date: Sat, 15 Dec 2018 00:32:58 +1000 Subject: [PATCH] Add flake8 to CircleCI and enable for the test folder (#342) --- .../dash-core-components/.circleci/config.yml | 6 +++ .../dash-core-components/dev-requirements.txt | 1 + .../test/IntegrationTests.py | 6 +-- .../test/test_dash_import.py | 8 +-- .../test/test_integration.py | 51 +++++++++---------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/dash-core-components/.circleci/config.yml b/packages/dash-core-components/.circleci/config.yml index dbef69874e..1632672909 100644 --- a/packages/dash-core-components/.circleci/config.yml +++ b/packages/dash-core-components/.circleci/config.yml @@ -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: | diff --git a/packages/dash-core-components/dev-requirements.txt b/packages/dash-core-components/dev-requirements.txt index abea377526..6ba575466b 100644 --- a/packages/dash-core-components/dev-requirements.txt +++ b/packages/dash-core-components/dev-requirements.txt @@ -5,3 +5,4 @@ selenium pandas dash_table_experiments xlrd +flake8 diff --git a/packages/dash-core-components/test/IntegrationTests.py b/packages/dash-core-components/test/IntegrationTests.py index e372cd88e8..03dbac57f6 100644 --- a/packages/dash-core-components/test/IntegrationTests.py +++ b/packages/dash-core-components/test/IntegrationTests.py @@ -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 diff --git a/packages/dash-core-components/test/test_dash_import.py b/packages/dash-core-components/test/test_dash_import.py index 9eb0774eee..64fb350eca 100644 --- a/packages/dash-core-components/test/test_dash_import.py +++ b/packages/dash-core-components/test/test_dash_import.py @@ -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 diff --git a/packages/dash-core-components/test/test_integration.py b/packages/dash-core-components/test/test_integration.py index 996a6e4d35..84053d2944 100644 --- a/packages/dash-core-components/test/test_integration.py +++ b/packages/dash-core-components/test/test_integration.py @@ -502,7 +502,7 @@ 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') ]) @@ -510,6 +510,7 @@ def test_tabs_in_vertical_mode(self): 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__) @@ -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') @@ -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') @@ -583,7 +583,6 @@ def test_tabs_render_without_selected(self): ]) ], id='tabs-two', style={'display': 'none'}) - app.layout = html.Div([ menu, tabs_one, @@ -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 @@ -602,9 +601,8 @@ 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 @@ -612,8 +610,8 @@ def on_click(n_clicks): return { 'data': [ { - 'x': [1,2,3,4], - 'y': [4,3,2,1] + 'x': [1, 2, 3, 4], + 'y': [4, 3, 2, 1] } ] } @@ -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') @@ -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([ @@ -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__) @@ -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) @@ -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 @@ -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 tag has a href attribute + # test if rendered Link's 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 @@ -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) @@ -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) @@ -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 @@ -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) @@ -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') ) -