Skip to content

Commit

Permalink
tests: Remove unittest usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler committed Jun 4, 2024
1 parent 5732eca commit 7081db5
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 67 deletions.
5 changes: 2 additions & 3 deletions tests/form_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# license that can be found in the LICENSE file.
import re
import time
import unittest

import pytest

Expand All @@ -13,7 +12,7 @@
def skip_if_zope(f):
def wrapper(self, *args, **kwargs):
if self.__class__.__name__ == "ZopeTestBrowserDriverTest":
return unittest.skip("skipping this test for zope testbrowser")
return pytest.skip("skipping this test for zope testbrowser")
else:
f(self, *args, **kwargs)

Expand All @@ -23,7 +22,7 @@ def wrapper(self, *args, **kwargs):
def skip_if_django(f):
def wrapper(self, *args, **kwargs):
if self.__class__.__name__ == "DjangoClientDriverTest":
return unittest.skip("skipping this test for django")
return pytest.skip("skipping this test for django")
else:
f(self, *args, **kwargs)

Expand Down
16 changes: 6 additions & 10 deletions tests/test_djangoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import sys
import time
import unittest

import django
import pytest
Expand All @@ -22,7 +21,7 @@
django.setup()


class DjangoClientDriverTest(BaseBrowserTests, unittest.TestCase):
class DjangoClientDriverTest(BaseBrowserTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("django")
Expand Down Expand Up @@ -150,21 +149,18 @@ def test_cookies_extra_parameters(self):
assert timestamp == cookie["expires"]


class DjangoClientDriverTestWithCustomHeaders(unittest.TestCase):
@classmethod
def setUpClass(cls):
class DjangoClientDriverTestWithCustomHeaders:
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
custom_headers = {
"X-Splinter-Customheaders-1": "Hello",
"X-Splinter-Customheaders-2": "Bye",
}
cls.browser = Browser("django", custom_headers=custom_headers)
request.cls.browser = get_browser("django", custom_headers=custom_headers)
request.addfinalizer(request.cls.browser.quit)

def test_create_a_phantomjs_with_custom_headers(self):
self.browser.visit(EXAMPLE_APP + "headers")
assert self.browser.is_text_present("X-Splinter-Customheaders-1: Hello")

assert self.browser.is_text_present("X-Splinter-Customheaders-2: Bye")

@classmethod
def tearDownClass(cls):
cls.browser.quit()
31 changes: 13 additions & 18 deletions tests/test_flaskclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@
# license that can be found in the LICENSE file.
import os
import time
import unittest

import pytest

from .base import BaseBrowserTests
from .base import get_browser
from .fake_webapp import app
from .fake_webapp import EXAMPLE_APP
from splinter import Browser


class FlaskClientDriverTest(BaseBrowserTests, unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.browser = Browser("flask", app=app, wait_time=0.1)
class FlaskClientDriverTest(BaseBrowserTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("flask", app=app, wait_time=0.1)
request.addfinalizer(request.cls.browser.quit)

def setUp(self):
@pytest.fixture(autouse=True)
def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)

@classmethod
def tearDownClass(cls):
cls.browser.quit()

def test_should_support_with_statement(self):
with Browser("flask", app=app) as internet:
assert internet is not None
Expand Down Expand Up @@ -174,20 +172,17 @@ def test_cookies_extra_parameters(self):
assert timestamp == int(cookie.expires.timestamp())


class FlaskClientDriverTestWithCustomHeaders(unittest.TestCase):
@classmethod
def setUpClass(cls):
class FlaskClientDriverTestWithCustomHeaders:
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
custom_headers = {
"X-Splinter-Customheaders-1": "Hello",
"X-Splinter-Customheaders-2": "Bye",
}
cls.browser = Browser("flask", app=app, custom_headers=custom_headers)
request.cls.browser = get_browser("flask", app=app, custom_headers=custom_headers)
request.addfinalizer(request.cls.browser.quit)

def test_create_a_flask_client_with_custom_headers(self):
self.browser.visit(EXAMPLE_APP + "headers")
assert self.browser.is_text_present("X-Splinter-Customheaders-1: Hello")
assert self.browser.is_text_present("X-Splinter-Customheaders-2: Bye")

@classmethod
def tearDownClass(cls):
cls.browser.quit()
18 changes: 10 additions & 8 deletions tests/test_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import unittest
import pytest

from splinter.request_handler.status_code import StatusCode


class RequestHandlerTestCase(unittest.TestCase):
def setUp(self):
self.status_code = StatusCode(200, "OK")
@pytest.fixture()
def valid_status_code():
return StatusCode(200, "OK")

def test_should_receive_an_url_and_get_a_success_response(self):
assert self.status_code.is_success()

def test_should_compare_app_index_with_404_and_get_false(self):
assert self.status_code != 404
def test_should_receive_an_url_and_get_a_success_response(valid_status_code):
assert valid_status_code.is_success()


def test_should_compare_app_index_with_404_and_get_false(valid_status_code):
assert valid_status_code != 404
6 changes: 2 additions & 4 deletions tests/test_webdriver_chrome.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Copyright 2013 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import unittest

import pytest

from .base import get_browser
from .base import WebDriverTests
from .fake_webapp import EXAMPLE_APP


class ChromeBrowserTest(WebDriverTests, unittest.TestCase):
class ChromeBrowserTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("chrome", fullscreen=False)
Expand All @@ -22,7 +20,7 @@ def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)


class ChromeBrowserFullscreenTest(WebDriverTests, unittest.TestCase):
class ChromeBrowserFullscreenTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("chrome", fullscreen=True)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_webdriver_edge_chromium.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Copyright 2021 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import unittest

import pytest

from .base import get_browser
from .base import WebDriverTests
from .fake_webapp import EXAMPLE_APP


class EdgeChromiumBrowserTest(WebDriverTests, unittest.TestCase):
class EdgeChromiumBrowserTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("edge", fullscreen=False)
Expand All @@ -22,7 +20,7 @@ def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)


