-
-
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
1 parent
a1c9970
commit 81c0fb2
Showing
5 changed files
with
156 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from itertools import islice | ||
|
||
|
||
def window(seq, n): | ||
"Returns a sliding window (of width n) over data from the iterable" | ||
" s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ... " | ||
it = iter(seq) | ||
result = tuple(islice(it, n)) | ||
if len(result) <= n: | ||
yield result | ||
for elem in it: | ||
result = result[1:] + (elem,) | ||
yield result |
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,111 @@ | ||
from nose.tools import istest, assert_equal | ||
|
||
from precisely import is_sequence_with, equal_to | ||
from precisely.results import matched, unmatched | ||
|
||
|
||
@istest | ||
def matches_when_all_submatchers_match_one_item_with_no_items_leftover(): | ||
matcher = is_sequence_with(equal_to("apple"), equal_to("banana")) | ||
|
||
assert_equal(matched(), matcher.match(["apple", "banana"])) | ||
|
||
|
||
@istest | ||
def mismatches_when_actual_is_not_iterable(): | ||
matcher = is_sequence_with(equal_to("apple")) | ||
|
||
assert_equal( | ||
unmatched("was not iterable\nwas 0"), | ||
matcher.match(0) | ||
) | ||
|
||
|
||
@istest | ||
def mismatches_when_items_are_in_wrong_order(): | ||
matcher = is_sequence_with(equal_to("apple"), equal_to("banana")) | ||
|
||
assert_equal( | ||
unmatched("element at index 0 mismatched:\n * was 'banana'"), | ||
matcher.match(["banana", "apple"]) | ||
) | ||
|
||
|
||
@istest | ||
def mismatches_when_item_is_missing(): | ||
matcher = is_sequence_with(equal_to("apple"), equal_to("banana"), equal_to("coconut")) | ||
|
||
assert_equal( | ||
unmatched("element at index 2 was missing"), | ||
matcher.match(["apple", "banana"]) | ||
) | ||
|
||
|
||
@istest | ||
def mismatches_when_item_is_expected_but_iterable_is_empty(): | ||
matcher = is_sequence_with(equal_to("apple")) | ||
|
||
assert_equal( | ||
unmatched("iterable was empty"), | ||
matcher.match([]) | ||
) | ||
|
||
|
||
@istest | ||
def when_empty_iterable_is_expected_then_empty_iterable_matches(): | ||
matcher = is_sequence_with() | ||
|
||
assert_equal( | ||
matched(), | ||
matcher.match([]) | ||
) | ||
|
||
|
||
@istest | ||
def matches_when_contains_extra_item_after(): | ||
matcher = is_sequence_with(equal_to("apple"), equal_to("pear")) | ||
|
||
assert_equal( | ||
matched(), | ||
matcher.match(["apple", "pear", "coconut"]) | ||
) | ||
|
||
|
||
@istest | ||
def matches_when_contains_extra_item_before(): | ||
matcher = is_sequence_with(equal_to("apple"), equal_to("pear")) | ||
|
||
assert_equal( | ||
matched(), | ||
matcher.match(["coconut", "apple", "pear"]) | ||
) | ||
|
||
|
||
@istest | ||
def when_there_are_zero_submatchers_then_description_is_of_empty_iterable(): | ||
matcher = is_sequence_with() | ||
|
||
assert_equal( | ||
"empty iterable", | ||
matcher.describe() | ||
) | ||
|
||
|
||
@istest | ||
def description_contains_descriptions_of_submatchers(): | ||
matcher = is_sequence_with(equal_to("apple"), equal_to("banana")) | ||
|
||
assert_equal( | ||
"iterable containing in order:\n 0: 'apple'\n 1: 'banana'", | ||
matcher.describe() | ||
) | ||
|
||
|
||
@istest | ||
def elements_are_coerced_to_matchers(): | ||
matcher = is_sequence_with("apple", "banana") | ||
|
||
assert_equal( | ||
"iterable containing in order:\n 0: 'apple'\n 1: 'banana'", | ||
matcher.describe() | ||
) |