Skip to content

Commit cccd30a

Browse files
committed
Add Format to the standard pact package
1 parent b78ac6d commit cccd30a

26 files changed

+518
-42
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ self.assertEqual(result, get_generated_values(expected))
253253
Often times, you find yourself having to re-write regular expressions for common formats.
254254

255255
```python
256-
from pact.matchers import Format
256+
from pact import Format
257257
Format().integer # Matches if the value is an integer
258258
Format().ip_address # Matches if the value is a ip address
259259
```
@@ -276,7 +276,7 @@ We've created a number of them for you to save you the time:
276276
These can be used to replace other matchers
277277

278278
```python
279-
from pact import Like, Term
279+
from pact import Like, Format
280280
Like({
281281
'id': Format().integer, # integer
282282
'lastUpdated': Format().timestamp, # timestamp

examples/e2e/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ attrs==19.3.0
22
certifi==2019.11.28
33
chardet==3.0.4
44
click==7.1.1
5+
enum34==1.1.10
56
Flask==1.1.1
67
idna==2.9
78
importlib-metadata==1.6.0
@@ -13,7 +14,7 @@ packaging==20.3
1314
pluggy==0.13.1
1415
psutil==5.7.0
1516
py==1.8.1
16-
pyparsing==2.4.6
17+
pyparsing==2.4.6f
1718
pytest==5.4.1
1819
requests==2.23.0
1920
six==1.14.0

examples/e2e/tests/test_user_consumer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
from requests.auth import HTTPBasicAuth
88

99
import pytest
10-
from pact import Consumer, Like, Provider, Term
11-
from pact.matchers import Format
10+
from pact import Consumer, Like, Provider, Term, Format
1211

1312
from ..src.consumer import UserConsumer
1413

1514
log = logging.getLogger(__name__)
1615
logging.basicConfig(level=logging.INFO)
17-
16+
print(Format().__dict__)
1817

1918
PACT_UPLOAD_URL = (
2019
"http://127.0.0.1/pacts/provider/UserService/consumer"

examples/e2e/tests/userserviceclient-userservice.json

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,6 @@
66
"name": "UserService"
77
},
88
"interactions": [
9-
{
10-
"description": "a request for UserA",
11-
"providerState": "UserA exists and is not an administrator",
12-
"request": {
13-
"method": "get",
14-
"path": "/users/UserA"
15-
},
16-
"response": {
17-
"status": 200,
18-
"headers": {
19-
},
20-
"body": {
21-
"name": "UserA",
22-
"id": "00000000-0000-4000-a000-000000000000",
23-
"created_on": "2016-12-15T20:16:01",
24-
"admin": false
25-
},
26-
"matchingRules": {
27-
"$.body": {
28-
"match": "type"
29-
},
30-
"$.body.id": {
31-
"match": "regex",
32-
"regex": "^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\\Z"
33-
},
34-
"$.body.created_on": {
35-
"match": "regex",
36-
"regex": "\\d+-\\d+-\\d+T\\d+:\\d+:\\d+"
37-
}
38-
}
39-
}
40-
},
419
{
4210
"description": "a request for UserA",
4311
"providerState": "UserA does not exist",

pact/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Python methods for interactive with a Pact Mock Service."""
22
from .consumer import Consumer
3-
from .matchers import EachLike, Like, SomethingLike, Term
3+
from .matchers import EachLike, Like, SomethingLike, Term, Format
44
from .pact import Pact
55
from .provider import Provider
66
from .__version__ import __version__ # noqa: F401
77

88
__all__ = ('Consumer', 'EachLike', 'Like', 'Pact', 'Provider', 'SomethingLike',
9-
'Term')
9+
'Term', 'Format')

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def read(filename):
117117

118118
if sys.version_info.major == 2:
119119
dependencies.append('subprocess32')
120+
dependencies.append('enum34')
120121

121122
if __name__ == '__main__':
122123
setup(

test.py

Whitespace-only changes.

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[tox]
2-
envlist=py{27}-{install}
2+
envlist=py{27,34,35,36,37,38}-{test,install}
33
[testenv]
44
deps=
55
test: -rrequirements_dev.txt
66
py27-test: subprocess32
7-
py27-install: enum34
87
commands=
98
test: nosetests
109
install: python -c "import pact"

venv27/bin/activate

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This file must be used with "source bin/activate" *from bash*
2+
# you cannot run it directly
3+
4+
5+
if [ "${BASH_SOURCE-}" = "$0" ]; then
6+
echo "You must source this script: \$ source $0" >&2
7+
exit 33
8+
fi
9+
10+
deactivate () {
11+
unset -f pydoc >/dev/null 2>&1
12+
13+
# reset old environment variables
14+
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
15+
if ! [ -z "${_OLD_VIRTUAL_PATH:+_}" ] ; then
16+
PATH="$_OLD_VIRTUAL_PATH"
17+
export PATH
18+
unset _OLD_VIRTUAL_PATH
19+
fi
20+
if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
21+
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
22+
export PYTHONHOME
23+
unset _OLD_VIRTUAL_PYTHONHOME
24+
fi
25+
26+
# This should detect bash and zsh, which have a hash command that must
27+
# be called to get it to forget past commands. Without forgetting
28+
# past commands the $PATH changes we made may not be respected
29+
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
30+
hash -r 2>/dev/null
31+
fi
32+
33+
if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
34+
PS1="$_OLD_VIRTUAL_PS1"
35+
export PS1
36+
unset _OLD_VIRTUAL_PS1
37+
fi
38+
39+
unset VIRTUAL_ENV
40+
if [ ! "${1-}" = "nondestructive" ] ; then
41+
# Self destruct!
42+
unset -f deactivate
43+
fi
44+
}
45+
46+
# unset irrelevant variables
47+
deactivate nondestructive
48+
49+
VIRTUAL_ENV="/Users/py356p/codebase/pact-python/venv27"
50+
export VIRTUAL_ENV
51+
52+
_OLD_VIRTUAL_PATH="$PATH"
53+
PATH="$VIRTUAL_ENV/bin:$PATH"
54+
export PATH
55+
56+
# unset PYTHONHOME if set
57+
if ! [ -z "${PYTHONHOME+_}" ] ; then
58+
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
59+
unset PYTHONHOME
60+
fi
61+
62+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
63+
_OLD_VIRTUAL_PS1="${PS1-}"
64+
if [ "x" != x ] ; then
65+
PS1="${PS1-}"
66+
else
67+
PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}"
68+
fi
69+
export PS1
70+
fi
71+
72+
# Make sure to unalias pydoc if it's already there
73+
alias pydoc 2>/dev/null >/dev/null && unalias pydoc || true
74+
75+
pydoc () {
76+
python -m pydoc "$@"
77+
}
78+
79+
# This should detect bash and zsh, which have a hash command that must
80+
# be called to get it to forget past commands. Without forgetting
81+
# past commands the $PATH changes we made may not be respected
82+
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
83+
hash -r 2>/dev/null
84+
fi

venv27/bin/activate.csh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This file must be used with "source bin/activate.csh" *from csh*.
2+
# You cannot run it directly.
3+
# Created by Davide Di Blasi <[email protected]>.
4+
5+
set newline='\
6+
'
7+
8+
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH:q" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT:q" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
9+
10+
# Unset irrelevant variables.
11+
deactivate nondestructive
12+
13+
setenv VIRTUAL_ENV "/Users/py356p/codebase/pact-python/venv27"
14+
15+
set _OLD_VIRTUAL_PATH="$PATH:q"
16+
setenv PATH "$VIRTUAL_ENV:q/bin:$PATH:q"
17+
18+
19+
20+
if ("" != "") then
21+
set env_name = ""
22+
else
23+
set env_name = '('"$VIRTUAL_ENV:t:q"') '
24+
endif
25+
26+
if ( $?VIRTUAL_ENV_DISABLE_PROMPT ) then
27+
if ( $VIRTUAL_ENV_DISABLE_PROMPT == "" ) then
28+
set do_prompt = "1"
29+
else
30+
set do_prompt = "0"
31+
endif
32+
else
33+
set do_prompt = "1"
34+
endif
35+
36+
if ( $do_prompt == "1" ) then
37+
# Could be in a non-interactive environment,
38+
# in which case, $prompt is undefined and we wouldn't
39+
# care about the prompt anyway.
40+
if ( $?prompt ) then
41+
set _OLD_VIRTUAL_PROMPT="$prompt:q"
42+
if ( "$prompt:q" =~ *"$newline:q"* ) then
43+
:
44+
else
45+
set prompt = "$env_name:q$prompt:q"
46+
endif
47+
endif
48+
endif
49+
50+
unset env_name
51+
unset do_prompt
52+
53+
alias pydoc python -m pydoc
54+
55+
rehash

0 commit comments

Comments
 (0)