예제 #1
0
파일: test_state.py 프로젝트: mahaase/bob
    def testPersistence(self):
        """Smoke test that tings are persisted"""
        s1 = BobState()
        s1.setInputHashes("path", b"hash")
        s1.finalize()

        s2 = BobState()
        self.assertEqual(b"hash", s2.getInputHashes("path"))
        s2.finalize()
예제 #2
0
파일: test_state.py 프로젝트: mahaase/bob
    def testCannotSave(self):
        """Failure to save state aborts"""
        os.mkdir("ro")
        os.chdir("ro")

        self.writeState()
        with self.assertRaises(BobError):
            s1 = BobState()
            os.chmod(".", stat.S_IRUSR | stat.S_IXUSR)
            s1.setInputHashes("path", b"hash")
예제 #3
0
파일: test_state.py 프로젝트: mahaase/bob
    def testUncommitted(self):
        """Uncommitted state must be picked up on next run"""
        s1 = BobState()
        s1.setInputHashes("path", b"hash")

        # simulate hard crash
        self.unlock()
        del s1

        s2 = BobState()
        self.assertEqual(b"hash", s2.getInputHashes("path"))
        s2.finalize()
예제 #4
0
파일: test_state.py 프로젝트: mahaase/bob
    def testCannotCommit(self):
        """Unability to commit state is handled gracefully"""
        os.mkdir("ro")
        os.chdir("ro")

        s1 = BobState()
        s1.setInputHashes("path", b"hash")
        os.chmod(".", stat.S_IRUSR | stat.S_IXUSR)
        s1.finalize()
        os.chmod(".", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
        self.unlock()
        os.unlink(".bob-state.pickle.new")

        s2 = BobState()
        self.assertEqual(None, s2.getInputHashes("path"))
        s2.finalize()
예제 #5
0
파일: test_state.py 프로젝트: mahaase/bob
    def testCorrupt(self):
        """A corrupted uncommitted state must be discarded"""
        s1 = BobState()
        s1.setInputHashes("path", b"hash")
        s1.finalize()

        s2 = BobState()
        s2.setInputHashes("path", b"must-be-discarded")
        # simulate hard crash and corrupt state
        self.unlock()
        del s2
        with open(".bob-state.pickle.new", "r+b") as f:
            f.write(b"garbabe")

        s3 = BobState()
        self.assertEqual(b"hash", s3.getInputHashes("path"))
        s3.finalize()