~jml/treeshape/matchers

« back to all changes in this revision

Viewing changes to treeshape/_matchers.py

  • Committer: Jonathan Lange
  • Date: 2012-08-07 15:48:38 UTC
  • Revision ID: jml@canonical.com-20120807154838-ftk8dhaqdmga6vrx
Docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 
64
64
 
65
65
class HasFileTree(Matcher):
 
66
    """Match a directory on disk against a file tree shape.
 
67
 
 
68
    The specified shape contains everything that is allowed to exist in the
 
69
    matched directory.  Parent directories that are implied by actual entries
 
70
    (e.g. 'foo/bar/' implies that 'foo/' exists) will be automatically added.
 
71
 
 
72
    Attributes can be matched using testtools matchers, e.g.::
 
73
 
 
74
      {'foo': {CONTENTS: Contains("Hello")}}
 
75
 
 
76
    Or will be simply checked for equality if they aren't matchers.  Thus::
 
77
 
 
78
      {'foo': {CONTENTS: Equals("Hello")}}
 
79
 
 
80
    is equivalent to::
 
81
 
 
82
      {'foo': {CONTENTS: "Hello"}}
 
83
 
 
84
    ``from_rough_spec`` also works with matchers, so you could call
 
85
    ``HasFileTree`` like this, if you want::
 
86
 
 
87
        HasFileTree(from_rough_spec([('foo', Contains("Hello")), 'bar/']))
 
88
 
 
89
    If the disk contains any files or directories that aren't specified in the
 
90
    matcher and aren't implied directories, then it will mismatch.  Likewise,
 
91
    if there are entries in the matcher spec that don't exist on disk, it will
 
92
    mismatch.
 
93
    """
66
94
 
67
95
    def __init__(self, shape):
68
96
        super(HasFileTree, self).__init__()