Skip to content

Commit 79a36cf

Browse files
committed
Fix test problems
1 parent bdcc4a0 commit 79a36cf

File tree

4 files changed

+43
-42
lines changed

4 files changed

+43
-42
lines changed

src/ghga_connector/cli.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616
"""CLI-specific wrappers around core functions."""
1717

1818
import asyncio
19-
import logging
2019
import os
21-
import sys
22-
from functools import partial
2320
from pathlib import Path
24-
from types import TracebackType
2521

2622
import typer
2723

@@ -30,39 +26,7 @@
3026
from ghga_connector.constants import C4GH
3127
from ghga_connector.core import CLIMessageDisplay, async_client
3228
from ghga_connector.core.main import async_download, decrypt_file, upload_file
33-
34-
35-
def strtobool(value: str) -> bool:
36-
"""Inplace replacement for distutils.utils"""
37-
return value.lower() in ("y", "yes", "on", "1", "true", "t")
38-
39-
40-
def exception_hook(
41-
type_: BaseException,
42-
value: BaseException,
43-
traceback: TracebackType | None,
44-
):
45-
"""When debug mode is NOT enabled, gets called to perform final error handling
46-
before program exits
47-
"""
48-
message = (
49-
"An error occurred. Rerun command"
50-
+ " with --debug at the end to see more information."
51-
)
52-
53-
if value.args:
54-
message += f"\n{value.args[0]}"
55-
56-
CLIMessageDisplay.failure(message)
57-
58-
59-
def modify_for_debug(debug: bool):
60-
"""Enable debug logging and configure exception printing if debug=True"""
61-
if debug:
62-
# enable debug logging
63-
logging.basicConfig(level=logging.DEBUG)
64-
sys.excepthook = partial(exception_hook)
65-
29+
from ghga_connector.core.utils import modify_for_debug, strtobool
6630

6731
cli = typer.Typer(no_args_is_help=True)
6832

src/ghga_connector/core/downloading/batch_processing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,4 @@ async def manage_file_downloads(self, overwrite: bool) -> AsyncGenerator[FileInf
220220
CLIMessageDisplay.success(
221221
f"File with id '{file_info.file_id}' has been successfully downloaded."
222222
)
223+
staged_files.clear()

src/ghga_connector/core/utils.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,53 @@
1515

1616
"""Various helper functions"""
1717

18+
import logging
19+
import sys
20+
from functools import partial
1821
from pathlib import Path
22+
from types import TracebackType
1923

2024
import crypt4gh.keys
2125
from ghga_service_commons.utils import crypt
2226

2327
from ghga_connector import exceptions
24-
from ghga_connector.core.downloading.batch_processing import FileInfo
28+
from ghga_connector.core.downloading.structs import FileInfo
2529
from ghga_connector.core.message_display import CLIMessageDisplay
2630
from ghga_connector.core.structs import WorkPackageInformation
2731

2832

33+
def strtobool(value: str) -> bool:
34+
"""Inplace replacement for distutils.utils"""
35+
return value.lower() in ("y", "yes", "on", "1", "true", "t")
36+
37+
38+
def exception_hook(
39+
type_: BaseException,
40+
value: BaseException,
41+
traceback: TracebackType | None,
42+
):
43+
"""When debug mode is NOT enabled, gets called to perform final error handling
44+
before program exits
45+
"""
46+
message = (
47+
"An error occurred. Rerun command"
48+
+ " with --debug at the end to see more information."
49+
)
50+
51+
if value.args:
52+
message += f"\n{value.args[0]}"
53+
54+
CLIMessageDisplay.failure(message)
55+
56+
57+
def modify_for_debug(debug: bool):
58+
"""Enable debug logging and configure exception printing if debug=True"""
59+
if debug:
60+
# enable debug logging
61+
logging.basicConfig(level=logging.DEBUG)
62+
sys.excepthook = partial(exception_hook)
63+
64+
2965
def get_work_package_information(my_private_key: bytes):
3066
"""Fetch a work package id and work package token and decrypt the token"""
3167
# get work package access token and id from user input

tests/integration/test_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
from pytest_httpx import HTTPXMock, httpx_mock # noqa: F401
3333

3434
from ghga_connector import exceptions
35-
from ghga_connector.cli import async_download, modify_for_debug
3635
from ghga_connector.config import set_runtime_config
3736
from ghga_connector.constants import C4GH, DEFAULT_PART_SIZE
3837
from ghga_connector.core.client import async_client
3938
from ghga_connector.core.crypt import Crypt4GHEncryptor
40-
from ghga_connector.core.main import upload_file
39+
from ghga_connector.core.main import async_download, upload_file
40+
from ghga_connector.core.utils import modify_for_debug
4141
from tests.fixtures import state
4242
from tests.fixtures.config import get_test_config
4343
from tests.fixtures.mock_api.app import (
@@ -94,7 +94,7 @@ def apply_test_config():
9494
"""Apply default test config"""
9595
with (
9696
patch("ghga_connector.config.CONFIG", get_test_config()),
97-
patch("ghga_connector.cli.CONFIG", get_test_config()),
97+
patch("ghga_connector.core.main.CONFIG", get_test_config()),
9898
):
9999
yield
100100

@@ -103,7 +103,7 @@ def apply_test_config():
103103
def apply_common_download_mocks(monkeypatch):
104104
"""Monkeypatch download-specific functions and values"""
105105
monkeypatch.setattr(
106-
"ghga_connector.cli.get_work_package_token", mock_work_package_token
106+
"ghga_connector.core.utils.get_work_package_token", mock_work_package_token
107107
)
108108
monkeypatch.setattr(
109109
"ghga_connector.core.work_package._decrypt",

0 commit comments

Comments
 (0)