def testExpectedWarnings(self):
     msg = ''
     # compare test files (.input and .expected for each)
     # N.B. in some cases, python 2 and python 3 will have different output!
     for fn in pathmap.all_files(os.path.join('collections', 'warn_err')):
         if fn.endswith('.input'):
             frag = fn[:-len('.input')]
             efn = frag + '.expected'
             # check for a python version-specific file, like 'foo.expected-py3'
             current_python_version = (sys.version_info > (3, 0)) and 'py3' or 'py2'
             versioned_efn = '{f}-{v}'.format(f=efn, v=current_python_version)
             if os.path.exists(versioned_efn):
                 efn = versioned_efn
             if os.path.exists(efn):
                 inp = testing_read_json(fn)
                 aa = validate_collection(inp)
                 errors = aa[0]
                 exp = testing_read_json(efn)
                 if errors != exp:
                     ofn = frag + '.output'
                     testing_write_json(errors, ofn)
                     msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format(o=ofn, e=efn)
                 self.assertEqual(exp, errors, msg)
             else:
                 _LOG.warn('Expected output file "{f}" not found'.format(f=efn))
 def testExpectedWarnings(self):
     msg = ''
     # compare test files (.input and .expected for each)
     # TODO: Add these files for amendments!
     # N.B. in some cases, python 2 and python 3 will have different output!
     for fn in pathmap.all_files(os.path.join('amendments', 'warn_err')):
         if fn.endswith('.input'):
             frag = fn[:-len('.input')]
             efn = frag + '.expected'
             # check for a python version-specific file, like 'foo.expected-py3'
             current_python_version = (sys.version_info > (3, 0)) and 'py3' or 'py2'
             versioned_efn = '{f}-{v}'.format(f=efn, v=current_python_version)
             if os.path.exists(versioned_efn):
                 efn = versioned_efn
             if os.path.exists(efn):
                 inp = testing_read_json(fn)
                 aa = validate_amendment(inp)
                 errors = aa[0]
                 exp = testing_read_json(efn)
                 if errors != exp:
                     ofn = frag + '.output'
                     testing_write_json(errors, ofn)
                     msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format(o=ofn, e=efn)
                 self.assertEqual(exp, errors, msg)
             else:
                 _LOG.warn('Expected output file "{f}" not found'.format(f=efn))
 def testInvalidFilesFail(self):
     # just one test file for now
     msg = ''
     frag = 'amendment-incomplete.json'
     inp = pathmap.amendment_obj(frag)
     aa = validate_amendment(inp)
     if len(aa) > 0:
         errors = aa[0]
         if len(errors) == 0:
             ofn = pathmap.amendment_source_path(frag + '.output')
             testing_write_json(errors, ofn)
             msg = "Failed to reject invalid file (no errors found)"
             self.assertTrue(False, msg)
 def testValidFilesPass(self):
     # just one test file for now
     msg = ''
     frag = 'collection-good.json'
     collection = pathmap.collection_obj(frag)
     aa = validate_collection(collection)
     errors = aa[0]
     for e in errors:
         _LOG.debug('unexpected error from {f}: {m}'.format(f=frag, m=UNICODE(e)))
     if len(errors) > 0:
         ofn = pathmap.collection_source_path(frag + '.output')
         testing_write_json(errors, ofn)
         msg = "File failed to validate cleanly. See {o}".format(o=ofn)
     self.assertEqual(len(errors), 0, msg)
 def testValidFilesPass(self):
     # just one test file for now
     msg = ''
     frag = 'amendment-good.json'
     amendment = pathmap.amendment_obj(frag)
     aa = validate_amendment(amendment)
     errors = aa[0]
     for e in errors:
         _LOG.debug('unexpected error from {f}: {m}'.format(f=frag, m=UNICODE(e)))
     if len(errors) > 0:
         ofn = pathmap.amendment_source_path(frag + '.output')
         testing_write_json(errors, ofn)
         msg = "File failed to validate cleanly. See {o}".format(o=ofn)
     self.assertEqual(len(errors), 0, msg)
 def testInvalidFilesFail(self):
     msg = ''
     for fn in pathmap.all_files(os.path.join('nexson', 'lacking_otus')):
         if fn.endswith('.input'):
             frag = fn[:-len('.input')]
             inp = testing_read_json(fn)
             aa = validate_nexson(inp)
             annot = aa[0]
             if len(annot.errors) == 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 testing_write_json(ew_dict, ofn)
                 msg = "Failed to reject file. See {o}".format(o=str(msg))
                 self.assertTrue(False, msg)
 def testInvalidFilesFail(self):
     msg = ''
     for fn in pathmap.all_files(os.path.join('nexson', 'lacking_otus')):
         if fn.endswith('.input'):
             frag = fn[:-len('.input')]
             inp = testing_read_json(fn)
             aa = validate_nexson(inp)
             annot = aa[0]
             if len(annot.errors) == 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 testing_write_json(ew_dict, ofn)
                 msg = "Failed to reject file. See {o}".format(o=str(msg))
                 self.assertTrue(False, msg)
 def testInvalidDOIsFail(self):
     # all DOIs should be in URL form
     msg = ''
     frag = 'amendment-bad-dois.json'
     inp = pathmap.amendment_obj(frag)
     aa = validate_amendment(inp)
     if len(aa) > 0:
         errors = aa[0]
         ofn = pathmap.amendment_source_path(frag + '.output')
         testing_write_json(errors, ofn)
         if len(errors) == 0:
             msg = "Failed to reject bare DOI (no errors found)"
             self.assertTrue(False, msg)
         else:
             self.assertTrue('should be a URL' in errors[0])
 def testInvalidFilesFail(self):
     # just one test file for now
     msg = ''
     frag = 'collection-incomplete.json'
     inp = pathmap.collection_obj(frag)
     try:
         aa = validate_collection(inp)
         if len(aa) > 0:
             errors = aa[0]
             if len(errors) == 0:
                 ofn = pathmap.collection_source_path(frag + '.output')
                 testing_write_json(errors, ofn)
                 msg = "Failed to reject file. See {o}".format(o=str(msg))
                 self.assertTrue(False, msg)
     except:
         pass
 def testInvalidFilesFail(self):
     # just one test file for now
     msg = ''
     frag = 'collection-incomplete.json'
     inp = pathmap.collection_obj(frag)
     try:
         aa = validate_collection(inp)
         if len(aa) > 0:
             errors = aa[0]
             if len(errors) == 0:
                 ofn = pathmap.collection_source_path(frag + '.output')
                 testing_write_json(errors, ofn)
                 msg = "Failed to reject file. See {o}".format(o=str(msg))
                 self.assertTrue(False, msg)
     except:
         pass
 def testValidFilesPass(self):
     format_list = ['1.2']
     msg = ''
     for d in VALID_NEXSON_DIRS:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             aa = validate_nexson(nexson)
             annot = aa[0]
             for e in annot.errors:
                 _LOG.debug('unexpected error from {f}: {m}'.format(f=frag, m=UNICODE(e)))
             if len(annot.errors) > 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 testing_write_json(ew_dict, ofn)
                 msg = "File failed to validate cleanly. See {o}".format(o=ofn)
             self.assertEqual(len(annot.errors), 0, msg)
