def testCreated(self):
     b = get_empty_nexson()
     aa = validate_nexson(b)
     annot = aa[0]
     self.assertFalse(annot.has_error())
     b = get_empty_nexson(include_cc0=True)
     aa = validate_nexson(b)
     annot = aa[0]
     self.assertFalse(annot.has_error())
 def testInvalidFilesFail(self):
     msg = ''
     for fn in pathmap.all_files(os.path.join('nexson', 'invalid')):
         if fn.endswith('.input'):
             frag = fn[:-len('.input')]
             inp = trj(fn)
             try:
                 aa = validate_nexson(inp)
             except:
                 continue
             annot = aa[0]
             if len(annot.errors) == 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 twj(ew_dict, ofn)
                 msg = "Failed to reject file. See {o}".format(o=str(msg))
                 self.assertTrue(False, msg)
 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()
                 twj(ew_dict, ofn)
                 msg = "File failed to validate cleanly. See {o}".format(
                     o=ofn)
             self.assertEqual(len(annot.errors), 0, msg)
Ejemplo n.º 4
0
 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 = trj(fn)
             aa = validate_nexson(inp)
             annot = aa[0]
             # import json
             # print(json.dumps(annot.prepare_annotation(), indent=2))
             #for n, e in enumerate(annot.errors):
                 # print(n, type(e))
                 # for nv, v in enumerate(e):
                 #     vt = v[0]
                 #     print(nv, vt.as_dict(v))
             if len(annot.errors) == 0:
                 ofn = pathmap.nexson_source_path(frag + '.output')
                 ew_dict = annot.get_err_warn_summary_dict()
                 twj(ew_dict, ofn)
                 msg = "Failed to reject file. See {o}".format(o=str(msg))
                 self.assertTrue(False, 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 = trj(fn)
                 aa = validate_nexson(inp)
                 annot = aa[0]
                 ew_dict = annot.get_err_warn_summary_dict()
                 ew_dict = ttj(ew_dict)
                 exp = trj(efn)
                 if not tde(ew_dict, exp):
                     ofn = frag + '.output'
                     twj(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.warning(
                     'Expected output file "{f}" not found'.format(f=efn))