~lifeless/testtools/haslength

« back to all changes in this revision

Viewing changes to testtools/tests/matchers/test_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:
19
19
    IsInstance,
20
20
    LessThan,
21
21
    GreaterThan,
 
22
    HasLength,
22
23
    MatchesRegex,
23
24
    NotEquals,
24
25
    SameMembers,
369
370
        ]
370
371
 
371
372
 
 
373
class TestHasLength(TestCase, TestMatchersInterface):
 
374
 
 
375
    matches_matcher = HasLength(2)
 
376
    matches_matches = [[1, 2]]
 
377
    matches_mismatches = [[], [1], [3, 2, 1]]
 
378
 
 
379
    str_examples = [
 
380
        ("HasLength(2)", HasLength(2)),
 
381
        ]
 
382
 
 
383
    describe_examples = [
 
384
        ("len([]) != 1", [], HasLength(1)),
 
385
        ]
 
386
 
 
387
 
372
388
def test_suite():
373
389
    from unittest import TestLoader
374
390
    return TestLoader().loadTestsFromName(__name__)