Exemple #12
0
 def testValidFilesPass(self):
     format_list = ['1.2']
     msg = ''
     for d in VALID_NEXSON_DIRS:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             aa = validate_nexson(nexson)
             annot = aa[0]
             for e in annot.errors:
                 _LOG.debug('unexpected error from {f}: {m}'.format(
                     f=frag, m=UNICODE(e)))
             if len(annot.errors) > 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 testing_write_json(ew_dict, ofn)
                 msg = "File failed to validate cleanly. See {o}".format(
                     o=ofn)
             self.assertEqual(len(annot.errors), 0, msg)
 def testOldExpectedWarnings(self):
     msg = ''
     for fn in pathmap.all_files(os.path.join('nexson', 'old-tests')):
         if fn.endswith('.input'):
             frag = fn[:-len('.input')]
             efn = frag + '.expected'
             if os.path.exists(efn):
                 inp = testing_read_json(fn)
                 aa = validate_nexson(inp)
                 annot = aa[0]
                 ew_dict = annot.get_err_warn_summary_dict()
                 ew_dict = testing_through_json(ew_dict)
                 exp = testing_read_json(efn)
                 if not testing_dict_eq(ew_dict, exp):
                     ofn = frag + '.output'
                     testing_write_json(ew_dict, ofn)
                     msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format(o=ofn, e=efn)
                 self.assertDictEqual(exp, ew_dict, msg)
             else:
                 _LOG.warn('Expected output file "{f}" not found'.format(f=efn))
Exemple #14
0
 def testOldExpectedWarnings(self):
     msg = ''
     for fn in pathmap.all_files(os.path.join('nexson', 'old-tests')):
         if fn.endswith('.input'):
             frag = fn[:-len('.input')]
             efn = frag + '.expected'
             if os.path.exists(efn):
                 inp = testing_read_json(fn)
                 aa = validate_nexson(inp)
                 annot = aa[0]
                 ew_dict = annot.get_err_warn_summary_dict()
                 ew_dict = testing_through_json(ew_dict)
                 exp = testing_read_json(efn)
                 if not testing_dict_eq(ew_dict, exp):
                     ofn = frag + '.output'
                     testing_write_json(ew_dict, ofn)
                     msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format(
                         o=ofn, e=efn)
                 self.assertDictEqual(exp, ew_dict, msg)
             else:
                 _LOG.warn(
                     'Expected output file "{f}" not found'.format(f=efn))