-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
161 additions
and
16 deletions.
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
File renamed without changes.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
include README.rst | ||
include CONTRIBUTORS.txt | ||
include CONTRIBUTORS | ||
include LICENSE |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ Code documentation | |
================== | ||
|
||
K | ||
------ | ||
- | ||
|
||
.. automodule:: kmatch | ||
.. autoclass:: kmatch.K | ||
|
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,11 @@ | ||
.. _ref-test_mixin: | ||
|
||
Test Mixin | ||
========== | ||
|
||
KmatchTestMixin | ||
--------------- | ||
|
||
.. automodule:: kmatch | ||
.. autoclass:: kmatch.KmatchTestMixin | ||
:members: |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
Release Notes | ||
============= | ||
|
||
v0.1.3 | ||
------ | ||
* Added KmatchTestMixin for tests | ||
|
||
v0.1.2 | ||
------ | ||
|
||
|
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 |
---|---|---|
|
@@ -9,5 +9,6 @@ Table of Contents | |
language_overview | ||
usage_examples | ||
ref/kmatch | ||
ref/test_mixin | ||
contributing | ||
release_notes |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# flake8: noqa | ||
from .version import __version__ | ||
from .kmatch import K | ||
from .kmatch import K | ||
from .mixins import KmatchTestMixin |
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,46 @@ | ||
from .kmatch import K | ||
|
||
|
||
class KmatchTestMixin(object): | ||
""" | ||
A mixin for test classes to perform kmatch validation on dictionaries | ||
""" | ||
def assertKmatches(self, pattern, value, suppress_key_errors=False): | ||
""" | ||
Assert that the value matches the kmatch pattern. | ||
:type pattern: list | ||
:param pattern: The kmatch pattern | ||
:type value: dict | ||
:param value: The dictionary to evaluate | ||
:type suppress_key_errors: bool | ||
:param suppress_key_errors: Suppress KeyError exceptions on filters and return False instead. False by default | ||
:raises: | ||
* :class:`KeyError <exceptions.KeyError>` if key from pattern does not exist in input value and the \ | ||
suppress_key_errors class variable is False | ||
* :class:`AssertionError <exceptions.AssertionError>` if the value **does not** match the pattern | ||
""" | ||
assert K(pattern, suppress_key_errors=suppress_key_errors).match(value) | ||
|
||
def assertNotKmatches(self, pattern, value, suppress_key_errors=True): | ||
""" | ||
Assert that the value does **not** matches the kmatch pattern. | ||
:type pattern: list | ||
:param pattern: The kmatch pattern | ||
:type value: dict | ||
:param value: The dictionary to evaluate | ||
:type suppress_key_errors: bool | ||
:param suppress_key_errors: Suppress KeyError exceptions on filters and return False instead. True by default | ||
:raises: | ||
* :class:`KeyError <exceptions.KeyError>` if key from pattern does not exist in input value and the \ | ||
suppress_key_errors class variable is False | ||
* :class:`AssertionError <exceptions.AssertionError>` if the value **does match** the pattern | ||
""" | ||
assert not K(pattern, suppress_key_errors=suppress_key_errors).match(value) |
File renamed without changes.
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,39 @@ | ||
import unittest | ||
|
||
from kmatch import KmatchTestMixin | ||
|
||
|
||
class MixinTestUsingMixin(KmatchTestMixin, unittest.TestCase): | ||
|
||
def test_matches(self): | ||
""" | ||
Test .assertMatches() using the mixin on a true match | ||
""" | ||
self.assertKmatches(['<=', 'f', 0], {'f': -1}) | ||
|
||
def test_matches_raises_error(self): | ||
""" | ||
Test .assertMatches() using the mixin on a false match | ||
""" | ||
with self.assertRaises(AssertionError): | ||
self.assertKmatches(['<=', 'f', 0], {'f': 1}) | ||
|
||
def test_not_matches(self): | ||
""" | ||
Test .assertNotMatches() using the mixin on a false match | ||
""" | ||
self.assertNotKmatches(['<=', 'f', 0], {'f': 1}) | ||
|
||
def test_not_matches_no_key_error(self): | ||
""" | ||
Test .assertNotMatches() using the mixin on a false match | ||
""" | ||
self.assertNotKmatches(['<=', 'f', 0], {'g': 1}) | ||
self.assertNotKmatches(['<=', 'f', 0], {'f': 1}) | ||
|
||
def test_not_matches_raises_error(self): | ||
""" | ||
Test .assertNotMatches() using the mixin raises an error on a match | ||
""" | ||
with self.assertRaises(AssertionError): | ||
self.assertNotKmatches(['<=', 'f', 0], {'f': -1}) |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.1.2' | ||
__version__ = '0.1.3' |
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