def match(self, matchee): checks = [] checks.append(matchers.IsInstance(MultiCheck)) checks.append( matchers.AfterPreprocessing(operator.attrgetter('strategy'), matchers.Is(self.strategy))) checks.append( matchers.AfterPreprocessing( operator.attrgetter('subchecks'), matchers.MatchesListwise(self.subchecks))) return matchers.MatchesAll(*checks).match(matchee)
def test_single_fail(self): """ A single incoming message with a single file path. """ sut = MetadataExtractor('exiftool', ('-some', '-arg')) error = RuntimeError('boom!') sut.peer = Mock(spec=ExiftoolProtocol) sut.peer.execute.return_value = defer.fail(error) insert = { 'inserts': ['a'], 'deletes': [], 'data': { 'a': { 'path': '/path/to/file.jpg', } } } send = Mock(spec=Scheduler.send) result = sut(insert, send) self.assertEquals(send.call_count, 0) sut.peer.execute.assert_called_once_with( b'-some', b'-arg', b'-j', b'-charset', b'exiftool=UTF-8', b'-charset', b'filename=UTF-8', b'/path/to/file.jpg') failure_matcher = matchers.AfterPreprocessing( lambda f: f.value, matchers.IsInstance(MetadataExtractorError)) assert_that(result, twistedsupport.failed(failure_matcher))
def match(self, matchee): checks = [] checks.append(matchers.IsInstance(FunctionCheck)) checks.append( matchers.Annotate( "name doesn't match", matchers.AfterPreprocessing(operator.attrgetter('name'), matchers.Equals(self.name)))) checks.append( matchers.Annotate( "info doesn't match", matchers.AfterPreprocessing(operator.attrgetter('info'), matchers.Equals(self.info)))) checks.append( matchers.Annotate( "blocking doesn't match", matchers.AfterPreprocessing(operator.attrgetter('blocking'), matchers.Equals(self.blocking)))) return matchers.MatchesAll(*checks).match(matchee)
def ContainsUUIDs(uuids): def _task_uuids(task): return sorted([r.node.uuid for r in task.resources]) return matchers.AfterPreprocessing(_task_uuids, matchers.Equals(uuids))