Ejemplo n.º 1
0
def validate_and_convert_nexson(nexson, output_version, allow_invalid):
    '''Runs the nexson validator and returns a converted 4 object:
        nexson, annotation, validation_log, nexson_adaptor

    `nexson` is the nexson dict.
    `output_version` is the version of nexson syntax to be used after validation.
    if `allow_invalid` is False, and the nexson validation has errors, then
        a GitWorkflowError will be generated before conversion.
    '''
    try:
        if TRACE_FILES:
            _write_to_next_free('input', nexson)
        annotation, validation_log, nexson_adaptor = ot_validate(nexson)
        if TRACE_FILES:
            _write_to_next_free('annotation', annotation)
    except:
        msg = 'exception in ot_validate: ' + traceback.format_exc()
        raise GitWorkflowError(msg)
    if (not allow_invalid) and validation_log.has_error():
        raise GitWorkflowError('ot_validation failed: ' +
                               json.dumps(annotation))
    nexson = convert_nexson_format(nexson, output_version)
    if TRACE_FILES:
        _write_to_next_free('converted', nexson)
    return nexson, annotation, validation_log, nexson_adaptor
Ejemplo n.º 2
0
    def add_validation_annotation(self, study_obj, sha):
        need_to_cache = False
        adaptor = None
        if self._cache_region is not None:
            key = 'v' + sha
            annot_event = self._cache_region.get(key, ignore_expiration=True)
            if annot_event != NO_VALUE:
                _LOG.debug('cache hit for ' + key)
                adaptor = NexsonAnnotationAdder()
                self._cache_hits += 1
            else:
                _LOG.debug('cache miss for ' + key)
                need_to_cache = True

        if adaptor is None:
            bundle = ot_validate(study_obj)
            annotation = bundle[0]
            annot_event = annotation['annotationEvent']
            #del annot_event['@dateCreated'] #TEMP
            #del annot_event['@id'] #TEMP
            adaptor = bundle[2]
        replace_same_agent_annotation(study_obj, annot_event)
        if need_to_cache:
            self._cache_region.set(key, annot_event)
            _LOG.debug('set cache for ' + key)

        return annot_event
Ejemplo n.º 3
0
 def add_validation_annotation(self, doc_obj, sha):
     need_to_cache = False
     adaptor = None
     annot_event = None
     if self._cache_region is not None:
         key = 'v' + sha
         annot_event = self._cache_region.get(key, ignore_expiration=True)
         if annot_event != NO_VALUE:
             _LOG.debug('cache hit for ' + key)
             adaptor = NexsonAnnotationAdder()
             self._cache_hits += 1
         else:
             _LOG.debug('cache miss for ' + key)
             need_to_cache = True
     if adaptor is None:
         bundle = ot_validate(doc_obj)
         annotation = bundle[0]
         annot_event = annotation['annotationEvent']
         # del annot_event['@dateCreated'] #TEMP
         # del annot_event['@id'] #TEMP
         adaptor = bundle[2]
     replace_same_agent_annotation(doc_obj, annot_event)
     if need_to_cache:
         self._cache_region.set(key, annot_event)
         _LOG.debug('set cache for ' + key)
     return annot_event
Ejemplo n.º 4
0
 def testValidFilesPass(self):
     format_list = ['1.0', '1.2']
     TESTS_WITH_GT_ONE_TREE = ['9']
     for d in TESTS_WITH_GT_ONE_TREE:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             annotation = ot_validate(nexson)[0]
             self.assertTrue(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             bundle = validate_and_convert_nexson(nexson,
                                              nf,
                                              allow_invalid=True,
                                              max_num_trees_per_study=1)
             nexson, annotation, validation_log, nexson_adaptor = bundle
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
Ejemplo n.º 5
0
 def testValidFilesPass(self):
     format_list = ['1.0', '1.2']
     TESTS_WITH_GT_ONE_TREE = ['9']
     for d in TESTS_WITH_GT_ONE_TREE:
         for nf in format_list:
             frag = os.path.join(d, 'v{f}.json'.format(f=nf))
             nexson = pathmap.nexson_obj(frag)
             annotation = ot_validate(nexson)[0]
             self.assertTrue(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             annotation = ot_validate(nexson, max_num_trees_per_study=1)[0]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
             bundle = validate_and_convert_nexson(nexson,
                                                  nf,
                                                  allow_invalid=True,
                                                  max_num_trees_per_study=1)
             annotation = bundle[1]
             self.assertFalse(annotation['annotationEvent']['@passedChecks'])
Ejemplo n.º 6
0
def validate_and_convert_nexson(nexson, output_version, allow_invalid, **kwargs):
    '''Runs the nexson validator and returns a converted 4 object:
        nexson, annotation, validation_log, nexson_adaptor

    `nexson` is the nexson dict.
    `output_version` is the version of nexson syntax to be used after validation.
    if `allow_invalid` is False, and the nexson validation has errors, then
        a GitWorkflowError will be generated before conversion.
    '''
    try:
        if TRACE_FILES:
            _write_to_next_free('input', nexson)
        annotation, validation_log, nexson_adaptor = ot_validate(nexson, **kwargs)    
        if TRACE_FILES:
            _write_to_next_free('annotation', annotation)
    except:
        msg = 'exception in ot_validate: ' + traceback.format_exc()
        raise GitWorkflowError(msg)
    if (not allow_invalid) and validation_log.has_error():
        raise GitWorkflowError('ot_validation failed: ' + json.dumps(annotation))
    nexson = convert_nexson_format(nexson, output_version)
    if TRACE_FILES:
        _write_to_next_free('converted', nexson)
    return nexson, annotation, validation_log, nexson_adaptor