Esempio n. 1
0
    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()
Esempio n. 2
0
    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")
Esempio n. 3
0
    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()
Esempio n. 4
0
    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()
Esempio n. 5
0
    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()