1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2025-01-03 13:45:49 +00:00

Improve autostart test. By @samuel-w (#720)

This commit is contained in:
Samuel 2020-11-18 17:42:21 -06:00 committed by GitHub
parent eb0102bde9
commit 849b980ef6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,31 +1,38 @@
from PyQt5 import QtCore from PyQt5 import QtCore
from PyQt5.QtWidgets import QCheckBox from PyQt5.QtWidgets import QCheckBox
from pathlib import Path from pathlib import Path
import pytest
import os import os
import sys import sys
@pytest.mark.skipif(sys.platform != 'linux', reason="Autostart files only generated in Linux") def test_autostart(qapp, qtbot):
def test_linux_autostart(qapp, qtbot): ''' Check if file exists only on Linux, otherwise just check it doesn't crash '''
main = qapp.main_window main = qapp.main_window
main.tabWidget.setCurrentIndex(4) main.tabWidget.setCurrentIndex(4)
tab = main.miscTab tab = main.miscTab
for x in range(0, tab.checkboxLayout.count()): def click_autostart():
checkbox = tab.checkboxLayout.itemAt(x).widget() for x in range(0, tab.checkboxLayout.count()):
checkbox.__class__ = QCheckBox checkbox = tab.checkboxLayout.itemAt(x).widget()
if checkbox.text().startswith("Automatically"): checkbox.__class__ = QCheckBox
# Have to use pos to click checkbox correctly if checkbox.text().startswith("Automatically"):
# https://stackoverflow.com/questions/19418125/pysides-qtest-not-checking-box/24070484#24070484 # Have to use pos to click checkbox correctly
qtbot.mouseClick(checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2, checkbox.height() / 2)) # https://stackoverflow.com/questions/19418125/pysides-qtest-not-checking-box/24070484#24070484
break qtbot.mouseClick(checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2, checkbox.height() / 2))
break
autostart_path = Path(os.environ.get( click_autostart()
"XDG_CONFIG_HOME", os.path.expanduser("~") + '/.config') + "/autostart") / "vorta.desktop"
qtbot.waitUntil(lambda: autostart_path.exists(), timeout=5000)
with open(autostart_path) as desktop_file: if sys.platform == 'linux':
desktop_file_text = desktop_file.read() autostart_path = Path(os.environ.get(
"XDG_CONFIG_HOME", os.path.expanduser("~") + '/.config') + "/autostart") / "vorta.desktop"
qtbot.waitUntil(lambda: autostart_path.exists(), timeout=5000)
with open(autostart_path) as desktop_file:
desktop_file_text = desktop_file.read()
assert(desktop_file_text.startswith("[Desktop Entry]")) assert(desktop_file_text.startswith("[Desktop Entry]"))
click_autostart()
if sys.platform == 'linux':
assert not os.path.exists(autostart_path)