Files
aqtinstall/tests/test_cli.py
Hiroshi Miura f35edf398a Fix logging in installer sub-process when multiprocessing context with spawn method (#273)
* Simplify logging

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Update logging

- keep logging file path in Settings
- introduce installer logger

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* PEP8/Black

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Logging: add queue handler

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Logging: introduce logutils module

- Add QueueListenerHandler
- Add queue listener handler config
- qualname to aqt.installer

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Logging: introduce aqt.updater logger

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Logging: introduce aqt.main and aqt.archives logger

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* PEP8/Black

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Logging: simplify config file

- use propergate for last output handler
- change formatter
  * console: brief
  * file: verbose
- Use multiprocessing.Queue() instead of queue.Queue()
- Remember logging config file customization in Settings
- QueueListener use handler as of getLogger("aqt").handlers

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* change log level of redirection

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Logging: Single global LoggingQueueListener

- Global instance of LoggingQueueListener
- Drop queue_listener from logging.ini
- Generate QueueHandler from LoggingQueueLisnter.get_queue_handler
- Explicitly close QueueListenerHandler and Queue object.

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* CI: use verbose console logging for ci

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* CLI: drop options to specify logger and logger configuration file

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Make Instance of LoggingQueueListener in Cli class

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Handle QueueListener in Cli.call_installer

- Use mp.Manager().Queue()
- start(), stop() in caller
- Gracefully close QueueHandler in installer

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* PEP8

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Drop berkeley.edu from fallbacks of mirror site

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Fix log format of time digits

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Update settings load

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* CI: catch custom settings from change in master branch

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Show log when loading custom settings

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Improve subprocess logging that use root logger

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* fix logging.ini settings

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Fix against tests

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* Introduce MyQueueListener

- Inherit System QueueListner to override logger name

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

* PEP8/Black

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
2021-06-21 15:25:00 +09:00

88 lines
2.9 KiB
Python

import aqt
def test_cli_help(capsys):
expected = "".join(
[
"usage: aqt [-h] [-c CONFIG]\n",
" {install,doc,examples,src,tool,list,help,version} ...\n",
"\n",
"Installer for Qt SDK.\n",
"\n",
"optional arguments:\n",
" -h, --help show this help message and exit\n",
" -c CONFIG, --config CONFIG\n",
" Configuration ini file.\n",
"\n",
"subcommands:\n",
" Valid subcommands\n",
"\n",
" {install,doc,examples,src,tool,list,help,version}\n",
" subcommand for aqt Qt installer\n",
]
)
cli = aqt.installer.Cli()
cli.run(["help"])
out, err = capsys.readouterr()
assert out == expected
def test_cli_check_module():
cli = aqt.installer.Cli()
cli._setup_settings()
assert cli._check_modules_arg("5.11.3", ["qtcharts", "qtwebengine"])
assert not cli._check_modules_arg("5.7", ["not_exist"])
assert cli._check_modules_arg("5.14.0", None)
assert not cli._check_modules_arg("5.15.0", ["Unknown"])
def test_cli_check_combination():
cli = aqt.installer.Cli()
cli._setup_settings()
assert cli._check_qt_arg_combination("5.11.3", "linux", "desktop", "gcc_64")
assert cli._check_qt_arg_combination("5.11.3", "mac", "desktop", "clang_64")
assert not cli._check_qt_arg_combination("5.14.0", "android", "desktop", "clang_64")
def test_cli_check_version():
cli = aqt.installer.Cli()
cli._setup_settings()
assert cli._check_qt_arg_versions("5.12.0")
assert not cli._check_qt_arg_versions("5.12")
def test_cli_check_mirror():
cli = aqt.installer.Cli()
cli._setup_settings()
assert cli._check_mirror(None)
arg = ["install", "5.11.3", "linux", "desktop", "-b", "https://download.qt.io/"]
args = cli.parser.parse_args(arg)
assert args.base == "https://download.qt.io/"
assert cli._check_mirror(args.base)
def test_cli_launch_with_no_argument(capsys):
expected = "".join(
[
"usage: aqt [-h] [-c CONFIG]\n",
" {install,doc,examples,src,tool,list,help,version} ...\n",
"\n",
"Installer for Qt SDK.\n",
"\n",
"optional arguments:\n",
" -h, --help show this help message and exit\n",
" -c CONFIG, --config CONFIG\n",
" Configuration ini file.\n",
"\n",
"subcommands:\n",
" Valid subcommands\n",
"\n",
" {install,doc,examples,src,tool,list,help,version}\n",
" subcommand for aqt Qt installer\n",
]
)
cli = aqt.installer.Cli()
cli.run([])
out, err = capsys.readouterr()
assert out == expected