def test_neurolucida_format_convert(): with open("test/neurolucida.asc", "rt") as fp: data = fp.read() out, err = command.run_lmeasure(data, *lm_metrics) command.check_errors(err) swc = command.run_convert(data) out, err = command.run_lmeasure(swc, *lm_metrics) command.check_errors(err)
def lmeasure(): if request.method == "OPTIONS": resp = jsonify(measure_options) resp.headers['Allow'] = "POST,OPTIONS" return resp elif request.method == "POST": if request.is_json: d = request.get_json() else: d = request.form if "data" not in d: return jsonify({"error": "no 'data' field in request"}), 400 if "metrics" not in d: metrics = command.lm_function_names elif isinstance(d["metrics"], str): metrics = (d["metrics"], ) elif isinstance(d["metrics"], list): metrics = d["metrics"] app.logger.debug('requested metrics: %s', metrics) try: out, err = command.run_lmeasure(d["data"], *metrics) app.logger.debug('stdout: %s', out) app.logger.debug('stderr: %s', err) command.check_errors(err) measures = [d for d in command.parse_results(out)] except KeyError as e: return jsonify({"error": "bad metric '{}' requested".format(e)}), 400 except RuntimeError as e: return jsonify({"error": "l-measure failed: {!s}".format(e)}), 400 else: return jsonify({"error": None, "measures": measures})
def test_metric_names_match_list(): with open("test/neuron.swc", "rt") as fp: data = fp.read() out, err = command.run_lmeasure(data, *lm_metrics) command.check_errors(err) result = tuple(command.parse_results(out)) assert_sequence_equal([x['metric'] for x in result], lm_metrics)
def test_neurolucida_format_ok(): with open("test/neurolucida.asc", "rt") as fp: data = fp.read() out, err = command.run_lmeasure(data, lm_metrics[0]) command.check_errors(err) tuple(command.parse_results(out))
def test_bad_metric_raises_error(): data = "blah blah blah" out, err = command.run_lmeasure(data, "amazingness")
def test_no_metrics_raises_error(): data = "blah blah blah" out, err = command.run_lmeasure(data)
def test_garbage_input_raises_error(): data = "blah blah blah" out, err = command.run_lmeasure(data, lm_metrics[0]) command.check_errors(err)
def test_blank_file_rasies_error(): with open("test/blank.swc", "rt") as fp: data = fp.read() out, err = command.run_lmeasure(data, lm_metrics[0]) command.check_errors(err)