diff options
author | Michael Hudson <michael.hudson@linaro.org> | 2010-12-15 13:17:28 +1300 |
---|---|---|
committer | Michael Hudson <michael.hudson@linaro.org> | 2010-12-15 13:17:28 +1300 |
commit | f1e0a48f95e6a75ba7bc14e2c1e9d818fa752625 (patch) | |
tree | 4578f2435454c1aa5c16f7e52111c3fcf8bfdf26 /hwpack | |
parent | be1862420af2f026ece3f9052d271ed157666bca (diff) |
copy StartsWith from testtools, as that is only present in testtools 0.9.7+ and reenable test
Diffstat (limited to 'hwpack')
-rw-r--r-- | hwpack/testing.py | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/hwpack/testing.py b/hwpack/testing.py index f0508e1..c6ac697 100644 --- a/hwpack/testing.py +++ b/hwpack/testing.py @@ -606,13 +606,46 @@ def MatchesAsPackageContent(package_matcher): return AfterPreproccessing(load_from_disk, package_matcher) +class DoesNotStartWith(Mismatch): + + def __init__(self, matchee, expected): + """Create a DoesNotStartWith Mismatch. + + :param matchee: the string that did not match. + :param expected: the string that `matchee` was expected to start + with. + """ + self.matchee = matchee + self.expected = expected + + def describe(self): + return "'%s' does not start with '%s'." % ( + self.matchee, self.expected) + + +class StartsWith(Matcher): + """Checks whether one string starts with another.""" + + def __init__(self, expected): + """Create a StartsWith Matcher. + + :param expected: the string that matchees should start with. + """ + self.expected = expected + + def __str__(self): + return "Starts with '%s'." % self.expected + + def match(self, matchee): + if not matchee.startswith(self.expected): + return DoesNotStartWith(matchee, self.expected) + return None + + def MatchesPackageRelationshipList(relationship_matchers): """Matches a set of matchers against a package relationship specification. - # XXX: Disabled because this seems to require a specific version of - # testtools that includes the StartsWith matcher. - >> from testtools.matchers import Equals, StartsWith - >> MatchesPackageRelationshipList( + >>> MatchesPackageRelationshipList( ... [Equals('foo'), StartsWith('bar (')]).match('bar (= 1.0), foo') >>> """ |