Skip to content

Commit bc01762

Browse files
committed
update test.
1 parent 7d7c42a commit bc01762

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

datajoint/external.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path, PurePosixPath, PureWindowsPath
22
from collections.abc import Mapping
33
from tqdm import tqdm
4+
import logging
45
from .settings import config
56
from .errors import DataJointError, MissingExternalFile
67
from .hash import uuid_from_buffer, uuid_from_file
@@ -10,6 +11,8 @@
1011
from . import s3
1112
from .utils import safe_write, safe_copy
1213

14+
logger = logging.getLogger(__name__.split(".")[0])
15+
1316
CACHE_SUBFOLDING = (
1417
2,
1518
2,
@@ -326,7 +329,9 @@ def _need_checksum(local_filepath):
326329
f"'{local_filepath}' downloaded but did not pass checksum'"
327330
)
328331
if not _need_checksum(local_filepath):
329-
print(f"WARNING SKIPPED CHECKSUM FOR FILE WITH HASH: {contents_hash}")
332+
logger.warning(
333+
f"WARNING SKIPPED CHECKSUM FOR FILE WITH HASH: {contents_hash}"
334+
)
330335
# This will turn into a proper logger when we implement the datajoint logger
331336
return str(local_filepath), contents_hash
332337

tests/test_filepath.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from pathlib import Path
55
import random
66
from .schema_external import schema, Filepath, FilepathS3, stores_config
7+
import logging
8+
import io
9+
10+
logger = logging.getLogger("datajoint")
711

812

913
def setUp(self):
@@ -188,7 +192,21 @@ def test_filepath_class_s3_again():
188192

189193

190194
def test_filepath_class_no_checksum():
195+
log_capture = io.StringIO()
196+
stream_handler = logging.StreamHandler(log_capture)
197+
log_format = logging.Formatter(
198+
"[%(asctime)s][%(funcName)s][%(levelname)s]: %(message)s"
199+
)
200+
stream_handler.setFormatter(log_format)
201+
stream_handler.set_name("test_limit_warning")
202+
logger.addHandler(stream_handler)
191203
test_filepath_class(verify_checksum=False)
204+
log_contents = log_capture.getvalue()
205+
log_capture.close()
206+
for handler in logger.handlers: # Clean up handler
207+
if handler.name == "test_limit_warning":
208+
logger.removeHandler(handler)
209+
assert "WARNING SKIPPED CHECKSUM FOR FILE WITH HASH" in log_contents
192210

193211

194212
def test_filepath_cleanup(table=Filepath(), store="repo"):

0 commit comments

Comments
 (0)