Beispiel #1
0
    def testAssertion(self):
        datamap = Mapping('mappingId')
        datamap.code = """
doAssert(1==1)
doAssert(1==2, "1 not equal 2")
upload.parts['record']="<somexml/>"
"""

        stream = StringIO()
        logger = StreamEventLogger(stream)
        datamap.addObserver(logger)
        try:
            datamap.createUpload(TestRepository(),
                                 oaiResponse(),
                                 doAsserts=True)
            self.fail()
        except DataMapAssertionException as ex:
            self.assertEqual(
                'ERROR\t[repository.id:oai:ident:321]\tAssertion: 1 not equal 2\n',
                stream.getvalue()[26:])
            self.assertEqual('1 not equal 2', str(ex))

        try:
            datamap.createUpload(TestRepository(),
                                 oaiResponse(),
                                 doAsserts=True)
            self.fail()
        except DataMapAssertionException as ex:
            self.assertEqual('1 not equal 2', str(ex))

        stream = StringIO()
        logger = StreamEventLogger(stream)
        datamap.createUpload(TestRepository(), oaiResponse(), doAsserts=False)
        self.assertEqual('', stream.getvalue())
 def compositLogger(self):
     stream1 = StringIO()
     stream2 = StringIO()
     log1 = StreamEventLogger(stream1)
     log2 = StreamEventLogger(stream2)
     comp = CompositeLogger([
             (['*'], log1),
             (['ERROR'], log2)
         ])
     return stream1, stream2, comp
 def testLogNone(self):
     stream = StringIO()
     logger = StreamEventLogger(stream)
     logger.logError(None)
     logger.logLine(None, None)
     lines = []
     stream.seek(0)
     for line in stream:
         lines.append(line[DATELENGTH:])
     self.assertEquals(['ERROR\t[]\tNone\n', 'None\t[]\tNone\n'],lines)
 def testTestStreamLog(self):
     stream = StringIO()
     logger = StreamEventLogger(stream)
     logger.logLine('BLA','something')
     logger.logError('this should not happen.')
     lines = []
     stream.seek(0)
     for line in stream:
         lines.append(line.strip()[DATELENGTH:])
     self.assertEquals(['BLA\t[]\tsomething','ERROR\t[]\tthis should not happen.'],lines)
Beispiel #5
0
    def testLogging(self):
        datamap = Mapping('mappingId')
        datamap.code = """
upload.parts['record']="<somexml/>"
logger.logError('Iets om te zeuren')
"""
        stream = StringIO()
        logger = StreamEventLogger(stream)
        datamap.addObserver(logger)
        datamap.createUpload(TestRepository(), oaiResponse=oaiResponse())
        self.assertEqual('ERROR\t[]\tIets om te zeuren\n',
                         stream.getvalue()[26:])
Beispiel #6
0
    def testSkip(self):
        datamap = Mapping('mappingId')
        datamap.code = """
skipRecord("Don't like it here.")
"""
        stream = StringIO()
        logger = StreamEventLogger(stream)
        datamap.addObserver(logger)
        upload = datamap.createUpload(TestRepository(), oaiResponse())
        self.assertTrue(upload.skip)
        self.assertEqual(
            "SKIP\t[repository.id:oai:ident:321]\tDon't like it here.\n",
            stream.getvalue()[26:])
 def testLogNone(self):
     stream = StringIO()
     logger = StreamEventLogger(stream)
     logger.logError(None)
     logger.logLine(None, None)
     lines = []
     stream.seek(0)
     for line in stream:
         lines.append(line[DATELENGTH:])
     self.assertEqual(['ERROR\t[]\tNone\n', 'None\t[]\tNone\n'],lines)
 def testTestStreamLog(self):
     stream = StringIO()
     logger = StreamEventLogger(stream)
     logger.logLine('BLA','something')
     logger.logError('this should not happen.')
     lines = []
     stream.seek(0)
     for line in stream:
         lines.append(line.strip()[DATELENGTH:])
     self.assertEqual(['BLA\t[]\tsomething','ERROR\t[]\tthis should not happen.'],lines)