# Path: sherpa_contrib/xspec/xcm.py
# class Response1D(sherpa.astro.instrument.Response1D):
# class FunctionParameter(sherpa.models.parameter.CompositeParameter):
# class Function2Parameter(sherpa.models.parameter.CompositeParameter):
# class Term(Enum):
# class ModelExpression:
#     def __init__(self, pha, resp_id):
#     def __call__(self, model):
# def notice(spectrum, lo, hi, ignore=False):
# def ignore(spectrum, lo, hi):
# def subtract(spectrum):
# def _mklabel(func):
#     def wrapobj(obj):
#     def __init__(self, arg, func):
#     def eval(self):
#     def wrapobj(obj):
#     def __init__(self, arg1, arg2, func):
#     def eval(self):
# def exp(x):
# def sin(x):
# def cos(x):
# def tan(x):
# def sqrt(x):
# def abs(x):
# def sind(x):
# def cosd(x):
# def tand(x):
# def asin(x):
# def acos(x):
# def ln(x):
# def log(x):
# def xint(x):
# def xmin(x, y):
# def xmax(x, y):
# def set_subtract(add_import, add_spacer, add, state):
# def parse_tie(pars, add_import, add, par, pline):
# def expand_token(add_import, pars, pname, token):
#     def import_xcm():
# def parse_dataid(token):
# def parse_ranges(ranges):
#     def lconvert(val):
# def parse_notice_range(add_import, add, datasets, command, tokens):
#     def __init__(self, expr, groups, postfix, names):
#     def mkname(self, ctr, grp):
#     def try_tablemodel(self, basename, gname):
#     def add_term(self, start, end, ctr):
#     def add_token(self, token):
#     def open_sep(self, prefix=None):
#     def close_sep(self, postfix=None):
#     def check_end_convolution(self):
#     def in_convolution(self):
#     def lastterm_is_openbracket(self):
#     def remove_unneeded_open_bracket(self):
# def create_source_expression(expr):
#     def conv(t):
# def convert_model(expr, postfix, groups, names):
# def convert(infile, chisq="chi2datavar", clean=False, explicit=None):
#     def add_import(expr):
#     def add_spacer(always=True):
#     def madd(expr, expand=False):
#         def sym(name):
#         def sym(name):
#     def add(name, *args, expand=True, **kwargs):
#     ADD = 1
#     MUL = 2
#     CON = 3


from io import StringIO
from sherpa_contrib.xspec import xcm
import os
import pytest
set_source(1, m1)
"""

    f = StringIO('model powerlaw')
    answer = xcm.convert(f)
    check(expected, answer)


# I'd like all these to map to the same string...
@pytest.mark.parametrize('expr,expected',
                         [('phabs * powerlaw', 'm1 * m2'),
                          ('phabs(powerlaw)', 'm1 * (m2)'),
                          ('phabs* powerlaw', 'm1 * m2')
                         ])
def test_absorbed_powerlaw(expr, expected):
    """model powerlaw"""

    expected = f"""from sherpa.astro.ui import *


# model {expr}
m1 = create_model_component('xsphabs', 'm1')
m2 = create_model_component('xspowerlaw', 'm2')

# Set up the model expressions
#
set_source(1, {expected})
"""

    f = StringIO(f'model {expr}')

# Path: sherpa_contrib/xspec/xcm.py
# class Response1D(sherpa.astro.instrument.Response1D):
# class FunctionParameter(sherpa.models.parameter.CompositeParameter):
# class Function2Parameter(sherpa.models.parameter.CompositeParameter):
# class Term(Enum):
# class ModelExpression:
#     def __init__(self, pha, resp_id):
#     def __call__(self, model):
# def notice(spectrum, lo, hi, ignore=False):
# def ignore(spectrum, lo, hi):
# def subtract(spectrum):
# def _mklabel(func):
#     def wrapobj(obj):
#     def __init__(self, arg, func):
#     def eval(self):
#     def wrapobj(obj):
#     def __init__(self, arg1, arg2, func):
#     def eval(self):
# def exp(x):
# def sin(x):
# def cos(x):
# def tan(x):
# def sqrt(x):
# def abs(x):
# def sind(x):
# def cosd(x):
# def tand(x):
# def asin(x):
# def acos(x):
# def ln(x):
# def log(x):
# def xint(x):
# def xmin(x, y):
# def xmax(x, y):
# def set_subtract(add_import, add_spacer, add, state):
# def parse_tie(pars, add_import, add, par, pline):
# def expand_token(add_import, pars, pname, token):
#     def import_xcm():
# def parse_dataid(token):
# def parse_ranges(ranges):
#     def lconvert(val):
# def parse_notice_range(add_import, add, datasets, command, tokens):
#     def __init__(self, expr, groups, postfix, names):
#     def mkname(self, ctr, grp):
#     def try_tablemodel(self, basename, gname):
#     def add_term(self, start, end, ctr):
#     def add_token(self, token):
#     def open_sep(self, prefix=None):
#     def close_sep(self, postfix=None):
#     def check_end_convolution(self):
#     def in_convolution(self):
#     def lastterm_is_openbracket(self):
#     def remove_unneeded_open_bracket(self):
# def create_source_expression(expr):
#     def conv(t):
# def convert_model(expr, postfix, groups, names):
# def convert(infile, chisq="chi2datavar", clean=False, explicit=None):
#     def add_import(expr):
#     def add_spacer(always=True):
#     def madd(expr, expand=False):
#         def sym(name):
#         def sym(name):
#     def add(name, *args, expand=True, **kwargs):
#     ADD = 1
#     MUL = 2
#     CON = 3


# Path: sherpa_contrib/tests/test_xcm.py
from io import StringIO
from sherpa_contrib.xspec import xcm
import os
import pytest

set_source(1, m1)
"""

    f = StringIO('model powerlaw')
    answer = xcm.convert(f)
    check(expected, answer)


# I'd like all these to map to the same string...
@pytest.mark.parametrize('expr,expected',
                         [('phabs * powerlaw', 'm1 * m2'),
                          ('phabs(powerlaw)', 'm1 * (m2)'),
                          ('phabs* powerlaw', 'm1 * m2')
                         ])
def test_absorbed_powerlaw(expr, expected):
    """model powerlaw"""

    expected = f"""from sherpa.astro.ui import *


# model {expr}
m1 = create_model_component('xsphabs', 'm1')
m2 = create_model_component('xspowerlaw', 'm2')

# Set up the model expressions
#
set_source(1, {expected})
"""

    f = StringIO(f'model {expr}')

    answer = xcm.convert(f)