示例#1
0
 def testNoRepeatedNewlines(self):
     s = State(self.tempdir, 'repository')
     s.close()
     data = open(join(self.tempdir, 'repository.stats')).read()
     self.assertEquals('', data)
     s = State(self.tempdir, 'repository')
     s._write('line')
     s.close()
     data = open(join(self.tempdir, 'repository.stats')).read()
     self.assertEquals('line\n', data)
     s = State(self.tempdir, 'repository')
     s.close()
     data = open(join(self.tempdir, 'repository.stats')).read()
     self.assertEquals('line\n', data)
示例#2
0
    def testMarkExceptionChange(self):
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("the same exception")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Error", "message": "the same exception"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))

        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("the same exception")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Error", "message": "the same exception"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))

        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 19, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("the other exception")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:19:00", "status": "Error", "message": "the other exception"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))
示例#3
0
    def testMarkHarvesterAfterExceptionChange(self):
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("whatever")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Error", "message": "whatever"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))

        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0)
        state.markStarted()
        state.markHarvested("9999/9999/9999/9999", "resumptionToken", "2012-08-13T12:14:00")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:17:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running'))))
示例#4
0
    def testMarkException(self):
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0)
        state.markStarted()
        state.markHarvested("9999/9999/9999/9999", "resumptionToken", "2012-08-13T12:14:00")
        state.close()

        self.assertEquals('Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken\n', open(join(self.tempdir, 'repo.stats')).read())
        self.assertEquals('{"from": "2012-08-13T12:14:00", "resumptionToken": "resumptionToken"}', open(join(self.tempdir, 'repo.next')).read())
        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running'))))

        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("whatever")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals("""Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken
Started: 2012-08-13 12:17:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Error: <type 'exceptions.ValueError'>: whatever
""", open(join(self.tempdir, 'repo.stats')).read())
        self.assertEquals({"changedate": "2012-08-13 12:17:00", "status": "Error", "message": "whatever"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))
示例#5
0
    def testSetToLastCleanState(self):
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0)
        state.markStarted()
        state.markHarvested("9999/9999/9999/9999", "", "2012-08-13T12:14:00")
        state.close()
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 14, 12, 17, 0, 0, 0, 0)
        state.markStarted()
        state.markHarvested("9999/9999/9999/9999", "resumptionToken", "2012-08-14T12:16:00")
        state.close()
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 15, 12, 19, 0, 0, 0, 0)
        state.setToLastCleanState()
        state.close()

        self.assertEquals("""Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: \nStarted: 2012-08-14 12:17:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-14 12:17:00, ResumptionToken: resumptionToken
Started: 2012-08-15 12:19:00, Done: Reset to last clean state. ResumptionToken: \n""", open(join(self.tempdir, 'repo.stats')).read())
        self.assertEquals('{"from": "2012-08-14T12:16:00", "resumptionToken": ""}', open(join(self.tempdir, 'repo.next')).read())
示例#6
0
    def testMarkDeleted(self):
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0)
        state.markStarted()
        state.markHarvested("9999/9999/9999/9999", "resumptionToken", "2012-08-13T12:14:00")
        state.close()

        self.assertEquals('Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken\n', open(join(self.tempdir, 'repo.stats')).read())
        self.assertEquals('{"from": "2012-08-13T12:14:00", "resumptionToken": "resumptionToken"}', open(join(self.tempdir, 'repo.next')).read())

        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running'))))

        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0)
        state.markDeleted()
        state.close()

        self.assertEquals("""Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken
Started: 2012-08-13 12:17:00, Harvested/Uploaded/Deleted/Total: 0/0/0/0, Done: Deleted all ids.
""", open(join(self.tempdir, 'repo.stats')).read())
        self.assertEquals('{"from": "", "resumptionToken": ""}', open(join(self.tempdir, 'repo.next')).read())
        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running'))))