summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGael Pasgrimaud <gael@gawel.org>2018-09-22 12:19:15 +0200
committerGael Pasgrimaud <gael@gawel.org>2018-09-22 12:19:15 +0200
commit27a87d8f478b5a918a5392ca648766d24746b6e2 (patch)
treed92cf5c5660a0434ea108a938b70366296a47f44
parent1aeeb31587f04da58b432679bdb71d40206894d9 (diff)
downloadwebtest-27a87d8f478b5a918a5392ca648766d24746b6e2.tar.gz
switch to pytest
-rw-r--r--.travis.yml5
-rw-r--r--docs/forms.rst8
-rw-r--r--docs/forms_fixt.py20
-rw-r--r--docs/index.rst5
-rw-r--r--docs/index_fixt.py15
-rw-r--r--docs/testapp.rst25
-rw-r--r--docs/testapp_fixt.py42
-rw-r--r--docs/testresponse.rst23
-rw-r--r--docs/testresponse_fixt.py46
-rw-r--r--setup.cfg12
-rw-r--r--tests/test_utils.py32
-rw-r--r--tox.ini18
12 files changed, 101 insertions, 150 deletions
diff --git a/.travis.yml b/.travis.yml
index d55ab13..e14bfa5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,6 @@ language: python
matrix:
include:
- python: 2.7
- - python: 3.3
- python: 3.4
- python: 3.5
- python: 3.6
@@ -11,6 +10,6 @@ matrix:
dist: xenial
install:
- - python setup.py dev
+ - pip install tox-travis
script:
- - nosetests -s -v --with-coverage
+ - tox
diff --git a/docs/forms.rst b/docs/forms.rst
index 0bd5740..63cd804 100644
--- a/docs/forms.rst
+++ b/docs/forms.rst
@@ -1,6 +1,14 @@
Form handling
=============
+..
+ >>> from webtest.debugapp import make_debug_app
+ >>> from webtest.app import TestApp
+ >>> app = make_debug_app({},
+ ... form='docs/form.html',
+ ... show_form=True)
+ >>> app = TestApp(app)
+
Getting a form
--------------
diff --git a/docs/forms_fixt.py b/docs/forms_fixt.py
deleted file mode 100644
index 26548aa..0000000
--- a/docs/forms_fixt.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# -*- coding: utf-8 -*-
-from webtest.debugapp import make_debug_app
-from webtest.app import TestApp
-from doctest import ELLIPSIS
-from doctest import NORMALIZE_WHITESPACE
-import os
-
-dirname = os.path.dirname(__file__)
-
-
-def setup_test(test):
- app = make_debug_app({},
- form=os.path.join(dirname, 'form.html'),
- show_form=True)
- test.globs['app'] = TestApp(app)
- for example in test.examples:
- example.options.setdefault(ELLIPSIS, 1)
- example.options.setdefault(NORMALIZE_WHITESPACE, 1)
-
-setup_test.__test__ = False
diff --git a/docs/index.rst b/docs/index.rst
index c18b33e..4db1737 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -70,6 +70,11 @@ The most important object in WebTest is :class:`~webtest.app.TestApp`, the wrapp
for WSGI applications. It also allows you to perform HTTP requests on it.
To use it, you simply instantiate it with your WSGI application.
+..
+ >>> import os
+ >>> with open('docs/form.html', 'rb') as fd:
+ ... body = fd.read()
+
.. note::
If your WSGI application requires any configuration,
diff --git a/docs/index_fixt.py b/docs/index_fixt.py
deleted file mode 100644
index dc60645..0000000
--- a/docs/index_fixt.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# -*- coding: utf-8 -*-
-import doctest
-import os
-
-
-def setup_test(test):
- fd = open(os.path.join(os.path.dirname(__file__), 'form.html'), 'rb')
- body = fd.read()
- fd.close()
- test.globs.update(body=body)
- for example in test.examples:
- example.options.setdefault(doctest.ELLIPSIS, 1)
- example.options.setdefault(doctest.NORMALIZE_WHITESPACE, 1)
-
-setup_test.__test__ = False
diff --git a/docs/testapp.rst b/docs/testapp.rst
index 911daca..b93b065 100644
--- a/docs/testapp.rst
+++ b/docs/testapp.rst
@@ -1,6 +1,31 @@
TestApp
=======
+..
+ >>> import json
+ >>> import six
+ >>> import sys
+ >>> from webtest.app import TestApp
+ >>> from webob import Request
+ >>> from webob import Response
+ >>> def application(environ, start_response):
+ ... req = Request(environ)
+ ... if req.path_info.endswith('.html'):
+ ... content_type = 'text/html'
+ ... body = six.b('<html><body><div id="content">hey!</div></body>')
+ ... elif req.path_info.endswith('.xml'):
+ ... content_type = 'text/xml'
+ ... body = six.b('<xml><message>hey!</message></xml>')
+ ... elif req.path_info.endswith('.json'):
+ ... content_type = 'application/json'
+ ... body = six.b(json.dumps({"a": 1, "b": 2}))
+ ... elif '/resource/' in req.path_info:
+ ... content_type = 'application/json'
+ ... body = six.b(json.dumps(dict(id=1, value='value')))
+ ... resp = Response(body, content_type=content_type)
+ ... return resp(environ, start_response)
+ >>> app = TestApp(application)
+
Making Requests
---------------
diff --git a/docs/testapp_fixt.py b/docs/testapp_fixt.py
deleted file mode 100644
index ecbbeb8..0000000
--- a/docs/testapp_fixt.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# -*- coding: utf-8 -*-
-from doctest import NORMALIZE_WHITESPACE
-from doctest import ELLIPSIS
-from doctest import SKIP
-from webtest import TestApp
-from webob import Request
-from webob import Response
-import json
-import six
-import sys
-
-
-def application(environ, start_response):
- req = Request(environ)
- if req.path_info.endswith('.html'):
- content_type = 'text/html'
- body = six.b('<html><body><div id="content">hey!</div></body>')
- elif req.path_info.endswith('.xml'):
- content_type = 'text/xml'
- body = six.b('<xml><message>hey!</message></xml>')
- elif req.path_info.endswith('.json'):
- content_type = 'application/json'
- body = six.b(json.dumps({"a": 1, "b": 2}))
- elif '/resource/' in req.path_info:
- content_type = 'application/json'
- body = six.b(json.dumps(dict(id=1, value='value')))
- resp = Response(body, content_type=content_type)
- return resp(environ, start_response)
-
-
-def setup_test(test):
- ver = sys.version_info[:2]
- test.globs.update(app=TestApp(application))
- for example in test.examples:
- if "'xml'" in example.want and ver == (2, 6):
- # minidom node do not render the same in 2.6
- example.options[SKIP] = 1
- else:
- example.options[ELLIPSIS] = 1
- example.options[NORMALIZE_WHITESPACE] = 1
-
-setup_test.__test__ = False
diff --git a/docs/testresponse.rst b/docs/testresponse.rst
index 0eb1343..309d8f3 100644
--- a/docs/testresponse.rst
+++ b/docs/testresponse.rst
@@ -1,6 +1,29 @@
TestResponse
############
+..
+ >>> import json
+ >>> import six
+ >>> import sys
+ >>> from webob import Request
+ >>> from webob import Response
+ >>> from webtest.app import TestApp
+ >>> def application(environ, start_response):
+ ... req = Request(environ)
+ ... if req.path_info.endswith('.html'):
+ ... content_type = 'text/html'
+ ... body = six.b('<html><body><div id="content">hey!</div></body>')
+ ... elif req.path_info.endswith('.xml'):
+ ... content_type = 'text/xml'
+ ... body = six.b('<xml><message>hey!</message></xml>')
+ ... elif req.path_info.endswith('.json'):
+ ... content_type = 'application/json'
+ ... body = six.b(json.dumps({"a": 1, "b": 2}))
+ ... resp = Response(body, content_type=content_type)
+ ... return resp(environ, start_response)
+ >>> app = TestApp(application)
+
+
The response object is based on :class:`webob.response.Response` with some additions
to help with testing.
diff --git a/docs/testresponse_fixt.py b/docs/testresponse_fixt.py
deleted file mode 100644
index b80503e..0000000
--- a/docs/testresponse_fixt.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# -*- coding: utf-8 -*-
-from doctest import NORMALIZE_WHITESPACE
-from doctest import ELLIPSIS
-from doctest import SKIP
-from webtest import TestApp
-from webob import Request
-from webob import Response
-import json
-import six
-import sys
-
-
-def application(environ, start_response):
- req = Request(environ)
- if req.path_info.endswith('.html'):
- content_type = 'text/html'
- body = six.b('<html><body><div id="content">hey!</div></body>')
- elif req.path_info.endswith('.xml'):
- content_type = 'text/xml'
- body = six.b('<xml><message>hey!</message></xml>')
- elif req.path_info.endswith('.json'):
- content_type = 'application/json'
- body = six.b(json.dumps({"a": 1, "b": 2}))
- resp = Response(body, content_type=content_type)
- return resp(environ, start_response)
-
-
-def setup_test(test):
- ver = sys.version_info[:2]
- is_pypy = 'PyPy' in sys.version
- test.globs.update(app=TestApp(application))
- for example in test.examples:
- if "lxml" in example.source and is_pypy:
- # minidom node do not render the same in 2.6
- example.options[SKIP] = 1
- elif "pyquery" in example.source and is_pypy:
- # minidom node do not render the same in 2.6
- example.options[SKIP] = 1
- elif "'xml'" in example.want and ver == (2, 6):
- # minidom node do not render the same in 2.6
- example.options[SKIP] = 1
- else:
- example.options[ELLIPSIS] = 1
- example.options[NORMALIZE_WHITESPACE] = 1
-
-setup_test.__test__ = False
diff --git a/setup.cfg b/setup.cfg
index 395b063..448dae5 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -15,3 +15,15 @@ include = docs
exclude = (CHANGELOG|changelog|contributing).rst
cover-package=webtest
doctest-options = +ELLIPSIS,+NORMALIZE_WHITESPACE
+
+[tool:pytest]
+addopts = -p no:warnings
+ --doctest-modules
+ --doctest-glob='*.rst'
+ --ignore=docs/
+ --ignore=CHANGES.rst
+ --ignore=setup.py
+ --ignore=bootstrap.py
+ --ignore=examples/
+ --ignore=docs/conf.py
+doctest_optionflags= NORMALIZE_WHITESPACE ELLIPSIS
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 4301d33..b897897 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -11,30 +11,30 @@ class NoDefaultTest(unittest.TestCase):
def test_nodefault(self):
from webtest.utils import NoDefault
- self.assertEquals(repr(NoDefault), '<NoDefault>')
+ self.assertEqual(repr(NoDefault), '<NoDefault>')
class encode_paramsTest(unittest.TestCase):
def test_encode_params_None(self):
- self.assertEquals(utils.encode_params(None, None), None)
+ self.assertEqual(utils.encode_params(None, None), None)
def test_encode_params_NoDefault(self):
- self.assertEquals(utils.encode_params(utils.NoDefault, None), '')
+ self.assertEqual(utils.encode_params(utils.NoDefault, None), '')
def test_encode_params_dict_or_list(self):
- self.assertEquals(utils.encode_params({'foo': 'bar'}, None),
+ self.assertEqual(utils.encode_params({'foo': 'bar'}, None),
utils.encode_params([('foo', 'bar')], None))
def test_encode_params_no_charset(self):
# no content_type at all
- self.assertEquals(utils.encode_params({'foo': 'bar'}, None), 'foo=bar')
+ self.assertEqual(utils.encode_params({'foo': 'bar'}, None), 'foo=bar')
# content_type without "charset=xxxx"
- self.assertEquals(utils.encode_params({'foo': 'bar'}, 'ba'), 'foo=bar')
+ self.assertEqual(utils.encode_params({'foo': 'bar'}, 'ba'), 'foo=bar')
def test_encode_params_charset_utf8(self):
# charset is using inconsistent casing on purpose, it should still work
- self.assertEquals(utils.encode_params({'f': '€'}, ' CHARset=uTF-8; '),
+ self.assertEqual(utils.encode_params({'f': '€'}, ' CHARset=uTF-8; '),
'f=%E2%82%AC')
@@ -45,15 +45,15 @@ class make_patternTest(unittest.TestCase):
return make_pattern(obj)
def test_make_pattern_None(self):
- self.assertEquals(self.call_FUT(None), None)
+ self.assertEqual(self.call_FUT(None), None)
def test_make_pattern_regex(self):
regex = re.compile(r'foobar')
- self.assertEquals(self.call_FUT(regex), regex.search)
+ self.assertEqual(self.call_FUT(regex), regex.search)
def test_make_pattern_function(self):
func = lambda x: x
- self.assertEquals(self.call_FUT(func), func)
+ self.assertEqual(self.call_FUT(func), func)
def test_make_pattern_bytes(self):
# if we pass a string, it will get compiled into a regex
@@ -67,13 +67,13 @@ class make_patternTest(unittest.TestCase):
class stringifyTest(unittest.TestCase):
def test_stringify_text(self):
- self.assertEquals(utils.stringify("foo"), "foo")
+ self.assertEqual(utils.stringify("foo"), "foo")
def test_stringify_binary(self):
- self.assertEquals(utils.stringify(b"foo"), "foo")
+ self.assertEqual(utils.stringify(b"foo"), "foo")
def test_stringify_other(self):
- self.assertEquals(utils.stringify(123), "123")
+ self.assertEqual(utils.stringify(123), "123")
class json_methodTest(unittest.TestCase):
@@ -92,20 +92,20 @@ class json_methodTest(unittest.TestCase):
def test_json_method_request_calls(self):
from webtest.utils import NoDefault
# no params
- self.assertEquals(self.mock.foo_json('url', params=NoDefault, c='c'),
+ self.assertEqual(self.mock.foo_json('url', params=NoDefault, c='c'),
('FOO', 'url', {'content_type': 'application/json',
'c': 'c',
'params': NoDefault,
'upload_files': None}))
# params dumped to json
- self.assertEquals(self.mock.foo_json('url', params={'a': 'b'}, c='c'),
+ self.assertEqual(self.mock.foo_json('url', params={'a': 'b'}, c='c'),
('FOO', 'url', {'content_type': 'application/json',
'c': 'c',
'params': json.dumps({'a': 'b'}),
'upload_files': None}))
def test_json_method_request_respects_content_type_argument(self):
- self.assertEquals(self.mock.foo_json('url', params={'a': 'b'}, c='c', content_type='application/vnd.api+json;charset=utf-8'),
+ self.assertEqual(self.mock.foo_json('url', params={'a': 'b'}, c='c', content_type='application/vnd.api+json;charset=utf-8'),
('FOO', 'url', {'content_type': 'application/vnd.api+json;charset=utf-8',
'c': 'c',
'params': json.dumps({'a': 'b'}),
diff --git a/tox.ini b/tox.ini
index 50c4628..74a3016 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,27 +3,29 @@ skip_missing_interpreters=true
envlist=py27,py33,py34,py35,py36,py37,coverage
[testenv]
+skip_install=true
setenv =
LC_ALL=C
LANG=C
COVERAGE_FILE=.coverage.{envname}
deps =
- nose<1.3.0
- .[tests]
+ pytest
+ pytest-mock
+ -e .[tests]
lxml
pyquery
- mock
BeautifulSoup4
PasteDeploy
WSGIProxy2
+ coverage
commands =
- {envbindir}/python --version
- {envbindir}/pip freeze
- py{27,33}: {envbindir}/nosetests --with-coverage --with-xunit --xunit-file=nosetests-{envname}.xml []
- py{27,33}: {envbindir}/coverage xml -o coverage-{envname}.xml
- py{34,35,36,37}: {envbindir}/nosetests
+ python --version
+ pip freeze
+ coverage run {envbindir}/pytest -xv []
[testenv:coverage]
+skip_install=false
+skipsdist=true
deps =
coverage
setenv =