Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #169 from edx/dep_upgrades
Browse files Browse the repository at this point in the history
Upgrade dependencies, improve test coverage
  • Loading branch information
Jeremy Bowman authored Jun 17, 2016
2 parents ac9890e + c939d11 commit 10344a8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[run]
branch = True
source = bok_choy

[report]
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python
python:
- '2.7'
- '3.5'
- 'pypy'
sudo: false
branches:
only:
Expand Down
4 changes: 2 additions & 2 deletions bok_choy/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def save_driver_logs(driver, prefix):
"It may be that the browser does not support it."
).format(log_type=log_type)

LOGGER.warning(msg, exec_info=True)
LOGGER.warning(msg, exc_info=True)


def browser(tags=None, proxy=None):
Expand Down Expand Up @@ -330,7 +330,7 @@ def _local_browser_class(browser_name):

def _remote_browser_class(env_vars, tags=None):
"""
Returns class, kwargs, and args needed to instatiate the remote browser.
Returns class, kwargs, and args needed to instantiate the remote browser.
"""
if tags is None:
tags = []
Expand Down
6 changes: 3 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ lazy-object-proxy==1.2.2
wrapt==1.10.8

# cov-core
coverage==3.7.1
coverage==4.1

# pylint
colorama==0.3.7

# pylint-plugin-utils
astroid==1.4.6
pylint==1.5.4
pylint==1.5.6

# pylint-celery, pylint-django
pylint-plugin-utils
Expand All @@ -37,7 +37,7 @@ pytest==2.9.2
edx_lint==0.5.1

# For mocking functionality in assorted tests
mock==1.0.1
mock==2.0.0

# For checking compliance with PEP 8 coding style guidelines
pycodestyle==2.0.0
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
license='Apache 2.0',
classifiers=['Development Status :: 3 - Alpha',
classifiers=['Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Testing',
'Topic :: Software Development :: Quality Assurance'],
packages=['bok_choy', 'bok_choy/a11y'],
Expand Down
59 changes: 43 additions & 16 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,16 @@ def test_socket_error(self):
self.assertEqual(patch_object.call_count, 3)


class TestSaveFiles(TestCase):

def setUp(self):
super(TestSaveFiles, self).setUp()
class TestSaveFiles(object):

def setup(self):
# Create a temp directory to save the files to
tempdir_path = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tempdir_path))
self.tempdir_path = tempfile.mkdtemp()
self.browser = bok_choy.browser.browser()

# Take a screenshot of a page
browser = bok_choy.browser.browser()
self.addCleanup(browser.quit)
self.browser = browser
self.tempdir_path = tempdir_path
def teardown(self):
shutil.rmtree(self.tempdir_path)
self.browser.quit()

def test_save_screenshot(self):
browser = self.browser
Expand All @@ -129,10 +125,15 @@ def test_save_screenshot(self):

# Check that the file was created
expected_file = os.path.join(tempdir_path, 'button_page.png')
self.assertTrue(os.path.isfile(expected_file))
assert os.path.isfile(expected_file)

# Check that the file is not empty
self.assertGreater(os.stat(expected_file).st_size, 100)
assert os.stat(expected_file).st_size > 100

def test_save_screenshot_unsupported(self, caplog):
browser = 'Some driver without save_screenshot()'
bok_choy.browser.save_screenshot(browser, 'button_page')
assert 'Browser does not support screenshots.' in caplog.text

def test_save_driver_logs(self):
browser = self.browser
Expand All @@ -148,7 +149,24 @@ def test_save_driver_logs(self):
log_types = ['browser', 'driver', 'client', 'server']
for log_type in log_types:
expected_file = os.path.join(tempdir_path, 'js_page_{}.log'.format(log_type))
self.assertTrue(os.path.isfile(expected_file))
assert os.path.isfile(expected_file)

def test_save_driver_logs_exception(self, caplog):
browser = self.browser
tempdir_path = self.tempdir_path

# Configure the driver log directory using an environment variable
os.environ['SELENIUM_DRIVER_LOG_DIR'] = tempdir_path
JavaScriptPage(browser).visit()
with patch.object(browser, 'get_log', side_effect=Exception):
bok_choy.browser.save_driver_logs(browser, 'js_page')

# Check that no files were created.
log_types = ['browser', 'driver', 'client', 'server']
for log_type in log_types:
expected_file = os.path.join(tempdir_path, 'js_page_{}.log'.format(log_type))
assert not os.path.exists(expected_file)
assert "Could not save browser log of type '{}'.".format(log_type) in caplog.text

def test_save_source(self):
browser = self.browser
Expand All @@ -161,7 +179,16 @@ def test_save_source(self):

# Check that the file was created
expected_file = os.path.join(tempdir_path, 'button_page.html')
self.assertTrue(os.path.isfile(expected_file))
assert os.path.isfile(expected_file)

# Check that the file is not empty
self.assertGreater(os.stat(expected_file).st_size, 100)
assert os.stat(expected_file).st_size > 100

def test_save_source_missing_directory(self, caplog):
os.environ['SAVED_SOURCE_DIR'] = '/does_not_exist'
ButtonPage(self.browser).visit()
bok_choy.browser.save_source(self.browser, 'button_page')

expected_file = os.path.join(self.tempdir_path, 'button_page.html')
assert not os.path.exists(expected_file)
assert 'Could not save the browser page source' in caplog.text

0 comments on commit 10344a8

Please sign in to comment.