class EdgeChromiumBrowserFullscreenTest(WebDriverTests, unittest.TestCase):
class EdgeChromiumBrowserFullscreenTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("edge", fullscreen=True)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_webdriver_firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import os
import unittest

import pytest

Expand All @@ -12,7 +11,7 @@
from splinter.config import Config


class FirefoxBrowserTest(WebDriverTests, unittest.TestCase):
class FirefoxBrowserTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("firefox", fullscreen=False)
Expand All @@ -23,7 +22,7 @@ def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)


class FirefoxBrowserFullScreenTest(WebDriverTests, unittest.TestCase):
class FirefoxBrowserFullScreenTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("firefox", fullscreen=True)
Expand Down
16 changes: 9 additions & 7 deletions tests/test_webdriver_remote.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2013 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import unittest
from unittest.mock import patch
from urllib.request import urlopen

Expand All @@ -22,13 +21,14 @@ def selenium_server_is_running():
return "WebDriver Hub" in page_contents


class RemoteBrowserFirefoxTest(WebDriverTests, unittest.TestCase):
class RemoteBrowserFirefoxTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = Browser("remote", browser="firefox")
request.addfinalizer(request.cls.browser.quit)

def setUp(self):
@pytest.fixture(autouse=True)
def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)

def test_support_with_statement(self):
Expand All @@ -41,13 +41,14 @@ def test_should_be_able_to_change_user_agent(self):
pass


class RemoteBrowserChromeTest(WebDriverTests, unittest.TestCase):
class RemoteBrowserChromeTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = Browser("remote", browser="chrome")
request.addfinalizer(request.cls.browser.quit)

def setUp(self):
@pytest.fixture(autouse=True)
def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)

def test_support_with_statement(self):
Expand All @@ -61,7 +62,7 @@ def test_should_be_able_to_change_user_agent(self):


@pytest.mark.macos
class RemoteBrowserSafariTest(WebDriverTests, unittest.TestCase):
class RemoteBrowserSafariTest(WebDriverTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
# test with statement. It can't be used as simple test
Expand All @@ -72,7 +73,8 @@ def setup_browser(self, request):
request.cls.browser = Browser("remote", browser="safari")
request.addfinalizer(request.cls.browser.quit)

def setUp(self):
@pytest.fixture(autouse=True)
def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)

def test_support_with_statement(self):
Expand Down
18 changes: 8 additions & 10 deletions tests/test_zopetestbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import os
import unittest

import pytest

from .base import BaseBrowserTests
from .base import get_browser
from .fake_webapp import EXAMPLE_APP
from splinter import Browser


class ZopeTestBrowserDriverTest(BaseBrowserTests, unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.browser = Browser("zope.testbrowser", wait_time=0.1)
class ZopeTestBrowserDriverTest(BaseBrowserTests):
@pytest.fixture(autouse=True, scope="class")
def setup_browser(self, request):
request.cls.browser = get_browser("zope.testbrowser", wait_time=0.1)
request.addfinalizer(request.cls.browser.quit)

def setUp(self):
@pytest.fixture(autouse=True)
def visit_example_app(self, request):
self.browser.visit(EXAMPLE_APP)

@classmethod
def tearDownClass(cls):
cls.browser.quit()

def test_should_support_with_statement(self):
with Browser("zope.testbrowser"):
pass
Expand Down

0 comments on commit 7081db5

Please sign in to comment.