Ejemplo n.º 1
0
 def test_events_validate_invalid(self):
     from hedweb.events import validate
     events_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events.tsv')
     json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events_bad.json')
     schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/HED8.0.0.xml')
     hed_schema = hedschema.load_schema(schema_path)
     json_sidecar = models.Sidecar(file=json_path, name='bids_events_bad')
     events = models.EventsInput(file=events_path, sidecars=json_sidecar, name='bids_events')
     with self.app.app_context():
         results = validate(hed_schema, events)
         self.assertTrue(results['data'],
                         'validate results should have a data key when validation errors')
         self.assertEqual('warning', results["msg_category"],
                          'validate msg_category should be warning when errors')
Ejemplo n.º 2
0
 def test_events_assemble_valid(self):
     from hedweb.events import assemble
     events_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events.tsv')
     json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events.json')
     schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/HED8.0.0.xml')
     hed_schema = hedschema.load_schema(schema_path)
     json_sidecar = models.Sidecar(file=json_path, name='bids_json')
     events = models.EventsInput(file=events_path, sidecars=json_sidecar, name='bids_events')
     with self.app.app_context():
         results = assemble(hed_schema, events, expand_defs=True)
         self.assertTrue(results['data'],
                         'assemble results should have a data key when no errors')
         self.assertEqual('success', results['msg_category'],
                          'assemble msg_category should be success when no errors')
Ejemplo n.º 3
0
 def test_events_process_invalid(self):
     from hedweb.events import process
     events_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events.tsv')
     json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events_bad.json')
     schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/HED8.0.0.xml')
     hed_schema = hedschema.load_schema(schema_path)
     json_sidecar = models.Sidecar(file=json_path, name='bids_events_bad')
     events = models.EventsInput(file=events_path, sidecars=json_sidecar, name='bids_events')
     arguments = {base_constants.EVENTS: events, base_constants.COMMAND: base_constants.COMMAND_VALIDATE,
                  base_constants.EXPAND_DEFS: True,
                  base_constants.CHECK_FOR_WARNINGS: True, base_constants.SCHEMA: hed_schema}
     with self.app.app_context():
         results = process(arguments)
         self.assertTrue(isinstance(results, dict),
                         'process validation should return a result dictionary when validation errors')
         self.assertEqual('warning', results['msg_category'],
                          'process validate should return warning when errors')
Ejemplo n.º 4
0
def get_input_from_events_form(request):
    """Gets the validation function input arguments from a request object associated with the validation form.

    Parameters
    ----------
    request: Request object
        A Request object containing user data from the validation form.

    Returns
    -------
    dictionary
        A dictionary containing input arguments for calling the underlying validation function.
    """

    arguments = {
        base_constants.SCHEMA:
        get_hed_schema_from_pull_down(request),
        base_constants.EVENTS:
        None,
        base_constants.COMMAND:
        request.form.get(base_constants.COMMAND_OPTION, ''),
        base_constants.CHECK_FOR_WARNINGS:
        form_has_option(request, base_constants.CHECK_FOR_WARNINGS, 'on'),
        base_constants.EXPAND_DEFS:
        form_has_option(request, base_constants.EXPAND_DEFS, 'on'),
        base_constants.COLUMNS_SELECTED:
        create_column_selections(request.form)
    }

    json_sidecar = None
    if base_constants.JSON_FILE in request.files:
        f = request.files[base_constants.JSON_FILE]
        json_sidecar = models.Sidecar(file=f, name=secure_filename(f.filename))
    arguments[base_constants.JSON_SIDECAR] = json_sidecar
    if base_constants.EVENTS_FILE in request.files:
        f = request.files[base_constants.EVENTS_FILE]
        arguments[base_constants.EVENTS] = \
            models.EventsInput(file=f, sidecars=json_sidecar, name=secure_filename(f.filename))
    return arguments
Ejemplo n.º 5
0
def get_input_objects(arguments, params):
    if base_constants.JSON_STRING in params and params[
            base_constants.JSON_STRING]:
        arguments[base_constants.JSON_SIDECAR] = \
            models.Sidecar(file=io.StringIO(params[base_constants.JSON_STRING]), name='JSON_Sidecar')
    if base_constants.EVENTS_STRING in params and params[
            base_constants.EVENTS_STRING]:
        arguments[base_constants.EVENTS] = \
            models.EventsInput(file=io.StringIO(params[base_constants.EVENTS_STRING]),
                               sidecars=arguments[base_constants.JSON_SIDECAR], name='Events')
    if base_constants.SPREADSHEET_STRING in params and params[
            base_constants.SPREADSHEET_STRING]:
        tag_columns, prefix_dict = spreadsheet.get_prefix_dict(params)
        arguments[base_constants.SPREADSHEET] = \
            models.HedInput(file=io.StringIO(params[base_constants.SPREADSHEET_STRING]), file_type=".tsv",
                            tag_columns=tag_columns,
                            has_column_names=arguments.get(base_constants.HAS_COLUMN_NAMES, None),
                            column_prefix_dictionary=prefix_dict, name='spreadsheet.tsv')
    if base_constants.STRING_LIST in params and params[
            base_constants.STRING_LIST]:
        s_list = []
        for s in params[base_constants.STRING_LIST]:
            s_list.append(models.HedString(s))
        arguments[base_constants.STRING_LIST] = s_list