def test_append_to_new_file(): new_file = "%s/barfile" % TMP_TEST_DIR assert not os.path.exists(new_file) append_to_file(new_file, "yolo\nswag") assert os.path.exists(new_file) assert read_file(new_file) == "yolo\nswag"
def test_append_to_new_file(tmp_path): new_file = tmp_path / "newfile.txt" append_to_file(str(new_file), "yolo\nswag") assert os.path.exists(str(new_file)) assert read_file(str(new_file)) == "yolo\nswag"
def _give_lock(action, service, p): # Depending of the action, systemctl calls the PID differently :/ if action == "start" or action == "restart": systemctl_PID_name = "MainPID" else: systemctl_PID_name = "ControlPID" cmd_get_son_PID = "systemctl show %s -p %s" % (service, systemctl_PID_name) son_PID = 0 # As long as we did not found the PID and that the command is still running while son_PID == 0 and p.poll() is None: # Call systemctl to get the PID # Output of the command is e.g. ControlPID=1234 son_PID = check_output(cmd_get_son_PID).split("=")[1] son_PID = int(son_PID) time.sleep(1) # If we found a PID if son_PID != 0: # Append the PID to the lock file logger.debug( "Giving a lock to PID %s for service %s !" % (str(son_PID), service) ) append_to_file(MOULINETTE_LOCK, "\n%s" % str(son_PID)) return son_PID
def test_append_to_existing_file(): assert os.path.exists(TMP_TEST_FILE) append_to_file(TMP_TEST_FILE, "yolo\nswag") assert read_file(TMP_TEST_FILE) == "foo\nbar\nyolo\nswag"
def test_append_to_existing_file(test_file): append_to_file(str(test_file), "yolo\nswag") assert read_file(str(test_file)) == "foo\nbar\nyolo\nswag"