Exemple #1
0
 def testLocking(self):
     """Make sure lock is deleted after cleanup"""
     s1 = BobState()
     with self.assertRaises(BobError):
         s2 = BobState()
     s1.finalize()
     s2 = BobState()
Exemple #2
0
    def testStickyLock(self):
        """Test that we do not crash if lock file cannot be removed"""
        os.mkdir("ro")
        os.chdir("ro")

        s1 = BobState()
        os.chmod(".", stat.S_IRUSR | stat.S_IXUSR)
        s1.finalize()
Exemple #3
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")
Exemple #4
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()
Exemple #5
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()
Exemple #6
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()
Exemple #7
0
 def testVanishedLock(self):
     """Test that we do not crash if lock file vanished"""
     s1 = BobState()
     self.unlock()
     s1.finalize()
Exemple #8
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()