Skip to content

Commit 6a9279b

Browse files
author
Xing Han Lu
committed
Updates based on PR comments
Additionally, changes to the Python versioning avoids version errors with CircleCI, as discussed here: plotly/dash#636
1 parent 473ac4f commit 6a9279b

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

demos/editor/callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def validate_positive(value):
2929
return min(0, value)
3030

3131

32-
def validate_color(color: str, default='#999999'):
32+
def validate_color(color, default='#999999'):
3333
'''
3434
Check if a color is valid, if so returns the color, else return a default color
3535
:param color: The color to validate

tests/test_interactions.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
"""Notes for the hardcoded values in the `init_pos` dictionary:
2+
3+
It's impossible to programatically get the initial rendered positions of the nodes, since we would
4+
need to obtain the node object (in dictionary format), which can be done either by (a) using the
5+
tapNode callback, which paradoxally requires you to click the node, or (b) by making a complex
6+
calculation relative to the size of the screen w.r.t largest coordinate in the list of elements.
7+
But (b) is unreliable, since we do not know how much padding around the graph is required, so it
8+
will likely be off.
9+
10+
If there is a need to modify the values in `init_pos`, e.g. if the size of the webdriver screen
11+
is changed, you can do the following:
12+
- Run usage-events.py
13+
- Resize window size to 1280x1000, or preferred size (can be manually done or with selenium)
14+
- Tap on a node
15+
- Inside the "Node Object JSON" section, find "renderedPosition" and use the values there
16+
- Repeat this for all the nodes
17+
18+
Notice also that there's an offset to Node 3's position. This is because it overlaps with
19+
Node 6, so clicking on Node 3 will erroneously show that you clicked Node 6. Therefore, adding an
20+
offset to the y-axis will ensure that the correct node is clicked.
21+
"""
122
import os
223
import importlib
324
import time
@@ -12,12 +33,30 @@
1233

1334
class Tests(IntegrationTests):
1435
def test_interactions(self):
36+
# VARIABLES
37+
drag_error = "Unable to drag Cytoscape nodes properly"
38+
click_error = "Unable to click Cytoscape nodes properly"
39+
mouseover_error = "Unable to mouseover Cytoscape nodes properly"
40+
41+
# View module docstring for more information about initial positions
42+
init_pos = {
43+
'Node 1': (80.94611044209678, 333.54879281525285),
44+
'Node 2': (375.64032747402433, 628.2430098471805),
45+
'Node 3': (277.40892179671516, 514.2945792615018 - 20),
46+
'Node 4': (768.5659501832611, 333.54879281525285),
47+
'Node 5': (473.8717331513335, 431.780198492562),
48+
'Node 6': (277.40892179671516, 530.0116041698712)
49+
}
50+
init_x, init_y = init_pos['Node 1']
51+
52+
# Initialize the apps
1553
app = importlib.import_module('usage-events').app
1654
self.startServer(app)
1755
WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, "cytoscape")))
1856

1957
actions = ActionChains(self.driver)
2058

59+
# FUNCTIONS
2160
def save_screenshot(dir_name, name):
2261
directory_path = os.path.join(
2362
os.path.dirname(__file__),
@@ -106,23 +145,10 @@ def perform_mouseover(x, y, elem, dir_name='interactions'):
106145

107146
return mouseover_label
108147

109-
drag_error = "Unable to drag Cytoscape nodes properly"
110-
click_error = "Unable to click Cytoscape nodes properly"
111-
mouseover_error = "Unable to mouseover Cytoscape nodes properly"
112-
113-
init_pos = {
114-
'Node 1': (80.94611044209678, 333.54879281525285),
115-
'Node 2': (375.64032747402433, 628.2430098471805),
116-
'Node 3': (277.40892179671516, 514.2945792615018 - 20),
117-
'Node 4': (768.5659501832611, 333.54879281525285),
118-
'Node 5': (473.8717331513335, 431.780198492562),
119-
'Node 6': (277.40892179671516, 530.0116041698712)
120-
}
121-
init_x, init_y = init_pos['Node 1']
122148
# Select the JSON output element
123149
elem_tap = self.driver.find_element_by_css_selector('pre#tap-node-json-output')
124150

125-
# # Test dragging the nodes around
151+
# Test dragging the nodes around
126152
offset_x, offset_y = perform_dragging(init_x, init_y, 0, 0, elem_tap)
127153
init_x += offset_x
128154
init_y += offset_y

tests/test_percy_snapshot.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ def display_image(pathname): # pylint: disable=W0612
7676

7777
def percy_snapshot(self, name=''):
7878
if os.environ.get('PERCY_ENABLED', False):
79-
snapshot_name = '{} (Python {}.{}.{})'.format(
79+
snapshot_name = '{} (Python {}.{})'.format(
8080
name,
8181
sys.version_info.major,
82-
sys.version_info.minor,
83-
sys.version_info.micro,
82+
sys.version_info.minor
8483
)
8584

8685
self.percy_runner.snapshot(

0 commit comments

Comments
 (0)