File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 1
1
from pathlib import Path , PurePosixPath , PureWindowsPath
2
2
from collections .abc import Mapping
3
3
from tqdm import tqdm
4
+ import logging
4
5
from .settings import config
5
6
from .errors import DataJointError , MissingExternalFile
6
7
from .hash import uuid_from_buffer , uuid_from_file
10
11
from . import s3
11
12
from .utils import safe_write , safe_copy
12
13
14
+ logger = logging .getLogger (__name__ .split ("." )[0 ])
15
+
13
16
CACHE_SUBFOLDING = (
14
17
2 ,
15
18
2 ,
@@ -326,7 +329,9 @@ def _need_checksum(local_filepath):
326
329
f"'{ local_filepath } ' downloaded but did not pass checksum'"
327
330
)
328
331
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
+ )
330
335
# This will turn into a proper logger when we implement the datajoint logger
331
336
return str (local_filepath ), contents_hash
332
337
Original file line number Diff line number Diff line change 4
4
from pathlib import Path
5
5
import random
6
6
from .schema_external import schema , Filepath , FilepathS3 , stores_config
7
+ import logging
8
+ import io
9
+
10
+ logger = logging .getLogger ("datajoint" )
7
11
8
12
9
13
def setUp (self ):
@@ -188,7 +192,21 @@ def test_filepath_class_s3_again():
188
192
189
193
190
194
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 )
191
203
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
192
210
193
211
194
212
def test_filepath_cleanup (table = Filepath (), store = "repo" ):
You can’t perform that action at this time.
0 commit comments