コード例 #1
0
 def test_open_remove(self):
     '''Lockfile create and destroy'''
     l = LockFile(self.locktmp)
     self.assertIsNotNone(l, "Object created")
     self.assertTrue(os.path.isfile(self.locktmp), "Lockfile created")
     l.remove()
     self.assertFalse(os.path.isfile(self.locktmp), "Lockfile removed")
コード例 #2
0
 def test_open_remove(self):
     '''Lockfile create and destroy'''
     l = LockFile(self.locktmp)
     self.assertIsNotNone(l, "Object created")
     self.assertTrue(os.path.isfile(self.locktmp), "Lockfile created")
     l.remove()
     self.assertFalse(os.path.isfile(self.locktmp), "Lockfile removed")
コード例 #3
0
    def test_open_multi(self):
        '''Lockfile multi-open failure'''
        l1 = LockFile(self.locktmp)
        self.assertIsNotNone(l1, "Object created")
        self.assertTrue(os.path.isfile(self.locktmp), "Lockfile created")
        with self.assertRaises(OSError):
            LockFile(self.locktmp)

        l1.remove()
        self.assertFalse(os.path.isfile(self.locktmp), "Lockfile removed")
コード例 #4
0
    def test_open_multi(self):
        '''Lockfile multi-open failure'''
        l1 = LockFile(self.locktmp)
        self.assertIsNotNone(l1, "Object created")
        self.assertTrue(os.path.isfile(self.locktmp), "Lockfile created")
        with self.assertRaises(OSError):
            LockFile(self.locktmp)

        l1.remove()
        self.assertFalse(os.path.isfile(self.locktmp), "Lockfile removed")
コード例 #5
0
 def test_open_destructor(self):
     '''Lockfile auto-destroy'''
     l = LockFile(self.locktmp)
     self.assertIsNotNone(l, "Object created")
     self.assertTrue(os.path.isfile(self.locktmp), "Lockfile created")
     l = None
     self.assertFalse(os.path.isfile(self.locktmp), "Lockfile removed")
コード例 #6
0
    def test_lockfile_detect_corrupt_pid(self):
        '''Notice when the lockfile PID is bogus.'''

        self._create_bogus_lockfile(self.locktmp, lockself=True, badpid=True)

        with self.assertRaises(Exception):
            LockFile(self.locktmp)
コード例 #7
0
    def test_lockfile_alive_nobreak(self):
        '''Don't break the lockfile when we're the process holding it'''

        self._create_bogus_lockfile(self.locktmp, lockself=True)

        # This should fail - it's this process' lockfile.
        with self.assertRaises(OSError):
            LockFile(self.locktmp, break_dead_lockfile=True)
コード例 #8
0
    def test_lockfile_detect_corrupt_lockfile_length(self):
        '''Notice when the lockfile isn't two lines long'''

        self._create_bogus_lockfile(self.locktmp,
                                    lockself=True,
                                    shortfile=True)

        with self.assertRaises(Exception):
            LockFile(self.locktmp)
コード例 #9
0
    def test_lockfile_dead_nobreak(self):
        '''When instructed, don't remove dead process lockfile'''

        self._create_bogus_lockfile(self.locktmp)

        # This should raise, as we've told it not to remove the lockfile
        # when normally it would be removed.
        with self.assertRaises(OSError):
            LockFile(self.locktmp, break_dead_lockfile=False)
コード例 #10
0
    def test_lock_in_non_dir(self):
        '''Shouldn't try to create a lockfile under a non-directory'''
        regfilename = os.path.join(self.topdir, 'not_a_directory')
        regfile_subdir_lock = os.path.join(regfilename, 'bad')
        regfile = open(regfilename, 'w')
        print("hello", file=regfile)
        regfile.close()
        self.assertTrue(os.path.isfile(regfilename), 'Regular file created')
        with self.assertRaises(NotADirectoryError):
            LockFile(regfile_subdir_lock)

        os.unlink(regfilename)