Skip to content

Commit

Permalink
Merge pull request #86 from xsnippet/pypy3
Browse files Browse the repository at this point in the history
Add support for PyPy3
  • Loading branch information
malor committed Apr 29, 2018
2 parents a6cd909 + 0e4f535 commit 603bc63
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ matrix:
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- python: pypy3
env: TOXENV=pypy
- python: 3.6
env: TOXENV=openapi
- python: 3.6
Expand Down
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Some pytest fixtures used around the code."""

import re

import picobox
import pkg_resources
import pytest
Expand Down Expand Up @@ -56,3 +58,22 @@ async def testapp(request, aiohttp_client, testconf, testdatabase):
# and do not set 'Content-Type' for us if it wasn't passed.
skip_auto_headers={'Content-Type'},
)


def pytest_namespace():
# Expose some internally used helpers via 'pytest' module to make it
# available everywhere without making modules and packages.
return {'regex': _pytest_regex}


class _pytest_regex:
"""Assert that a given string matches a given regular expression."""

def __init__(self, pattern, flags=0):
self._regex = re.compile(pattern, flags)

def __eq__(self, actual):
return bool(self._regex.match(actual))

def __repr__(self):
return self._regex.pattern
32 changes: 9 additions & 23 deletions tests/resources/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
:license: MIT, see LICENSE for details
"""

import re
import json
import datetime
import cgi
Expand All @@ -17,19 +16,6 @@
import pytest


class _pytest_regex:
"""Assert that a given string matches a given regular expression."""

def __init__(self, pattern, flags=0):
self._regex = re.compile(pattern, flags)

def __eq__(self, actual):
return bool(self._regex.match(actual))

def __repr__(self):
return self._regex.pattern


class _pytest_link_header:
"""Assert that two HTTP Link headers are equal to each other."""

Expand Down Expand Up @@ -528,8 +514,8 @@ async def test_get_snippets_pagination_not_found(testapp):
'content': 'def foo(): pass',
'syntax': None,
'tags': [],
'created_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
'created_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
({'title': 'snippet #1',
'content': 'def foo(): pass',
Expand All @@ -540,8 +526,8 @@ async def test_get_snippets_pagination_not_found(testapp):
'content': 'def foo(): pass',
'syntax': 'python',
'tags': ['tag_a', 'tag_b'],
'created_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
'created_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
])
async def test_post_snippet(testapp, testconf, snippet, rv):
testconf['snippet']['syntaxes'] = 'python\nclojure'
Expand Down Expand Up @@ -668,8 +654,8 @@ async def test_delete_snippet_bad_request(testapp):
'content': 'def foo(): pass',
'syntax': None,
'tags': [],
'created_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
'created_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
({'title': 'snippet #1',
'content': 'def foo(): pass',
Expand All @@ -680,8 +666,8 @@ async def test_delete_snippet_bad_request(testapp):
'content': 'def foo(): pass',
'syntax': 'python',
'tags': ['tag_a', 'tag_b'],
'created_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
'created_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}')}),
])
async def test_put_snippet(testapp, snippets, snippet, rv):
resp = await testapp.put('/v1/snippets/1', data=json.dumps(snippet))
Expand Down Expand Up @@ -764,7 +750,7 @@ async def test_patch_snippet(testapp, snippets):
'syntax': 'python',
'tags': ['tag_a', 'tag_b'],
'created_at': '2018-01-24T22:26:35',
'updated_at': _pytest_regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
'updated_at': pytest.regex('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'),
}


Expand Down
3 changes: 1 addition & 2 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ async def test_post_malformed_payload(testapp):

assert resp.status == 400
assert await resp.json() == {
'message': ('Malformed application/json payload: '
'Expecting value: line 1 column 1 (char 0)'),
'message': pytest.regex('^Malformed application/json payload:.*'),
}


Expand Down

0 comments on commit 603bc63

Please sign in to comment.