Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix docstring, add getting available port number #448

Merged
merged 12 commits into from
Oct 18, 2019

Conversation

KazuCocoa
Copy link
Member

No description provided.

driver2 = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
self.assertEqual(2, len(self.driver.all_sessions))
finally:
if driver2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not None


def tearDown(self):
self.driver.quit()

def testAllSessions(self):
def test_all_sessions(self):
port = desired_capabilities.get_available_port()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this method be located in desired_capabilities?
I'd rather put in test helpers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, let me update them to the proper place later.
Current this test is not stable (I rebuild once to make the CI green)

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

for port in range(8102, 8200):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic numbers?

def get_available_port(in_range):
"""Returns available local port number.
"""
range(8102, 8200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this operator is for?

"""
range(8102, 8200)
if not isinstance(in_range, range):
raise ValueError('{} should be range'.format(in_range))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be of type range

@@ -0,0 +1,15 @@
def get_available_port(in_range):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

port_range

"""Returns available local port number.
"""
range(8102, 8200)
if not isinstance(in_range, range):
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Oct 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in python3 range creates a generator by default. I would rather provide just start and end port numbers with default values of 8102 and 8200 as method arguments

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

for port in in_range:
if sock.connect_ex(('localhost', port)) != 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try:
    if sock.connect_ex(('localhost', port)) != 0:
       return port
finally:
    sock.close()

@KazuCocoa KazuCocoa changed the title [wip] fix docstring, add getting available port number fix docstring, add getting available port number Oct 13, 2019
@@ -0,0 +1,15 @@
def get_available_port_range(from_range, to_range):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...port_from_range

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from_port, to_port

@KazuCocoa
Copy link
Member Author

KazuCocoa commented Oct 13, 2019

removed wip

def get_available_port_range(from_range, to_range):
"""Returns available local port number.
"""
if not isinstance(from_range, int) or not isinstance(to_range, int):
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Oct 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit types verifications is not very pythonic

simply cast values to int in range call and let it throw if this is not possible

self.driver1.quit()
desired_caps['wdaLocalPort'] = port

class get_all_sessions(object):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class name doesn't mean actual behavior and it's a little tricky.
I'd rather have your original code style from maintenance point of view if it works.

WebDriverWait(driver2, 10).until(len(driver.all_sessions) == 2)

or

TIMEOUT = 10
WebDriverWait(driver2, TIMEOUT).until(len(driver.all_sessions) == 2)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(driver.all_sessions) == 2 did not work in WebDriverWait, unfortunately

"""
r = range(from_port, to_port)

import socket
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we don't import socket at the start of the module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just copied and pasted, but can move it to outside. Will do with renaming the class name

self.driver1.quit()
desired_caps['wdaLocalPort'] = port

class GetAllSessions(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually class names are nouns. How about SessionCountIsTwoCondition ?

self.driver1.quit()
desired_caps['wdaLocalPort'] = port

class session_counts_is_two(object):
Copy link
Member Author

@KazuCocoa KazuCocoa Oct 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snake case to follow https://selenium-python.readthedocs.io/waits.html 's name style

@KazuCocoa KazuCocoa merged commit 947a943 into appium:master Oct 18, 2019
@KazuCocoa KazuCocoa deleted the km/tweak-all-sessions branch October 18, 2019 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants