-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/ffi provider #245
Closed
Closed
Feat/ffi provider #245
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
34f67a7
feat: added rust linux/osx support
elliottmurray afd0931
feat: fix to pytest request signature@
elliottmurray 6c95248
feat: first ffi interface
elliottmurray de93a1f
feat: added so file
elliottmurray be6c971
fix: so now a relative path so picked up by tests (temp fix) Also som…
elliottmurray 4b239e4
chore: move dyn libs to libs folder@
elliottmurray e7d686a
feat: some work on preparing verify call
elliottmurray 050ee0e
feat: refactoring to prepare verify
elliottmurray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ __pycache__/ | |
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
# *.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Wrapper to pact reference dynamic libraries using FFI.""" | ||
from pact.pact_exception import PactException | ||
from cffi import FFI | ||
import platform | ||
|
||
|
||
class FFIVerify(object): | ||
"""A Pact Verifier Wrapper.""" | ||
|
||
def version(self): | ||
"""Publish version info.""" | ||
ffi = FFI() | ||
ffi.cdef(""" | ||
char *pactffi_version(void); | ||
""") | ||
lib = self._load_ffi_library(ffi) | ||
result = lib.pactffi_version() | ||
return ffi.string(result).decode('utf-8') | ||
|
||
def verify(self, *pacts, provider_base_url, provider, enable_pending=False, | ||
include_wip_pacts_since=None, **kwargs): | ||
"""Call verify method.""" | ||
self._validate_input(pacts, **kwargs) | ||
|
||
ffi = FFI() | ||
ffi.cdef(""" | ||
char *pactffi_verify(void); | ||
""") | ||
lib = self._load_ffi_library(ffi) | ||
result = lib.pactffi_version() | ||
return ffi.string(result).decode('utf-8') | ||
|
||
def _load_ffi_library(self, ffi): | ||
"""Load the right library.""" | ||
target_platform = platform.platform().lower() | ||
|
||
if 'darwin' in target_platform or 'macos' in target_platform: | ||
libname = "libs/libpact_ffi-osx-x86_64.dylib" | ||
elif 'linux' in target_platform: | ||
libname = "libs/libpact_ffi-linux-x86_64.so" | ||
elif 'windows' in target_platform: | ||
libname = "libs/libpact_ffi-osx-x86_64.dylib" | ||
else: | ||
msg = ('Unfortunately, {} is not a supported platform. Only Linux,' | ||
' Windows, and OSX are currently supported.').format( | ||
platform.platform()) | ||
raise Exception(msg) | ||
|
||
return ffi.dlopen(libname) | ||
|
||
def _validate_input(self, pacts, **kwargs): | ||
if len(pacts) == 0 and not self._broker_present(**kwargs): | ||
raise PactException('Pact urls or Pact broker required') | ||
|
||
def _broker_present(self, **kwargs): | ||
if kwargs.get('broker_url') is None: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Custom Pact Exception.""" | ||
|
||
class PactException(Exception): | ||
"""PactException when input isn't valid. | ||
|
||
Args: | ||
Exception ([type]): [description] | ||
|
||
Raises: | ||
KeyError: [description] | ||
Exception: [description] | ||
|
||
Returns: | ||
[type]: [description] | ||
|
||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Create wrapper.""" | ||
super().__init__(*args, **kwargs) | ||
self.message = args[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are using the DLL, you don't need the static lib (.lib). But there is no harm in downloading it, apart from it being the biggest one.