Skip to content

Commit 26df79a

Browse files
author
Xing
authored
Merge pull request #37 from plotly/dev
Add tests for callbacks and user interactions
2 parents f7cc272 + 13850d2 commit 26df79a

33 files changed

+709
-106
lines changed

.circleci/config.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,39 @@ jobs:
5959
name: Run pylint
6060
command: |
6161
. venv/bin/activate
62-
pylint usage.py tests
62+
pylint usage.py usage-advanced.py usage-elements.py usage-events.py usage-stylesheet.py
63+
pylint demos tests
6364
when: always
6465

6566
- run:
6667
name: Run flake8
6768
command: |
6869
. venv/bin/activate
69-
flake8 usage.py tests
70+
flake8 --max-line-length=100 usage.py usage-advanced.py usage-elements.py usage-events.py usage-stylesheet.py
71+
flake8 --max-line-length=100 demos tests
7072
when: always
7173

7274
- run:
73-
name: Integration Tests - Usage
75+
name: Integration Tests - Usage Apps Rendering
7476
command: |
7577
. venv/bin/activate
7678
python -m unittest tests.test_usage
7779
when: always
7880

81+
- run:
82+
name: Integration Tests - Interactions
83+
command: |
84+
. venv/bin/activate
85+
python -m unittest tests.test_interactions
86+
when: always
87+
88+
- run:
89+
name: Integration Tests - Callbacks
90+
command: |
91+
. venv/bin/activate
92+
python -m unittest tests.test_callbacks
93+
when: always
94+
7995
- run:
8096
name: Capture Percy Snapshots
8197
command: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
.idea/**/gradle.xml
3838
.idea/**/libraries
3939
tests/screenshots/*.png
40+
tests/screenshots/**/*.png
4041

4142
# misc
4243
.DS_Store

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## Added
10+
* `tests.test_usage`: Tests for rendering usage files.
11+
* `tests.test_callbacks`: Tests for updating `Cytoscape` with callbacks.
12+
* `tests.test_interactions`: Tests for interacting with `Cytoscape`, and evaluating its event callbacks.
13+
* `tests.test_percy_snapshot`: Creates a Percy build using screenshots from other tests.
14+
15+
## Changed
16+
* `config.yml`: Added steps to run the new tests. Added coverage for Python 3.7. Included `demos` and all usage examples in `pylint` and `flake8`. Increased line limit to 100.
17+
* `demos/usage-*`: Formatted all demo apps in order to respect pylint and flake8.
18+
* `usage-*`: Formatted all demo apps in order to respect pylint and flake8.
19+
* `package.json`: Removed `"prepublish": "npm run validate-init"` due to conflict with CircleCI build. This script will be deprecated in favor of the upcoming Dash Component CLI.
20+
* `tests/IntegrationTests.py`: Moved the `percy_snapshot` method to `test_percy_snapshot` in order to avoid duplicate (failing) builds on Percy. Decrease the number of processes to 1.
21+
22+
## Removed
23+
* `tests.test_render`: Removed unused test
24+
925
## Added
1026
* Two new demos: `usage-grid-social-network.py` and `usage-concentric-social-network.py`
1127
* Add Issue and PR templates for Github (located in `.github`)

demos/dash_reusable_components.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from textwrap import dedent
2-
31
import dash_core_components as dcc
42
import dash_html_components as html
53

demos/editor/callbacks.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=W0612,R1705
12
import json
23
from colour import Color
34

@@ -41,10 +42,19 @@ def validate_color(color, default='#999999'):
4142
try:
4243
# Converting 'deep sky blue' to 'deepskyblue'
4344
color = color.replace(" ", "")
45+
46+
if color.startswith('rgb'):
47+
values = color.replace('rgb(', '').replace(')', '').split(',')
48+
49+
if len(values) == 3 and all(0 <= int(v) <= 255 for v in values):
50+
return color
51+
52+
return default
53+
4454
Color(color)
4555
# if everything goes fine then return True
4656
return color
47-
except: # The color code was not found
57+
except: # noqa
4858
return default
4959

5060

@@ -225,7 +235,6 @@ def disable_side_endpoint_width(value):
225235
def disable_side_endpoint_height(value):
226236
return value != 'other'
227237

228-
229238
# ############################## CYTOSCAPE ################################
230239
@app.callback(Output('cytoscape', 'elements'),
231240
[Input('dropdown-select-element-list', 'value')])

