Skip to content

Commit

Permalink
tests: avoid update check in custom GUI test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 21, 2025
1 parent e601681 commit 86e5374
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.16.9
- tests: avoid update check in custom GUI test
0.16.8
- ci: maintenance release
0.16.7
Expand Down
10 changes: 4 additions & 6 deletions dcoraid/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ def main(splash=True):
import platform
import sys

from ._version import version
from .loggers import setup_logging

logging.basicConfig(
level=logging.DEBUG if version.count("post") else logging.INFO,
format="%(asctime)s %(levelname)s %(processName)s/%(threadName)s "
+ "in %(name)s: %(message)s",
datefmt='%H:%M:%S')
setup_logging("dcoraid")
setup_logging("dclab")
setup_logging("requests", level=logging.INFO)

from PyQt5.QtWidgets import QApplication

Expand Down
11 changes: 5 additions & 6 deletions dcoraid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
from argparse import RawTextHelpFormatter
import logging
import pathlib
import sys
import threading
import time
import traceback
import sys

import urllib3.exceptions
import requests.exceptions

from .api import CKANAPI
from .loggers import setup_logging
from .upload import task
from ._version import version

Expand Down Expand Up @@ -156,11 +157,9 @@ def upload_task(path_task: str | pathlib.Path = None,


def upload_task_parser():
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(processName)s/%(threadName)s "
+ "in %(name)s: %(message)s",
datefmt='%H:%M:%S')
setup_logging("dcoraid")
setup_logging("dclab")
setup_logging("requests", level=logging.INFO)

descr = (
"Upload a .dcoraid-task file to a DCOR instance. Example usage::\n"
Expand Down
5 changes: 3 additions & 2 deletions dcoraid/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, *args, **kwargs):

#: DCOR-Aid settings
self.settings = QtCore.QSettings()
self.settings.setIniCodec("utf-8")
ref_ui = resources.files("dcoraid.gui") / "main.ui"
with resources.as_file(ref_ui) as path_ui:
uic.loadUi(path_ui, self)
Expand Down Expand Up @@ -120,7 +121,7 @@ def __init__(self, *args, **kwargs):
self.on_wizard()

# check for updates
do_update = int(self.settings.value("check for updates", 1))
do_update = int(self.settings.value("check for updates", "1"))
self.on_action_check_update(do_update)

self.show()
Expand Down Expand Up @@ -158,7 +159,7 @@ def on_action_about(self):

@QtCore.pyqtSlot(bool)
def on_action_check_update(self, b):
self.settings.setValue("check for updates", int(b))
self.settings.setValue("check for updates", f"{int(b)}")
if b and self._update_thread is None:
self._update_thread = QtCore.QThread()
self._update_worker = updater.UpdateWorker()
Expand Down
32 changes: 32 additions & 0 deletions dcoraid/loggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import logging
import os

from ._version import version


def setup_logging(module="dcoraid", level=None):
"""Setup global logging
The logging `level` can be any logging level (e.g. `logging.INFO`).
If the logging level is not set, then `INFO` is the default. If the
environment variable `CSKERNEL_DEBUG` is set or if CSKernel is
in-between releases ("post" in the version string), then `DEBUG`
is used.
"""
is_dev = version.count("post")
must_debug = os.environ.get("DCORAID_DEBUG")
if level is None:
level = logging.DEBUG if (is_dev or must_debug) else logging.INFO

formatter = logging.Formatter(
fmt="%(asctime)s %(levelname)s %(processName)s/%(threadName)s "
"in %(name)s: %(message)s",
datefmt="%H:%M:%S"
)

logger = logging.getLogger(module)
handler_stream = logging.StreamHandler()
handler_stream.setFormatter(formatter)
logger.addHandler(handler_stream)
logger.setLevel(level)
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def pytest_configure(config):
QtCore.QSettings.setDefaultFormat(QtCore.QSettings.IniFormat)
settings = QtCore.QSettings()
settings.setIniCodec("utf-8")
settings.setValue("check for updates", 0)
settings.setValue("check for updates", "0")
settings.setValue("user scenario", "dcor-dev")
settings.setValue("auth/server", "dcor-dev.mpl.mpg.de")
settings.setValue("auth/api key", common.get_api_key())
Expand All @@ -74,6 +74,7 @@ def pytest_unconfigure(config):
settings = QtCore.QSettings()
settings.setIniCodec("utf-8")
settings.remove("debug/without timers")
settings.remove("check for updates")
settings.sync()
# cleanup
cleanup_dcoraid_tasks()
Expand Down
1 change: 1 addition & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_gui_anonymous(qtbot):
spath.write_text("\n".join([
"[General]",
"user%20scenario = anonymous",
"check for updates = 0",
"[auth]",
"api%20key =",
"server = dcor.mpl.mpg.de",
Expand Down

0 comments on commit 86e5374

Please sign in to comment.