def test_os_getpid_not_int(mocked_getpid, tmp): folder = tmp() folder.mkdir() mocked_getpid.return_value = "Boom !" lock = PidLockFile(folder, "qt") with pytest.raises(RuntimeError): lock.lock()
def test_check_running_process_creation_time_too_high(mocked_create_time, tmp): folder = tmp() folder.mkdir() lock = PidLockFile(folder, "qt") lock.lock() # Test process creation time mocked_create_time.return_value = 999_999_999_999 assert not lock.check_running()
def test_already_locked_same_process(tmp): folder = tmp() folder.mkdir() lock_file = folder / "nxdrive_qt.pid" # Save the current pid lock_file.write_text(str(os.getpid()), encoding="utf-8") lock = PidLockFile(folder, "qt") pid = lock.lock() assert pid == os.getpid() assert not lock.locked
def test_already_locked(tmp): folder = tmp() folder.mkdir() lock_file = folder / "nxdrive_qt.pid" # Inexistent pid lock_file.write_text("3857965", encoding="utf-8") lock = PidLockFile(folder, "qt") pid = lock.lock() assert pid is None assert lock.locked
def launch(self, options=None, console=False): """Launch the Qt app in the main thread and sync in another thread.""" # TODO: use the start method as default once implemented from nxdrive.utils import PidLockFile lock = PidLockFile(self.manager.get_configuration_folder(), "qt") if lock.lock() is not None: self.log.warning("Qt application already running: exiting") return app = self._get_application(options, console=console) exit_code = app.exec_() lock.unlock() self.log.debug("Qt application exited with code %r", exit_code) return exit_code
def test_bad_lock_file_content(tmp): folder = tmp() folder.mkdir() lock_file = folder / "nxdrive_qt.pid" # Craft a bad lock file lock_file.write_text("BOOM", encoding="utf-8") lock = PidLockFile(folder, "qt") pid = lock.lock() assert pid is None assert lock_file.is_file() assert lock.locked
def launch(self, options=None): """Launch the Qt app in the main thread and sync in another thread.""" # TODO: use the start method as default once implemented from nxdrive.utils import PidLockFile lock = PidLockFile(self.controller.config_folder, "qt") if lock.lock() is not None: self.log.warning("Qt application already running: exiting") return from nxdrive.gui.application import Application app = Application(self.controller, options) exit_code = app.exec_() lock.unlock() self.log.debug("Qt application exited with code %r", exit_code)
def launch(self, options=None, console=False): """Launch the Qt app in the main thread and sync in another thread.""" from nxdrive.utils import PidLockFile lock = PidLockFile(self.manager.get_configuration_folder(), "qt") if lock.lock() is not None: self.log.warning("Qt application already running: exiting") # Handle URL if needed self.manager.get_direct_edit().handle_url() return app = self._get_application(options, console=console) exit_code = app.exec_() lock.unlock() self.log.debug("Qt application exited with code %r", exit_code) return exit_code
def launch(self, options=None, console=False): """Launch the Qt app in the main thread and sync in another thread.""" from nxdrive.utils import PidLockFile lock = PidLockFile(self.manager.nxdrive_home, 'qt') if lock.lock() is not None: self.log.warning('Qt application already running: exiting') # Handle URL if needed self.manager.direct_edit.handle_url() return app = self._get_application(console=console) exit_code = app.exec_() lock.unlock() self.log.debug('Qt application exited with code %r', exit_code) return exit_code
def launch(self, options=None, console=False): """Launch the Qt app in the main thread and sync in another thread.""" from nxdrive.utils import PidLockFile lock = PidLockFile(self.manager.get_configuration_folder(), "qt") if lock.lock() is not None: self.log.warning("Qt application already running: exiting") # Handle URL if needed self.manager.get_drive_edit().handle_url() return app = self._get_application(options, console=console) exit_code = app.exec_() lock.unlock() self.log.debug("Qt application exited with code %r", exit_code) return exit_code
def test_lock_file(tmp): folder = tmp() folder.mkdir() lock_file = folder / "nxdrive_qt.pid" assert not lock_file.is_file() lock = PidLockFile(folder, "qt") assert not lock.locked pid = lock.lock() assert pid is None assert lock.locked assert lock_file.is_file() lock.unlock() assert lock.locked assert not lock_file.is_file()
def test_unlock(mocked_unlink, tmp): folder = tmp() folder.mkdir() lock_file = folder / "nxdrive_qt.pid" assert not lock_file.is_file() lock = PidLockFile(folder, "qt") # Not yet locked lock.unlock() # Now locked lock.lock() # Test file already removed mocked_unlink.side_effect = FileNotFoundError("Boom !") lock.unlock() # Test another OSerror mocked_unlink.side_effect = PermissionError("Boom !") lock.unlock()
def test_check_running(mocked_unlink, tmp): folder = tmp() folder.mkdir() lock_file = folder / "nxdrive_qt.pid" lock = PidLockFile(folder, "qt") lock.lock() # Set false PID number lock_file.write_text("999999999") # Test another OSerror mocked_unlink.side_effect = PermissionError("Boom !") assert lock.check_running() == 999_999_999 # Set PID data not int lock_file.write_text("999-999,999") assert lock.check_running() is None