# Path: ensembler/param_parsers.py
# def eval_quantity_string(param_value_string):
#     """
#     Safely evaluate simtk quantities passed from CLI, using either Python expression syntax
#     ('2 * picoseconds' or '2 / picoseconds') or a more natural syntax ('2 picoseconds').
# 
#     Parameters
#     ----------
#     param_value_string: str
# 
#     Examples
#     --------
#     >>> eval_quantity_string('2 picoseconds')
#     Quantity(value=2, unit=picosecond)
#     >>> eval_quantity_string('2 / picoseconds')
#     Quantity(value=2, unit=/picosecond)
#     >>> eval_quantity_string('2')
#     2
#     """
# 
#     quantity_as_number_space_unit_match = re.match(quantity_without_operator_regex, param_value_string)
#     if quantity_as_number_space_unit_match:
#         number, unit_name = quantity_as_number_space_unit_match.groups()
#         number = ast.literal_eval(number)
#         unit_obj = getattr(simtk.unit, unit_name)
#         return number * unit_obj
# 
#     else:
#         expr = ast.parse(param_value_string, mode='eval')
#         return safe_eval(expr.body)
# 
# def parse_api_params_string(params_string):
#     """
#     Safely parse a string representing a dict of kwargs to be passed to an API function.
# 
#     Parameters
#     ----------
#     params_string: str
# 
#     Returns
#     -------
#     dict
# 
#     Examples
#     --------
#     >>> mydict = parse_api_params_string('{"a": 3 / picoseconds, "b": "x", "c": 2.4}')
#     """
# 
#     expr = ast.parse(params_string, mode='eval')
#     if not isinstance(expr.body, ast.Dict):
#         raise TypeError('Parsed string - {0} - should return a dict'.format(params_string))
#     return safe_eval(expr.body)


from ensembler.param_parsers import eval_quantity_string, parse_api_params_string
from simtk import unit
from nose.plugins.attrib import attr


@attr('unit')
def test_eval_quantity_string():
    assert eval_quantity_string('2 picoseconds') == 2 * unit.picoseconds
    assert eval_quantity_string('2picoseconds') == 2 * unit.picoseconds

# Path: ensembler/param_parsers.py
# def eval_quantity_string(param_value_string):
#     """
#     Safely evaluate simtk quantities passed from CLI, using either Python expression syntax
#     ('2 * picoseconds' or '2 / picoseconds') or a more natural syntax ('2 picoseconds').
# 
#     Parameters
#     ----------
#     param_value_string: str
# 
#     Examples
#     --------
#     >>> eval_quantity_string('2 picoseconds')
#     Quantity(value=2, unit=picosecond)
#     >>> eval_quantity_string('2 / picoseconds')
#     Quantity(value=2, unit=/picosecond)
#     >>> eval_quantity_string('2')
#     2
#     """
# 
#     quantity_as_number_space_unit_match = re.match(quantity_without_operator_regex, param_value_string)
#     if quantity_as_number_space_unit_match:
#         number, unit_name = quantity_as_number_space_unit_match.groups()
#         number = ast.literal_eval(number)
#         unit_obj = getattr(simtk.unit, unit_name)
#         return number * unit_obj
# 
#     else:
#         expr = ast.parse(param_value_string, mode='eval')
#         return safe_eval(expr.body)
# 
# def parse_api_params_string(params_string):
#     """
#     Safely parse a string representing a dict of kwargs to be passed to an API function.
# 
#     Parameters
#     ----------
#     params_string: str
# 
#     Returns
#     -------
#     dict
# 
#     Examples
#     --------
#     >>> mydict = parse_api_params_string('{"a": 3 / picoseconds, "b": "x", "c": 2.4}')
#     """
# 
#     expr = ast.parse(params_string, mode='eval')
#     if not isinstance(expr.body, ast.Dict):
#         raise TypeError('Parsed string - {0} - should return a dict'.format(params_string))
#     return safe_eval(expr.body)


# Path: ensembler/tests/test_param_parsers.py
from ensembler.param_parsers import eval_quantity_string, parse_api_params_string
from simtk import unit
from nose.plugins.attrib import attr



@attr('unit')
def test_eval_quantity_string():
    assert eval_quantity_string('2 picoseconds') == 2 * unit.picoseconds
    assert eval_quantity_string('2picoseconds') == 2 * unit.picoseconds

    assert eval_quantity_string('2 / picoseconds') == 2 / unit.picoseconds