Example #1
0
 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())
Example #2
0
 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())
Example #3
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 = 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()
                 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 = 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()
                 write_json(ew_dict, ofn)
                 msg = "Failed to reject file. See {o}".format(o=str(msg))
                 self.assertTrue(False, msg)
Example #5
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)
Example #6
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)
Example #7
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))
Example #8
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))
Example #9
0
         err_stream = codecs.open(errfn, mode='w', encoding='utf-8')
     except:
         sys.exit('validate_ot_nexson: Could not open err-stream filepath "{fn}"\n'.format(fn=errfn))
 try:
     obj = json.load(inp)
 except ValueError as vx:
     _LOG.error('Not valid JSON.')
     if args.verbose:
         raise vx
     else:
         sys.exit(1)
 codes_to_skip = None
 if not args.meta:
     codes_to_skip = [NexsonWarningCodes.UNVALIDATED_ANNOTATION]
 try:
     v_log, adaptor = validate_nexson(obj, codes_to_skip)
 except NexsonError as nx:
     _LOG.error(nx.value)
     sys.exit(1)
 rc = 0
 if args.embed:
     rc = 1 if v_log.has_error() else 0
     annotation = v_log.prepare_annotation(author_name=SCRIPT_NAME,
                                           invocation=sys.argv[1:],
                                           )
     adaptor.add_or_replace_annotation(obj,
                                       annotation['annotationEvent'],
                                       annotation['agent'],
                                       add_agent_only=args.add_agent_only)
     write_as_json(obj, out)
     if args.add_agent_only: