예제 #1
0
    def test_create_paren_dirs_fail(self, mock_logger):
        lock_file_path = Path('/root/lock/file/test.lock')
        lock_file = LockFile(lock_file_path)

        lock_file._acquire_lock()
        self.assertFalse(lock_file.has_lock())

        assert_called_once(mock_logger.error)
예제 #2
0
    def test_acquire_lock(self):
        lock_file_path = self.temp_dir / 'test.lock'

        lock_file = LockFile(lock_file_path)
        lock_file._acquire_lock()

        self.assertTrue(lock_file.has_lock())
        self.assertTrue(lock_file_path.exists())
        lock_file._release_lock()
예제 #3
0
    def test_acquire_lock(self):
        lock_file_path = self.temp_dir / "test.lock"

        lock_file = LockFile(lock_file_path)
        lock_file._acquire_lock()  # pylint: disable = protected-access

        self.assertTrue(lock_file.has_lock())
        self.assertTrue(lock_file_path.exists())
        lock_file._release_lock()  # pylint: disable = protected-access
예제 #4
0
    def test_create_paren_dirs_fail(self, mock_logger):
        lock_file_path = MagicMock(spec=Path).return_value
        parent = MagicMock(spec=PosixPath)
        lock_file_path.parent = parent
        parent.mkdir.side_effect = PermissionError

        lock_file = LockFile(lock_file_path)

        lock_file._acquire_lock()
        self.assertFalse(lock_file.has_lock())

        assert_called_once(mock_logger.error)
예제 #5
0
    def test_create_parent_dirs(self):
        lock_file_path = self.temp_dir / 'foo' / 'bar' / 'test.lock'

        lock_file = LockFile(lock_file_path)
        lock_file._acquire_lock()

        self.assertTrue(lock_file.has_lock())

        self.assertTrue(lock_file_path.exists())
        self.assertTrue(lock_file_path.parent.is_dir())
        self.assertTrue(lock_file_path.parent.parent.is_dir())

        lock_file._release_lock()
예제 #6
0
    def test_already_locked(self, mock_logger):
        lock_file_path = self.temp_dir / 'test.lock'

        lock_file_aux = LockFile(lock_file_path)
        lock_file_aux._acquire_lock()
        self.assertTrue(lock_file_aux.has_lock())

        lock_file = LockFile(lock_file_path)
        lock_file._acquire_lock()
        self.assertFalse(lock_file.has_lock())
        assert_called(mock_logger.debug)

        lock_file_aux._release_lock()
예제 #7
0
    def test_create_parent_dirs(self):
        lock_file_path = self.temp_dir / "foo" / "bar" / "test.lock"

        lock_file = LockFile(lock_file_path)
        lock_file._acquire_lock()  # pylint: disable = protected-access

        self.assertTrue(lock_file.has_lock())

        self.assertTrue(lock_file_path.exists())
        self.assertTrue(lock_file_path.parent.is_dir())
        self.assertTrue(lock_file_path.parent.parent.is_dir())

        lock_file._release_lock()  # pylint: disable = protected-access
예제 #8
0
    def test_already_locked(self, mock_logger):
        lock_file_path = self.temp_dir / "test.lock"

        lock_file_aux = LockFile(lock_file_path)
        lock_file_aux._acquire_lock()  # pylint: disable = protected-access
        self.assertTrue(lock_file_aux.has_lock())

        lock_file = LockFile(lock_file_path)
        lock_file._acquire_lock()  # pylint: disable = protected-access
        self.assertFalse(lock_file.has_lock())
        assert_called(mock_logger.debug)

        lock_file_aux._release_lock()  # pylint: disable = protected-access