Skip to content

Commit

Permalink
Improve linting and add missing requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
John Lane authored and jlane9 committed Jul 22, 2019
1 parent 2a96906 commit e17e8d3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
16 changes: 9 additions & 7 deletions Pipfile
Expand Up @@ -7,16 +7,18 @@ verify_ssl = true

[packages]
bumpversion = ">=0.5.0"
needle = "<0.6.0,>=0.5.0"
pytest = ">=3.0.0,<5.0.0"
pytest-cov = ">=2.5.0"
needle = ">=0.5.0,<0.6.0"
Pillow = ">=6.0.0"
pytest = ">=3.7.0,<5.0.0"
pytest-cov = ">=2.7.0"
pytest-pep8 = ">=1.0.0"
python-coveralls = ">=2.9.0"
pytest-selenium = ">=1.10.0,<2.0.0"
recommonmark = ">=0.4.0"
pytest-selenium = ">=1.16.0,<2.0.0"
recommonmark = ">=0.5.0"
selenium = ">=3.0.0"
sphinx-autobuild = ">=0.7.0"
sphinx-rtd-theme = ">=0.2.4"
Sphinx = ">=1.6.5"
sphinx-rtd-theme = ">=0.4.0"
Sphinx = ">=1.8.0"

[requires]
python_version = "3.7"
4 changes: 3 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions pytest_needle/driver.py
Expand Up @@ -23,11 +23,7 @@
from io import BytesIO as IOClass

# Ignoring since basetring is not redefined if running on python3
# pylint: disable=W0622
# pylint: disable=C0103
basestring = str
# pylint: enable=W0622
# pylint: enable=C0103
basestring = str # pylint: disable=W0622,C0103

else:
try:
Expand All @@ -42,7 +38,7 @@
DEFAULT_VIEWPORT_SIZE = '1024x768'


class NeedleDriver(object):
class NeedleDriver(object): # pylint: disable=R0205
"""NeedleDriver instance
"""

Expand Down Expand Up @@ -90,14 +86,16 @@ def _find_element(self, element_or_selector=None):
:return:
"""

if isinstance(element_or_selector, tuple):
if isinstance(element_or_selector, tuple): # pylint: disable=R1705

elements = self.driver.find_elements(*element_or_selector)
return elements[0] if elements else None

elif isinstance(element_or_selector, WebElement):
return element_or_selector

raise ValueError("element_or_selector must be a WebElement or tuple selector")

@staticmethod
def _get_element_dimensions(element):
"""Returns an element's position and size
Expand All @@ -119,6 +117,8 @@ def _get_element_dimensions(element):
'height': int(size['height'])
}

raise ValueError("element must be a WebElement")

def _get_element_rect(self, element):
"""Returns the two points that define the rectangle
Expand All @@ -137,6 +137,8 @@ def _get_element_rect(self, element):
(dimensions['top'] + dimensions['height'])
)

return ()

@staticmethod
def _get_ratio(image_size, window_size):

Expand Down Expand Up @@ -294,7 +296,7 @@ def assert_screenshot(self, file_path, element_or_selector=None, threshold=0, ex
:return:
"""

element = self._find_element(element_or_selector)
element = self._find_element(element_or_selector) if element_or_selector else None

# Get baseline screenshot
self._create_dir(self.baseline_dir)
Expand All @@ -303,7 +305,8 @@ def assert_screenshot(self, file_path, element_or_selector=None, threshold=0, ex

# Take screenshot and exit if in baseline saving mode
if self.save_baseline:
return self.get_screenshot_as_image(element, exclude=exclude).save(baseline_image)
self.get_screenshot_as_image(element, exclude=exclude).save(baseline_image)
return

# Get fresh screenshot
self._create_dir(self.output_dir)
Expand All @@ -322,7 +325,7 @@ def assert_screenshot(self, file_path, element_or_selector=None, threshold=0, ex
self.engine.assertSameFiles(fresh_image_file, baseline_image, threshold)

except AssertionError as err:
msg = err.message if hasattr(err, "message") else err.args[0] if err.args else ""
msg = getattr(err, 'message', err.args[0] if err.args else "")
args = err.args[1:] if len(err.args) > 1 else []
raise ImageMismatchException(msg, baseline_image, fresh_image_file, args)

Expand Down Expand Up @@ -398,7 +401,8 @@ def set_viewport(self):
"""

if self.viewport_size.lower() == 'fullscreen':
return self.driver.maximize_window()
self.driver.maximize_window()
return

viewport_size = re.match(r'(?P<width>\d+)\s?[xX]\s?(?P<height>\d+)', self.viewport_size)

Expand Down
2 changes: 0 additions & 2 deletions pytest_needle/exceptions.py
Expand Up @@ -9,8 +9,6 @@ class NeedleException(AssertionError):
"""Base exception for pytest-needle
"""

pass


class ImageMismatchException(NeedleException):
"""Image mismatch exception
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -7,6 +7,7 @@ pytest-pep8>=1.0.0
python-coveralls>=2.9.0
pytest-selenium>=1.16.0,<2.0.0
recommonmark>=0.5.0
selenium>=3.0.0
sphinx>=1.8.0
sphinx-autobuild>=0.7.0
sphinx-rtd-theme>=0.4.0
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -35,8 +35,9 @@ def read(filename):
long_description_content_type="text/markdown",
install_requires=[
'pytest>=3.7.0,<5.0.0',
'pytest-selenium>=1.16.0,<2.0.0',
'needle>=0.5.0,<0.6.0',
'pytest-selenium>=1.16.0,<2.0.0'
'selenium>=3.0.0'
],
python_requires=">=2.7",
tests_require=[
Expand Down
1 change: 1 addition & 0 deletions test/test_example.py
Expand Up @@ -161,6 +161,7 @@ def test_image_engine(needle, engine):
"""Verify all image engines can be set
:param NeedleDriver needle: NeedleDriver instance
:param engine: Image engine class
:return:
"""

Expand Down
2 changes: 1 addition & 1 deletion test/test_screenshot_creation.py
Expand Up @@ -17,7 +17,7 @@ def test_screenshot_creation(needle):
pytest.skip('Only run screenshot creation for non-baseline runs')

screenshot_name = 'screenshot_without_baseline'
screenshot_path = os.path.join(needle.output_dir, screenshot_name+".png")
screenshot_path = os.path.join(needle.output_dir, screenshot_name + ".png")
needle.driver.get('https://www.example.com')

try:
Expand Down

0 comments on commit e17e8d3

Please sign in to comment.