11import hashlib
22import json
3+ from pathlib import Path
34
4- from dcqc .file import File
55from dcqc .tests .test_abc import ExternalTestMixin , Process , TestABC , TestStatus
66
77
@@ -11,7 +11,7 @@ class FileExtensionTest(TestABC):
1111
1212 def compute_status (self ) -> TestStatus :
1313 status = TestStatus .PASS
14- for file in self .target . files :
14+ for file in self .get_files ( staged = False ) :
1515 file_type = file .get_file_type ()
1616 file_extensions = file_type .file_extensions
1717 if not file .name .endswith (file_extensions ):
@@ -26,18 +26,17 @@ class Md5ChecksumTest(TestABC):
2626
2727 def compute_status (self ) -> TestStatus :
2828 status = TestStatus .PASS
29- for file in self .target . files :
29+ for file in self .get_files () :
3030 expected_md5 = file .get_metadata ("md5_checksum" )
31- actual_md5 = self ._compute_md5_checksum (file )
31+ actual_md5 = self ._compute_md5_checksum (file . local_path )
3232 if expected_md5 != actual_md5 :
3333 status = TestStatus .FAIL
3434 break
3535 return status
3636
37- def _compute_md5_checksum (self , file : File ) -> str :
38- local_path = file .local_path
37+ def _compute_md5_checksum (self , path : Path ) -> str :
3938 hash_md5 = hashlib .md5 ()
40- with local_path .open ("rb" ) as infile :
39+ with path .open ("rb" ) as infile :
4140 for chunk in iter (lambda : infile .read (4096 ), b"" ):
4241 hash_md5 .update (chunk )
4342 actual_md5 = hash_md5 .hexdigest ()
@@ -50,16 +49,15 @@ class JsonLoadTest(TestABC):
5049
5150 def compute_status (self ) -> TestStatus :
5251 status = TestStatus .PASS
53- for file in self .target . files :
54- if not self ._can_be_loaded (file ):
52+ for file in self .get_files () :
53+ if not self ._can_be_loaded (file . local_path ):
5554 status = TestStatus .FAIL
5655 break
5756 return status
5857
59- def _can_be_loaded (self , file : File ) -> bool :
58+ def _can_be_loaded (self , path : Path ) -> bool :
6059 success = True
61- local_path = file .local_path
62- with local_path .open ("r" ) as infile :
60+ with path .open ("r" ) as infile :
6361 try :
6462 json .load (infile )
6563 except Exception :
@@ -73,19 +71,18 @@ class JsonLdLoadTest(TestABC):
7371
7472 def compute_status (self ) -> TestStatus :
7573 status = TestStatus .PASS
76- for file in self .target . files :
77- if not self ._can_be_loaded (file ):
74+ for file in self .get_files () :
75+ if not self ._can_be_loaded (file . local_path ):
7876 status = TestStatus .FAIL
7977 break
8078 return status
8179
82- def _can_be_loaded (self , file : File ) -> bool :
80+ def _can_be_loaded (self , path : Path ) -> bool :
8381 rdflib = self .import_module ("rdflib" )
8482 graph = rdflib .Graph ()
8583
8684 success = True
87- local_path = file .local_path
88- with local_path .open ("r" ) as infile :
85+ with path .open ("r" ) as infile :
8986 try :
9087 graph .parse (infile , format = "json-ld" )
9188 except Exception :
@@ -97,9 +94,8 @@ class LibTiffInfoTest(ExternalTestMixin, TestABC):
9794 tier = 2
9895
9996 def generate_process (self ) -> Process :
100- file = self ._get_single_target_file ()
101- path = file .local_path .as_posix ()
102- command_args = ["tiffinfo" , path ]
97+ file = self .get_file ()
98+ command_args = ["tiffinfo" , file .local_path .as_posix ()]
10399 process = Process (
104100 container = "quay.io/sagebionetworks/libtiff:2.0" ,
105101 command_args = command_args ,
@@ -111,14 +107,13 @@ class BioFormatsInfoTest(ExternalTestMixin, TestABC):
111107 tier = 2
112108
113109 def generate_process (self ) -> Process :
114- file = self ._get_single_target_file ()
115- path = file .local_path .as_posix ()
110+ file = self .get_file ()
116111 command_args = [
117112 "/opt/bftools/showinf" ,
118113 "-nopix" ,
119114 "-novalid" ,
120115 "-nocore" ,
121- path ,
116+ file . local_path . as_posix () ,
122117 ]
123118 process = Process (
124119 container = "quay.io/sagebionetworks/bftools:latest" ,
@@ -131,11 +126,10 @@ class OmeXmlSchemaTest(ExternalTestMixin, TestABC):
131126 tier = 2
132127
133128 def generate_process (self ) -> Process :
134- file = self ._get_single_target_file ()
135- path = file .local_path .as_posix ()
129+ file = self .get_file ()
136130 command_args = [
137131 "/opt/bftools/xmlvalid" ,
138- path ,
132+ file . local_path . as_posix () ,
139133 ]
140134 process = Process (
141135 container = "quay.io/sagebionetworks/bftools:latest" ,
0 commit comments