Skip to content

Commit

Permalink
Add Format to the standard pact package
Browse files Browse the repository at this point in the history
  • Loading branch information
pyasi committed May 15, 2020
1 parent b78ac6d commit cccd30a
Show file tree
Hide file tree
Showing 26 changed files with 518 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ self.assertEqual(result, get_generated_values(expected))
Often times, you find yourself having to re-write regular expressions for common formats.

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

```python
from pact import Like, Term
from pact import Like, Format
Like({
'id': Format().integer, # integer
'lastUpdated': Format().timestamp, # timestamp
Expand Down
3 changes: 2 additions & 1 deletion examples/e2e/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ attrs==19.3.0
certifi==2019.11.28
chardet==3.0.4
click==7.1.1
enum34==1.1.10
Flask==1.1.1
idna==2.9
importlib-metadata==1.6.0
Expand All @@ -13,7 +14,7 @@ packaging==20.3
pluggy==0.13.1
psutil==5.7.0
py==1.8.1
pyparsing==2.4.6
pyparsing==2.4.6f
pytest==5.4.1
requests==2.23.0
six==1.14.0
Expand Down
5 changes: 2 additions & 3 deletions examples/e2e/tests/test_user_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from requests.auth import HTTPBasicAuth

import pytest
from pact import Consumer, Like, Provider, Term
from pact.matchers import Format
from pact import Consumer, Like, Provider, Term, Format

from ..src.consumer import UserConsumer

log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

print(Format().__dict__)

PACT_UPLOAD_URL = (
"http://127.0.0.1/pacts/provider/UserService/consumer"
Expand Down
32 changes: 0 additions & 32 deletions examples/e2e/tests/userserviceclient-userservice.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,6 @@
"name": "UserService"
},
"interactions": [
{
"description": "a request for UserA",
"providerState": "UserA exists and is not an administrator",
"request": {
"method": "get",
"path": "/users/UserA"
},
"response": {
"status": 200,
"headers": {
},
"body": {
"name": "UserA",
"id": "00000000-0000-4000-a000-000000000000",
"created_on": "2016-12-15T20:16:01",
"admin": false
},
"matchingRules": {
"$.body": {
"match": "type"
},
"$.body.id": {
"match": "regex",
"regex": "^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\\Z"
},
"$.body.created_on": {
"match": "regex",
"regex": "\\d+-\\d+-\\d+T\\d+:\\d+:\\d+"
}
}
}
},
{
"description": "a request for UserA",
"providerState": "UserA does not exist",
Expand Down
4 changes: 2 additions & 2 deletions pact/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Python methods for interactive with a Pact Mock Service."""
from .consumer import Consumer
from .matchers import EachLike, Like, SomethingLike, Term
from .matchers import EachLike, Like, SomethingLike, Term, Format
from .pact import Pact
from .provider import Provider
from .__version__ import __version__ # noqa: F401

__all__ = ('Consumer', 'EachLike', 'Like', 'Pact', 'Provider', 'SomethingLike',
'Term')
'Term', 'Format')
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def read(filename):

if sys.version_info.major == 2:
dependencies.append('subprocess32')
dependencies.append('enum34')

if __name__ == '__main__':
setup(
Expand Down
Empty file added test.py
Empty file.
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[tox]
envlist=py{27}-{install}
envlist=py{27,34,35,36,37,38}-{test,install}
[testenv]
deps=
test: -rrequirements_dev.txt
py27-test: subprocess32
py27-install: enum34
commands=
test: nosetests
install: python -c "import pact"
84 changes: 84 additions & 0 deletions venv27/bin/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly


if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi

deactivate () {
unset -f pydoc >/dev/null 2>&1

# reset old environment variables
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
if ! [ -z "${_OLD_VIRTUAL_PATH:+_}" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi

if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
if [ ! "${1-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="/Users/py356p/codebase/pact-python/venv27"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

# unset PYTHONHOME if set
if ! [ -z "${PYTHONHOME+_}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1-}"
if [ "x" != x ] ; then
PS1="${PS1-}"
else
PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}"
fi
export PS1
fi

# Make sure to unalias pydoc if it's already there
alias pydoc 2>/dev/null >/dev/null && unalias pydoc || true

pydoc () {
python -m pydoc "$@"
}

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi
55 changes: 55 additions & 0 deletions venv27/bin/activate.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This file must be used with "source bin/activate.csh" *from csh*.
# You cannot run it directly.
# Created by Davide Di Blasi <[email protected]>.

set newline='\
'

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'

# Unset irrelevant variables.
deactivate nondestructive

setenv VIRTUAL_ENV "/Users/py356p/codebase/pact-python/venv27"

set _OLD_VIRTUAL_PATH="$PATH:q"
setenv PATH "$VIRTUAL_ENV:q/bin:$PATH:q"



if ("" != "") then
set env_name = ""
else
set env_name = '('"$VIRTUAL_ENV:t:q"') '
endif

if ( $?VIRTUAL_ENV_DISABLE_PROMPT ) then
if ( $VIRTUAL_ENV_DISABLE_PROMPT == "" ) then
set do_prompt = "1"
else
set do_prompt = "0"
endif
else
set do_prompt = "1"
endif

if ( $do_prompt == "1" ) then
# Could be in a non-interactive environment,
# in which case, $prompt is undefined and we wouldn't
# care about the prompt anyway.
if ( $?prompt ) then
set _OLD_VIRTUAL_PROMPT="$prompt:q"
if ( "$prompt:q" =~ *"$newline:q"* ) then
:
else
set prompt = "$env_name:q$prompt:q"
endif
endif
endif

unset env_name
unset do_prompt

alias pydoc python -m pydoc

rehash
102 changes: 102 additions & 0 deletions venv27/bin/activate.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This file must be used using `source bin/activate.fish` *within a running fish ( http://fishshell.com ) session*.
# Do not run it directly.

function _bashify_path -d "Converts a fish path to something bash can recognize"
set fishy_path $argv
set bashy_path $fishy_path[1]
for path_part in $fishy_path[2..-1]
set bashy_path "$bashy_path:$path_part"
end
echo $bashy_path
end

function _fishify_path -d "Converts a bash path to something fish can recognize"
echo $argv | tr ':' '\n'
end

function deactivate -d 'Exit virtualenv mode and return to the normal environment.'
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
if test (echo $FISH_VERSION | tr "." "\n")[1] -lt 3
set -gx PATH (_fishify_path $_OLD_VIRTUAL_PATH)
else
set -gx PATH $_OLD_VIRTUAL_PATH
end
set -e _OLD_VIRTUAL_PATH
end

if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
set -e _OLD_VIRTUAL_PYTHONHOME
end

if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
and functions -q _old_fish_prompt
# Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functions -e`.
set -l fish_function_path