demos/editor/layout.py

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@
437437
id='dropdown-edge-curve-style',
438438
value='haystack',
439439
clearable=False,
440-
searchable=False,
441440
options=drc.DropdownOptionsList(
442441
'haystack',
443442
'bezier',
@@ -610,8 +609,7 @@
610609
placeholder='Input value in % or px...',
611610
value='0px'
612611
)
613-
]) for side in
614-
['source', 'target']],
612+
]) for side in ['source', 'target']],
615613

616614
drc.NamedInput(
617615
name='Source Distance from node',
@@ -637,8 +635,7 @@
637635
drc.NamedRadioItems(
638636
name='Use Labels',
639637
id='radio-use-labels',
640-
options=drc.DropdownOptionsList('yes',
641-
'no'),
638+
options=drc.DropdownOptionsList('yes', 'no'),
642639
value='no'
643640
),
644641

@@ -682,8 +679,7 @@
682679
options=[{
683680
'label': element.capitalize(),
684681
'value': f'div-label-{element}'
685-
} for element in
686-
LABEL_ELEMENT_TYPES],
682+
} for element in LABEL_ELEMENT_TYPES],
687683
clearable=False,
688684
value='div-label-node'
689685
),
@@ -760,8 +756,7 @@
760756
searchable=False,
761757
value='none'
762758
)
763-
]) for element in
764-
LABEL_ELEMENT_TYPES],
759+
]) for element in LABEL_ELEMENT_TYPES],
765760
]),
766761
drc.NamedCard(title='Text Wrapping', size=4, children=[
767762
drc.NamedDropdown(
@@ -770,8 +765,7 @@
770765
options=[{
771766
'label': element.capitalize(),
772767
'value': f'div-text-wrapping-{element}'
773-
} for element in
774-
LABEL_ELEMENT_TYPES],
768+
} for element in LABEL_ELEMENT_TYPES],
775769
clearable=False,
776770
value='div-text-wrapping-node'
777771
),
@@ -796,8 +790,7 @@
796790
type='number',
797791
placeholder='Enter the maximum width in px...'
798792
)
799-
]) for element in
800-
LABEL_ELEMENT_TYPES],
793+
]) for element in LABEL_ELEMENT_TYPES],
801794
]),
802795
drc.NamedCard(title='Label Alignment', size=4, children=[
803796
drc.NamedRadioItems(
@@ -848,23 +841,24 @@
848841
value='div-text-margins-node'
849842
),
850843

851-
*[html.Div(id=f'div-text-margins-{element}',
852-
children=[
853-
drc.NamedInput(
854-
name=f"{element.capitalize()} Margin X (px)",
855-
id=f'input-{element}-text-margin-x',
856-
type='number',
857-
placeholder='Enter a value in px...'
858-
),
859-
860-
drc.NamedInput(
861-
name=f"{element.capitalize()} Margin Y(px)",
862-
id=f'input-{element}-text-margin-y',
863-
type='number',
864-
placeholder='Enter a value in px...'
865-
)
866-
]) for element in
867-
LABEL_ELEMENT_TYPES_ALL],
844+
*[html.Div(
845+
id=f'div-text-margins-{element}',
846+
children=[
847+
drc.NamedInput(
848+
name=f"{element.capitalize()} Margin X (px)",
849+
id=f'input-{element}-text-margin-x',
850+
type='number',
851+
placeholder='Enter a value in px...'
852+
),
853+
854+
drc.NamedInput(
855+
name=f"{element.capitalize()} Margin Y(px)",
856+
id=f'input-{element}-text-margin-y',
857+
type='number',
858+
placeholder='Enter a value in px...'
859+
)
860+
]
861+
) for element in LABEL_ELEMENT_TYPES_ALL],
868862
])
869863
]
870864
)

demos/usage-animated-bfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/animated-bfs/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/animated-bfs
3+
Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/animated-bfs
44
55
Note: Animation Not Implemented yet, please refer to code.
66
"""

demos/usage-breadthfirst-layout.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/images-breadthfirst-layout/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/images-breadthfirst-layout
43
54
Note: Click Animation is not implemented.
65
"""

demos/usage-circle-layout.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/circle-layout/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/circle-layout
43
"""
54
import json
65

demos/usage-compound-nodes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Original Demo: http://js.cytoscape.org/demos/compound-nodes/
3-
Original Code: https://github.com/cytoscape/cytoscape.js/tree/master/documentation/demos/compound-nodes
43
54
Note: The Dash version is also uncentered. Otherwise it works.
65
"""

0 commit comments

Comments
 (0)