Skip to content

Commit

Permalink
moved hoverpy's TestCase class to its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
shyal committed Dec 9, 2016
1 parent f0a0c68 commit afcfb87
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
9 changes: 9 additions & 0 deletions docs/source/hoverpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ hoverpy package
Submodules
----------

hoverpy.testing module
----------------------

.. automodule:: hoverpy.testing
:members:
:undoc-members:
:show-inheritance:


Module contents
---------------

Expand Down
6 changes: 3 additions & 3 deletions docs/source/unittesting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ In this example, we'll take a look at writing unit tests that use HoverPy. Pleas

::

>>> import hoverpy
>>> from hoverpy import testing


Instead of inheriting off `unittest.TestCase` let's inherit off `hoverpy.TestCase`
Instead of inheriting off `unittest.TestCase` let's inherit off `hoverpy.testing.TestCase`

::

>>> class TestRTD(hoverpy.TestCase):
>>> class TestRTD(testing.TestCase):


In our test, we'll once again download a load of readthedocs pages
Expand Down
6 changes: 3 additions & 3 deletions examples/unittesting/unittesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# that you are testing your code against known data. This makes you hermetic to
# issues with third party APIs. Let's begin by importing hoverpy.

import hoverpy
from hoverpy import testing

# Instead of inheriting off `unittest.TestCase` let's inherit off
# `hoverpy.TestCase`
# `hoverpy.testing.TestCase`


class TestRTD(hoverpy.TestCase):
class TestRTD(testing.TestCase):

# in our test, we'll once again download a load of readthedocs pages
def test_rtd_links(self):
Expand Down
27 changes: 0 additions & 27 deletions hoverpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,32 +393,5 @@ def quick_test():
if "data" in hp.delays().keys():
print("HOVERPY AND HOVERFLY QUICK TEST SUCCESS!!")

import unittest


class TestCase(unittest.TestCase):

hp = None

def setUp(self):
enabled = os.environ.get(
"HOVERPY_ENABLED",
"true").lower() in [
"true",
"1",
"on"]
if enabled:
capture = os.environ.get(
"HOVERPY_CAPTURE",
"").lower() in [
"true",
"1",
"on"]
self.hp = HoverPy(capture=capture)

def tearDown(self):
if self.hp:
self.hp.__disableProxy()

if __name__ == "__main__":
quick_test()
32 changes: 32 additions & 0 deletions hoverpy/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from hoverpy import HoverPy
import unittest
import os


class TestCase(unittest.TestCase):
"""
TestCase, which can be used like unittest.TestCase
"""

def setUp(self):
"""
Set up each test case by initializing HoverPy
"""

enabled = os.environ.get(
"HOVERPY_ENABLED",
"true").lower() in [
"true",
"1",
"on"]
if enabled:
capture = os.environ.get(
"HOVERPY_CAPTURE",
"").lower() in [
"true",
"1",
"on"]
self.hp = HoverPy(capture=capture)

def tearDown(self):
del self.hp
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ docs: .PHONY
mv examples/urllib2eg/urllib2eg.rst docs/source/
mv examples/urllib3eg/urllib3eg.rst docs/source/

#sphinx-apidoc -o docs/source/ hoverpy
sphinx-apidoc -o docs/source/ hoverpy hoverpy/tests hoverpy/config.py hoverpy/generateDocs.py -f

cd docs; make html;
# cd docs/source/mermaid/intro; mermaid *;
Expand Down

0 comments on commit afcfb87

Please sign in to comment.