Skip to content

Commit

Permalink
[py] Add initial unit test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt committed Mar 10, 2017
1 parent c32d893 commit 36ba4cc
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ matrix:
- language: python
python: 2.7
env: TOXENV=docs
- language: python
python: 2.7
env: TOXENV=py27-unit
- language: python
python: 2.7
env: CHROME=1 TOXENV=py27-chrome
Expand Down Expand Up @@ -159,6 +162,9 @@ matrix:
- language: python
python: 3.6
env: TOXENV=docs
- language: python
python: 3.6
env: TOXENV=py36-unit
- language: python
python: 3.6
env: CHROME=1 TOXENV=py36-chrome
Expand Down
3 changes: 2 additions & 1 deletion py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def load(self, name):

@pytest.fixture(autouse=True, scope='session')
def server(request):
if 'Remote' not in request.config.getoption('drivers'):
drivers = request.config.getoption('drivers')
if drivers is None or 'Remote' not in drivers:
yield None
return

Expand Down
2 changes: 1 addition & 1 deletion py/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ ignore = E501

[tool:pytest]
addopts = -r=a
python_files = *_tests.py
python_files = test_*.py *_tests.py
testpaths = test
16 changes: 16 additions & 0 deletions py/test/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
16 changes: 16 additions & 0 deletions py/test/unit/selenium/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
16 changes: 16 additions & 0 deletions py/test/unit/selenium/webdriver/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
16 changes: 16 additions & 0 deletions py/test/unit/selenium/webdriver/remote/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
35 changes: 35 additions & 0 deletions py/test/unit/selenium/webdriver/remote/test_remote_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import pytest

from selenium.webdriver.remote.remote_connection import RemoteConnection


def test_basic_auth(mocker):
def check(request, timeout):
assert request.headers['Authorization'] == 'Basic dXNlcjpwYXNz'

try:
method = mocker.patch('urllib.request.OpenerDirector.open')
except ImportError:
method = mocker.patch('urllib2.OpenerDirector.open')
method.side_effect = check

with pytest.raises(AttributeError):
RemoteConnection('http://user:pass@remote', resolve_ip=False) \
.execute('status', {})
6 changes: 4 additions & 2 deletions py/tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[tox]
envlist = py{27,36}-{chrome,edge,firefox,ie,phantomjs,remote,safari}, docs, flake8
envlist = py{27,36}-{unit,chrome,edge,firefox,ie,phantomjs,remote,safari}, docs, flake8

[testenv]
passenv = DISPLAY PYTEST_ADDOPTS
commands =
py{27,36}-unit: py.test -n=auto {posargs:test/unit}
py{27,36}-chrome: py.test -n=auto --driver=Chrome {posargs}
py{27,36}-edge: py.test --driver=Edge {posargs}
py{27,36}-firefox: py.test -n=auto --driver=Firefox {posargs}
Expand All @@ -16,8 +17,9 @@ install_command = pip install -v --no-index --find-links=../third_party/py {opts
deps =
pytest==3.0.3
pytest-instafail==0.3.0
pytest-mock==1.5.0
py{27,36}-phantomjs: psutil==4.3.1
py{27,36}-{chrome,firefox,marionette,phantomjs}: pytest-xdist==1.15
py{27,36}-{unit,chrome,firefox,marionette,phantomjs}: pytest-xdist==1.15

[testenv:docs]
skip_install = true
Expand Down
Binary file not shown.
Binary file added third_party/py/mock-2.0.0-py2.py3-none-any.whl
Binary file not shown.
Binary file added third_party/py/pbr-2.0.0-py2.py3-none-any.whl
Binary file not shown.
Binary file not shown.

0 comments on commit 36ba4cc

Please sign in to comment.