# Erase virtualenv's `fish_prompt` and restore the original.
functions -e fish_prompt
functions -c _old_fish_prompt fish_prompt
functions -e _old_fish_prompt
set -e _OLD_FISH_PROMPT_OVERRIDE
end

set -e VIRTUAL_ENV

if test "$argv[1]" != 'nondestructive'
# Self-destruct!
functions -e pydoc
functions -e deactivate
functions -e _bashify_path
functions -e _fishify_path
end
end

# Unset irrelevant variables.
deactivate nondestructive

set -gx VIRTUAL_ENV "/Users/py356p/codebase/pact-python/venv27"

# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
if test (echo $FISH_VERSION | tr "." "\n")[1] -lt 3
set -gx _OLD_VIRTUAL_PATH (_bashify_path $PATH)
else
set -gx _OLD_VIRTUAL_PATH $PATH
end
set -gx PATH "$VIRTUAL_ENV/bin" $PATH

# Unset `$PYTHONHOME` if set.
if set -q PYTHONHOME
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
set -e PYTHONHOME
end

function pydoc
python -m pydoc $argv
end

if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
# Copy the current `fish_prompt` function as `_old_fish_prompt`.
functions -c fish_prompt _old_fish_prompt

function fish_prompt
# Save the current $status, for fish_prompts that display it.
set -l old_status $status

# Prompt override provided?
# If not, just prepend the environment name.
if test -n ""
printf '%s%s' "" (set_color normal)
else
printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV")
end

# Restore the original $status
echo "exit $old_status" | source
_old_fish_prompt
end

set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
end
Loading

0 comments on commit cccd30a

Please sign in to comment.