~lifeless/testtools/haslength

« back to all changes in this revision

Viewing changes to testtools/matchers/_basic.py

  • Committer: Robert Collins
  • Date: 2013-01-23 20:07:43 UTC
  • Revision ID: robertc@robertcollins.net-20130123200743-0hoe8ny6nzt32liq
* New matcher ``HasLength`` for matching the length of a collection.
  (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
    'EndsWith',
6
6
    'Equals',
7
7
    'GreaterThan',
 
8
    'HasLength',
8
9
    'Is',
9
10
    'IsInstance',
10
11
    'LessThan',
24
25
    text_repr,
25
26
    )
26
27
from ..helpers import list_subtract
27
 
from ._higherorder import PostfixedMismatch
 
28
from ._higherorder import (
 
29
    MatchesPredicateWithParams,
 
30
    PostfixedMismatch,
 
31
    )
28
32
from ._impl import (
29
33
    Matcher,
30
34
    Mismatch,
313
317
            pattern = pattern.encode("unicode_escape").decode("ascii")
314
318
            return Mismatch("%r does not match /%s/" % (
315
319
                    value, pattern.replace("\\\\", "\\")))
 
320
 
 
321
 
 
322
def has_len(x, y):
 
323
    return len(x) == y
 
324
 
 
325
 
 
326
HasLength = MatchesPredicateWithParams(has_len, "len({0}) != {1}", "HasLength")