Changeset 29235
- Timestamp:
- Sep 24, 2010, 3:50:36 PM (16 years ago)
- Location:
- branches/sc_branches/psps_testing
- Files:
-
- 1 added
- 10 edited
-
build.sh (modified) (2 diffs)
-
data/psut/ko/dont_use_B00000010.tar.gz (added)
-
psi/psi_inquisitor.py (modified) (2 diffs)
-
testers/batch_file.py (modified) (4 diffs)
-
testers/batch_manifest_file.py (modified) (6 diffs)
-
testers/fits_file.py (modified) (1 diff)
-
utilities/configuration.py (modified) (2 diffs)
-
utilities/psps_logger.py (modified) (3 diffs)
-
utilities/test_product.py (modified) (2 diffs)
-
utilities/test_report.py (modified) (2 diffs)
-
utilities/util.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/sc_branches/psps_testing/build.sh
r29116 r29235 13 13 testers/batch_manifest_file.py \ 14 14 testers/fits_file.py \ 15 testers/fits/__init__.py \ 16 testers/fits/p2.py \ 15 17 utilities/__init__.py \ 16 18 utilities/configuration.py \ 17 utilities/file_manipulation.py\ 18 psi/psi_inquisitor.py" 19 utilities/file_manipulation.py \ 20 utilities/psps_logger.py \ 21 utilities/test_report.py \ 22 utilities/test_product.py \ 23 utilities/util.py \ 24 psi/__init__.py \ 25 psi/psi_inquisitor.py \ 26 psi/web01_configuration.py" 19 27 20 28 case "$1" in … … 28 36 for file in $FILES; do 29 37 echo "Coverage for $file" 30 $COVERAGE -x $file 38 $COVERAGE -x $file test -debug > /dev/null 2> /dev/null 31 39 done 32 40 echo "### Coverage results ###" -
branches/sc_branches/psps_testing/psi/psi_inquisitor.py
r29227 r29235 135 135 # position... 136 136 values = line.split(',') 137 if len(values) != len(contents['fields']): 138 # I wonder if this test is relevant. 139 # We should trust the server response at least140 # at theprotocol level...137 if len(values) != len(contents['fields']): # pragma: no cover 138 # I wonder if this test is relevant. We should 139 # trust the server response at least at the 140 # protocol level... 141 141 raise Exception("Different array length? %d vs %d" 142 142 % (len(values), len(contents['fields']))) … … 154 154 if __name__ == '__main__': 155 155 import logging 156 PsPsLogger.set_stderr() 157 PsPsLogger.setLevel(logging.DEBUG) 158 import doctest 159 doctest.testmod() 156 import sys 157 PsPsLogger.setLevel(logging.INFO) 158 PsPsLogger.set_stdout() 159 current_argument_position = 1 160 while current_argument_position < len(sys.argv): 161 if sys.argv[current_argument_position] == '-debug': # pragma: no cover 162 PsPsLogger.set_stderr() 163 current_argument_position += 1 164 elif sys.argv[current_argument_position] == 'test': 165 print 'Running unittest for PsiInquisitor class' 166 import doctest 167 doctest.testmod(exclude_empty = True) 168 sys.exit(0) -
branches/sc_branches/psps_testing/testers/batch_file.py
r29228 r29235 26 26 27 27 >>> print BatchFileTester("data/psut/ok/B00000010.tar.gz").test().success 28 True 28 False 29 >>> # Will be True one day... 29 30 """ 30 31 def __init__(self, filename): … … 51 52 Runs the different tests. Runs the dependant tests if all 52 53 tests are succesful. 54 55 >>> print BatchFileTester("data/psut/ok/B00000005.tar.gz").test().success 56 False 57 >>> print BatchFileTester("data/psut/ok/B00000005.tar.gz").test().success 58 False 53 59 """ 54 60 PsPsLogger.debug('Starting BatchFileTester object test') … … 92 98 FileManipulation.delete_directory(tempDir) 93 99 else: 94 PsPsLogger.debug('Dependant tests not run (condition on upstream tests is %s and start_dependant_tests variable is %s)' % (str( testsOk), str(start_dependant_tests)))100 PsPsLogger.debug('Dependant tests not run (condition on upstream tests is %s and start_dependant_tests variable is %s)' % (str( product.success), str(start_dependant_tests))) 95 101 return product 96 102 … … 254 260 current_argument_position = 1 255 261 while current_argument_position < len(sys.argv): 256 if sys.argv[current_argument_position] == '- v':262 if sys.argv[current_argument_position] == '-debug': # pragma: no cover 257 263 PsPsLogger.set_stderr() 258 264 current_argument_position += 1 -
branches/sc_branches/psps_testing/testers/batch_manifest_file.py
r29227 r29235 56 56 """ 57 57 Executes the various tests. 58 TODO: This method should call/be split into individual tests.59 58 60 59 >>> # Unit test: valid file … … 71 70 >>> print product.filename 72 71 00000010.FITS 73 74 # >>> print fits_info 75 # {'filetype': u'P2', 'filename': u'00000010.FITS'} 76 # >>> BatchManifestFileTester._remove_test_environment() 72 """ 73 TestReport.title('Batch manifest file tests') 74 # Check batch file existence and correct naming in archive 75 if not self._test_batch_file_exists().success: 76 return TestProduct() 77 # Check validation of XML by XSD through xmllint 78 subproduct = self._test_xml_validates() 79 if not subproduct.success: 80 return subproduct 81 xmldoc = subproduct.xmldoc 82 fileList = subproduct.fileList 83 # File existence 84 subproduct = self._test_fits_file_exists(fileList) 85 if not subproduct.success: 86 return subproduct 87 fileToLookFor = subproduct.fileToLookFor 88 fitsFilename = subproduct.fitsFilename 89 # File size match 90 if not self._test_file_size(fileList, fileToLookFor).success: 91 return TestProduct() 92 # File md5sum 93 if not self._test_md5sum(fileList, fileToLookFor).success: 94 return TestProduct() 95 # TODO: Perform some validation of the XML content that XSD can't do 96 # e.g.: minObjId < maxObjId. 97 # Note: if other objects need to be provided in the output, just add them to the dictionary... 98 # e.g.: return (..., {'filename': fitsFilename, 'fitsFilesize': fitsFilesize}) 99 # Extend test product with values useful in next tests 100 product = TestProduct(True) 101 product.filename = fitsFilename 102 product.filetype = xmldoc.getElementsByTagName('manifest')[0].attributes['type'].value 103 return product 104 105 def _test_batch_file_exists(self): 106 """ 107 Checks batch file existence and correct naming in archive 77 108 78 109 >>> # Unit test: invalid manifest file name in archive … … 86 117 False 87 118 >>> BatchManifestFileTester._remove_test_environment() 88 89 >>> # Unit test: manifest file does not validate 90 >>> basename = 'B00000006' 91 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 92 >>> # Create the temporary directory for tests 93 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 94 >>> bmft = BatchManifestFileTester(basename, '.tmp') 95 >>> product = bmft.test() 96 >>> print product.success 97 False 98 >>> BatchManifestFileTester._remove_test_environment() 99 100 >>> # Unit test: manifest file does not validate (no or incorrect FITS file name) 101 >>> basename = 'B00000007' 102 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 103 >>> # Create the temporary directory for tests 104 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 105 >>> bmft = BatchManifestFileTester(basename, '.tmp') 106 >>> print product.success 107 False 108 >>> BatchManifestFileTester._remove_test_environment() 109 110 >>> # Unit test: manifest file does not validate (incorrect size of FITS file) 111 >>> basename = 'B00000008' 112 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 113 >>> # Create the temporary directory for tests 114 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 115 >>> bmft = BatchManifestFileTester(basename, '.tmp') 116 >>> product = bmft.test() 117 >>> print product.success 118 False 119 >>> BatchManifestFileTester._remove_test_environment() 120 121 >>> # Unit test: manifest file does not validate (incorrect MD5 sum of FITS file) 122 >>> basename = 'B00000009' 123 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 124 >>> # Create the temporary directory for tests 125 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 126 >>> bmft = BatchManifestFileTester(basename, '.tmp') 127 >>> product = bmft.test() 128 >>> print product.success 129 False 130 >>> BatchManifestFileTester._remove_test_environment() 131 """ 132 TestReport.title('Batch manifest file tests') 133 # Check file existence and proper naming in archive 119 """ 134 120 requirement = 'PSDC-940-006-01, 3.5.1.2' 135 product = TestProduct()136 121 if not FileManipulation.exists(self.manifest): 137 122 TestReport.ko(requirement, 138 123 'No %s file' % (self.manifest)) 139 return product 140 else: 141 TestReport.ok(requirement) 142 # Check validation of XML by XSD through xmllint 124 return TestProduct() 125 TestReport.ok(requirement) 126 return TestProduct(True) 127 128 def _test_xml_validates(self): 129 """ 130 Checks if the XML file validates against the XSD file. 131 132 >>> # Unit test: manifest XML file does not validate against XSD 133 >>> basename = 'B00000006' 134 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 135 >>> # Create the temporary directory for tests 136 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 137 >>> bmft = BatchManifestFileTester(basename, '.tmp') 138 >>> product = bmft.test() 139 >>> print product.success 140 False 141 >>> BatchManifestFileTester._remove_test_environment() 142 """ 143 143 requirement = 'PSDC-940-006-01, 3.5.1.1' 144 144 command = '%s --schema %s --noout %s' % (Configuration.XMLLINT, … … 151 151 TestReport.ko(requirement, 152 152 'XML validation through XSD failed: command was [%s]' % (command)) 153 return product153 return TestProduct() 154 154 TestReport.ok(requirement) 155 155 # Get XML information concerning FITS file 156 156 # Note: We are only interested in the first <file> element 157 xmldoc = minidom.parse(self.manifest) 158 fileList = xmldoc.getElementsByTagName('file') 159 # File existence 157 product = TestProduct(True) 158 product.xmldoc = minidom.parse(self.manifest) 159 product.fileList = product.xmldoc.getElementsByTagName('file') 160 return product 161 162 def _test_fits_file_exists(self, xmlFileList): 163 """ 164 Checks if the FITS file named in the manifest file exists is 165 in the archive. 166 167 >>> # Unit test: manifest file does not validate (no or incorrect FITS file name) 168 >>> basename = 'B00000007' 169 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 170 >>> # Create the temporary directory for tests 171 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 172 >>> bmft = BatchManifestFileTester(basename, '.tmp') 173 >>> product = bmft.test() 174 >>> print product.success 175 False 176 >>> BatchManifestFileTester._remove_test_environment() 177 """ 160 178 requirement = 'PSDC-940-006-01, 3.5.1 (file attributes/name)' 161 fitsFilename = fileList[0].attributes['name'].value179 fitsFilename = xmlFileList[0].attributes['name'].value 162 180 fileToLookFor = self._manifest_relative_directory + '/' + fitsFilename 163 181 if not FileManipulation.exists(fileToLookFor): 164 182 TestReport.ko(requirement, 165 183 'no FITS file is named \'%s\'' % (fileToLookFor)) 166 return product 167 TestReport.ok(requirement) 168 # File size match 184 return TestProduct() 185 TestReport.ok(requirement) 186 product = TestProduct(True) 187 product.fileToLookFor = fileToLookFor 188 product.fitsFilename = fitsFilename 189 return product 190 191 def _test_file_size(self, xmlFileList, fileToLookFor): 192 """ 193 Checks if the size shown in manifest file is equal to the FITS 194 file one. 195 196 >>> # Unit test: manifest file does not validate (incorrect size of FITS file) 197 >>> basename = 'B00000008' 198 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 199 >>> # Create the temporary directory for tests 200 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 201 >>> bmft = BatchManifestFileTester(basename, '.tmp') 202 >>> product = bmft.test() 203 >>> print product.success 204 False 205 >>> BatchManifestFileTester._remove_test_environment() 206 """ 169 207 requirement = 'PSDC-940-006-01, 3.5.1 (file attributes/size)' 170 expected_size = fileList[0].attributes['bytes'].value208 expected_size = xmlFileList[0].attributes['bytes'].value 171 209 actual_size = str(FileManipulation.size(fileToLookFor)) 172 210 if actual_size != expected_size: … … 174 212 'actual size of FITS file is \'%s\' instead of \'%s\'' 175 213 % (actual_size, expected_size)) 176 return product 177 TestReport.ok(requirement) 178 # File md5sum 214 return TestProduct() 215 TestReport.ok(requirement) 216 return TestProduct(True) 217 218 def _test_md5sum(self, xmlFileList, fileToLookFor): 219 """ 220 Checks if the MD5 sum shown in manifest file is equal to the 221 computed one. 222 223 >>> # Unit test: manifest file does not validate (incorrect MD5 sum of FITS file) 224 >>> basename = 'B00000009' 225 >>> tgz_filename = 'data/psut/ko/' + basename + '.tar.gz' 226 >>> # Create the temporary directory for tests 227 >>> BatchManifestFileTester._setup_test_environment(basename, tgz_filename) 228 >>> bmft = BatchManifestFileTester(basename, '.tmp') 229 >>> product = bmft.test() 230 >>> print product.success 231 False 232 >>> BatchManifestFileTester._remove_test_environment() 233 """ 179 234 requirement = 'PSDC-940-006-01, 3.5.1 (file attributes/MD5 checksum of file)' 180 expected_md5sum = fileList[0].attributes['md5'].value235 expected_md5sum = xmlFileList[0].attributes['md5'].value 181 236 actual_md5sum = FileManipulation.md5(fileToLookFor) 182 237 if actual_md5sum != expected_md5sum: … … 184 239 'actual md5sum of FITS file is \'%s\' instead of \'%s\'' 185 240 % (actual_md5sum, expected_md5sum)) 186 return product 187 TestReport.ok(requirement) 188 # TODO: Perform some validation of the XML content that XSD can't do 189 # e.g.: minObjId < maxObjId. 190 # Note: if other objects need to be provided in the output, just add them to the dictionary... 191 # e.g.: return (..., {'filename': fitsFilename, 'fitsFilesize': fitsFilesize}) 192 # Extend test product with values useful in next tests 193 product.success = True 194 product.filename = fitsFilename 195 product.filetype = xmldoc.getElementsByTagName('manifest')[0].attributes['type'].value 196 return product 241 return TestProduct() 242 TestReport.ok(requirement) 243 return TestProduct(True) 197 244 198 245 if __name__ == '__main__': 199 246 import logging 200 247 import sys 201 PsPsLogger.setLevel(logging.DEBUG) 248 PsPsLogger.setLevel(logging.INFO) 249 PsPsLogger.set_stdout() 202 250 current_argument_position = 1 203 251 while current_argument_position < len(sys.argv): 204 if sys.argv[current_argument_position] == '-v': 252 if sys.argv[current_argument_position] == '-v': # pragma: no cover 205 253 PsPsLogger.set_stderr() 206 254 current_argument_position += 1 -
branches/sc_branches/psps_testing/testers/fits_file.py
r29227 r29235 98 98 current_argument_position = 1 99 99 while current_argument_position < len(sys.argv): 100 if sys.argv[current_argument_position] == '-v': 100 if sys.argv[current_argument_position] == '-v': # pragma: no cover 101 101 PsPsLogger.set_stderr() 102 102 current_argument_position += 1 -
branches/sc_branches/psps_testing/utilities/configuration.py
r29227 r29235 19 19 20 20 def __repr__(self): 21 """ 22 >>> print Configuration() 23 Tests Configuration Values: 24 File extension: [.tar.gz] 25 Batch manifest name: [BatchManifest.xml] 26 XSD file: [data/xsd/BatchManifest.xsd] 27 XML validation tool: [/usr/bin/xmllint] 28 Limit for test failure in a single test item: [15] 29 Tolerance for floating-point comparison: [1e-05] 30 Different types comparison [never] fails 31 >>> Configuration.BE_TYPE_TOLERANT = False 32 >>> print Configuration() 33 Tests Configuration Values: 34 File extension: [.tar.gz] 35 Batch manifest name: [BatchManifest.xml] 36 XSD file: [data/xsd/BatchManifest.xsd] 37 XML validation tool: [/usr/bin/xmllint] 38 Limit for test failure in a single test item: [15] 39 Tolerance for floating-point comparison: [1e-05] 40 Different types comparison [always] fails 41 """ 21 42 from StringIO import StringIO 22 43 representation = StringIO() … … 41 62 % tolerant) 42 63 return representation.getvalue() 64 65 ################################################################ 66 # 67 # __main__ 68 # 69 ################################################################ 70 if __name__ == '__main__': 71 import logging 72 import sys 73 # Logging 74 from utilities.psps_logger import PsPsLogger 75 PsPsLogger.setLevel(logging.DEBUG) 76 current_argument_position = 1 77 while current_argument_position < len(sys.argv): 78 if sys.argv[current_argument_position] == '-debug': # pragma: no cover 79 PsPsLogger.set_stderr() 80 current_argument_position += 1 81 elif sys.argv[current_argument_position] == 'test': 82 print 'Running unittest for Configuration class' 83 import doctest 84 doctest.testmod() 85 sys.exit(0) -
branches/sc_branches/psps_testing/utilities/psps_logger.py
r29227 r29235 14 14 15 15 class __impl(logging.Logger): 16 """ Implementation of the singleton interface"""16 """Implementation of the singleton interface""" 17 17 def __init__(self): 18 18 """Sets logging up""" … … 40 40 >>> logger1.debug('This message is not displayed') 41 41 >>> logger2 = PsPsLoggerClass() 42 >>> logger1.id() == logger2.id()42 >>> print logger1.id() == logger2.id() 43 43 True 44 44 >>> logger1.setLevel(logging.DEBUG) … … 123 123 import doctest 124 124 doctest.testmod() 125 PsPsLogger.test() 125 126 sys.exit(0) 126 127 # if sys.argv[1] == 'testfile': -
branches/sc_branches/psps_testing/utilities/test_product.py
r29227 r29235 7 7 enriched with anything useful for following tests. 8 8 """ 9 def __init__(self ):9 def __init__(self, success = False): 10 10 """ 11 11 Creates a test product and set the success status to False. … … 13 13 >>> print TestProduct().success 14 14 False 15 >>> print TestProduct(True).success 16 True 15 17 """ 16 self.success = False18 self.success = success 17 19 18 20 if __name__ == '__main__': 21 import logging 19 22 import sys 20 if len(sys.argv) == 2 and sys.argv[1]=='test': 21 print 'Running TestProduct unit tests' 22 import doctest 23 doctest.testmod() 24 sys.exit(0) 23 current_argument_position = 1 24 while current_argument_position < len(sys.argv): 25 if sys.argv[current_argument_position] == '-debug': # pragma: no cover 26 PsPsLogger.setLevel(logging.DEBUG) 27 PsPsLogger.set_stderr() 28 current_argument_position += 1 29 elif sys.argv[current_argument_position] == 'test': 30 print 'Running unittest for TestProduct class' 31 import doctest 32 doctest.testmod() 33 sys.exit(0) 25 34 -
branches/sc_branches/psps_testing/utilities/test_report.py
r29227 r29235 32 32 """ 33 33 Creates singleton instance. 34 35 >>> tr1 = TestReportClass() 36 >>> tr2 = TestReportClass() 37 >>> tr1.id() == tr2.id() 38 True 34 39 """ 35 40 # Check whether we already have an instance … … 71 76 72 77 if __name__ == '__main__': 73 if len(sys.argv)<2: 74 import doctest 75 doctest.testmod() 76 sys.exit(0) 77 TestReport.ok('Req1') 78 TestReport.ko('Req2', 'A good reason for failure') 78 import logging 79 import sys 80 current_argument_position = 1 81 while current_argument_position < len(sys.argv): 82 if sys.argv[current_argument_position] == '-debug': # pragma: no cover 83 PsPsLogger.setLevel(logging.DEBUG) 84 PsPsLogger.set_stderr() 85 current_argument_position += 1 86 elif sys.argv[current_argument_position] == 'test': 87 print 'Running unittest for TestReport class' 88 import doctest 89 doctest.testmod() 90 sys.exit(0) -
branches/sc_branches/psps_testing/utilities/util.py
r29227 r29235 21 21 True 22 22 >>> equal(a, b, 1.e-16) 23 False 24 >>> class Dummy: 25 ... def __init__(self): 26 ... pass 27 >>> dummy1 = Dummy() 28 >>> dummy2 = Dummy() 29 >>> equal(dummy1, dummy2) 23 30 False 24 31 """ … … 84 91 >>> answer2['items'][0]['sky2'] = 1792.054 85 92 >>> product = match(fits2, answer2, 'Req: ') 93 >>> print product.success 94 False 95 96 >>> fits2._fields['sky2'] = [1792.05] 97 >>> answer2['items'][0]['sky2'] = 1792.054 98 >>> product = match(fits2, answer2, 'Req: ', max_failures = -1) 86 99 >>> print product.success 87 100 False … … 179 192 ... 180 193 Exception: Type 'UnsupportedType' is not supported 194 >>> print psi_convert('Byte', 128) 195 -128 196 >>> print psi_convert('Byte', 255) 197 -1 181 198 """ 182 199 # PsPsLogger.debug('Value class: %s (%s/%s)' … … 215 232 current_argument_position = 1 216 233 while current_argument_position < len(sys.argv): 217 if sys.argv[current_argument_position] == '- v':234 if sys.argv[current_argument_position] == '-debug': #pragma: no cover 218 235 PsPsLogger.set_stderr() 219 236 current_argument_position += 1
Note:
See TracChangeset
for help on using the changeset viewer.
