# Path: prolog/interpreter/parsing.py
# def get_engine(source, create_files=False, load_system=False, **modules):
#     from prolog.interpreter.continuation import Engine
#     from prolog.interpreter.test.tool import create_file, delete_file
#     e = Engine(load_system)
#     for name, module in modules.iteritems():
#         if create_files:
#             create_file(name, module)
#         else:
#             e.runstring(module)
#     try:
#         e.modulewrapper.current_module = e.modulewrapper.user_module
#         e.runstring(source)
#     finally:
#         if create_files:
#             for name in modules.keys():
#                 delete_file(name)
#     return e
# 
# Path: prolog/interpreter/parsing.py
# def get_query_and_vars(s):
#     tokens = lexer.tokenize(s, eof=True)
#     s = parser_query.parse(tokens, lazy=False)
#     builder = TermBuilder()
#     query = builder.build_query(s)
#     return query, builder.varname_to_var
# 
# Path: prolog/interpreter/error.py
# class UncaughtError(TermedError):
#     def __init__(self, term, sig_context=None, rule_likely_source=None, scont=None):
#         TermedError.__init__(self, term, sig_context)
#         self.rule = rule_likely_source
#         self.traceback = _construct_traceback(scont)
# 
#     def format_traceback(self, engine):
#         out = ["Traceback (most recent call last):"]
#         self.traceback._format(out)
#         context = ""
#         if self.sig_context is not None:
#             context = self.sig_context.string()
#             if context == "throw/1":
#                 context = ""
#             else:
#                 context += ": "
#         out.append("%s%s" % (context, self.get_errstr(engine)))
#         return "\n".join(out)
# 
# Path: prolog/interpreter/signature.py
# class Signature(object):
#     """An object representing the signature of a Prolog term."""
# 
#     _cache = SignatureFactory()
# 
#     _immutable_fields_ = ["name", "numargs", "atom_signature", "factory"]
# 
#     def __init__(self, name, numargs, cached=False, factory=None):
#         assert name is not None
#         assert isinstance(name, str)
#         name = rstring.assert_str0(name)
#         self.name = name
#         self.numargs = numargs
#         self.cached = cached
#         if factory is None:
#             factory = self._cache
#         self.factory = factory
#         if numargs:
#             atom_signature = factory.getsignature(name, 0, cached)
#         else:
#             atom_signature = self
#         self.atom_signature = atom_signature
#         factory.init_extra_attrs(self)
# 
#     def eq(self, other):
#         # slightly evil
#         if jit.isconstant(self):
#             jit.promote(other)
#         elif jit.isconstant(other):
#             jit.promote(self)
#         return self is other or (
#                 self.numargs == other.numargs and
#                 self.name == other.name)
# 
#     @specialize.arg(1)
#     def get_extra(self, name):
#         aname = "extra_attr_" + name
#         if not we_are_translated():
#             assert aname in self.factory.extra_attr_names
#         self = self.ensure_cached()
#         return getattr(self, aname)
# 
#     @specialize.arg(1)
#     def set_extra(self, name, val):
#         aname = "extra_attr_" + name
#         if not we_are_translated():
#             assert aname in self.factory.extra_attr_names
#         self = self.ensure_cached()
#         setattr(self, aname, val)
# 
# 
#     @specialize.arg(1)
#     def get_extra_engine_local(self, name, engine):
#         ename = "extra_attr_engine_" + name
#         if not we_are_translated():
#             assert ename in self.factory.extra_attr_names
#         if getattr(self, ename) is not engine:
#             setattr(self, ename, engine)
#             aname = "extra_attr_" + name
#             setattr(self, aname, None)    
#         return self.get_extra(name)
# 
#     @specialize.arg(1)
#     def set_extra_engine_local(self, name, val, engine):
#         ename = "extra_attr_engine_" + name
#         setattr(self, ename, engine)
#         self.set_extra(name, val)
# 
#     def ensure_cached(self):
#         if self.cached:
#             return self
#         return self.factory.ensure_cached(self)
# 
#     def string(self):
#         return "%s/%s" % (self.name, self.numargs)
# 
#     def __repr__(self):
#         return "<Signature %s>" % (self.string(), )
# 
#     @staticmethod
#     @jit.elidable
#     def getsignature(name, numargs):
#         return Signature._cache.getsignature(name, numargs)
# 
#     @staticmethod
#     def register_extr_attr(name, engine=False, default=None):
#         Signature._cache.register_extr_attr(name, engine, default)


import py, pytest
from prolog.interpreter.parsing import get_engine
from prolog.interpreter.parsing import get_query_and_vars
from prolog.interpreter.error import UncaughtError
from prolog.interpreter.signature import Signature


def get_uncaught_error(query, e):
    if isinstance(query, str):
        (query, _) = get_query_and_vars(query)
    return pytest.raises(UncaughtError, e.run_query_in_current, query).value


def test_errstr():
    e = get_engine("""

# Path: prolog/interpreter/parsing.py
# def get_engine(source, create_files=False, load_system=False, **modules):
#     from prolog.interpreter.continuation import Engine
#     from prolog.interpreter.test.tool import create_file, delete_file
#     e = Engine(load_system)
#     for name, module in modules.iteritems():
#         if create_files:
#             create_file(name, module)
#         else:
#             e.runstring(module)
#     try:
#         e.modulewrapper.current_module = e.modulewrapper.user_module
#         e.runstring(source)
#     finally:
#         if create_files:
#             for name in modules.keys():
#                 delete_file(name)
#     return e
# 
# Path: prolog/interpreter/parsing.py
# def get_query_and_vars(s):
#     tokens = lexer.tokenize(s, eof=True)
#     s = parser_query.parse(tokens, lazy=False)
#     builder = TermBuilder()
#     query = builder.build_query(s)
#     return query, builder.varname_to_var
# 
# Path: prolog/interpreter/error.py
# class UncaughtError(TermedError):
#     def __init__(self, term, sig_context=None, rule_likely_source=None, scont=None):
#         TermedError.__init__(self, term, sig_context)
#         self.rule = rule_likely_source
#         self.traceback = _construct_traceback(scont)
# 
#     def format_traceback(self, engine):
#         out = ["Traceback (most recent call last):"]
#         self.traceback._format(out)
#         context = ""
#         if self.sig_context is not None:
#             context = self.sig_context.string()
#             if context == "throw/1":
#                 context = ""
#             else:
#                 context += ": "
#         out.append("%s%s" % (context, self.get_errstr(engine)))
#         return "\n".join(out)
# 
# Path: prolog/interpreter/signature.py
# class Signature(object):
#     """An object representing the signature of a Prolog term."""
# 
#     _cache = SignatureFactory()
# 
#     _immutable_fields_ = ["name", "numargs", "atom_signature", "factory"]
# 
#     def __init__(self, name, numargs, cached=False, factory=None):
#         assert name is not None
#         assert isinstance(name, str)
#         name = rstring.assert_str0(name)
#         self.name = name
#         self.numargs = numargs
#         self.cached = cached
#         if factory is None:
#             factory = self._cache
#         self.factory = factory
#         if numargs:
#             atom_signature = factory.getsignature(name, 0, cached)
#         else:
#             atom_signature = self
#         self.atom_signature = atom_signature
#         factory.init_extra_attrs(self)
# 
#     def eq(self, other):
#         # slightly evil
#         if jit.isconstant(self):
#             jit.promote(other)
#         elif jit.isconstant(other):
#             jit.promote(self)
#         return self is other or (
#                 self.numargs == other.numargs and
#                 self.name == other.name)
# 
#     @specialize.arg(1)
#     def get_extra(self, name):
#         aname = "extra_attr_" + name
#         if not we_are_translated():
#             assert aname in self.factory.extra_attr_names
#         self = self.ensure_cached()
#         return getattr(self, aname)
# 
#     @specialize.arg(1)
#     def set_extra(self, name, val):
#         aname = "extra_attr_" + name
#         if not we_are_translated():
#             assert aname in self.factory.extra_attr_names
#         self = self.ensure_cached()
#         setattr(self, aname, val)
# 
# 
#     @specialize.arg(1)
#     def get_extra_engine_local(self, name, engine):
#         ename = "extra_attr_engine_" + name
#         if not we_are_translated():
#             assert ename in self.factory.extra_attr_names
#         if getattr(self, ename) is not engine:
#             setattr(self, ename, engine)
#             aname = "extra_attr_" + name
#             setattr(self, aname, None)    
#         return self.get_extra(name)
# 
#     @specialize.arg(1)
#     def set_extra_engine_local(self, name, val, engine):
#         ename = "extra_attr_engine_" + name
#         setattr(self, ename, engine)
#         self.set_extra(name, val)
# 
#     def ensure_cached(self):
#         if self.cached:
#             return self
#         return self.factory.ensure_cached(self)
# 
#     def string(self):
#         return "%s/%s" % (self.name, self.numargs)
# 
#     def __repr__(self):
#         return "<Signature %s>" % (self.string(), )
# 
#     @staticmethod
#     @jit.elidable
#     def getsignature(name, numargs):
#         return Signature._cache.getsignature(name, numargs)
# 
#     @staticmethod
#     def register_extr_attr(name, engine=False, default=None):
#         Signature._cache.register_extr_attr(name, engine, default)


# Path: prolog/interpreter/test/test_error.py
import py, pytest
from prolog.interpreter.parsing import get_engine
from prolog.interpreter.parsing import get_query_and_vars
from prolog.interpreter.error import UncaughtError
from prolog.interpreter.signature import Signature



def get_uncaught_error(query, e):
    if isinstance(query, str):
        (query, _) = get_query_and_vars(query)
    return pytest.raises(UncaughtError, e.run_query_in_current, query).value


def test_errstr():
    e = get_engine("""

        f(X) :- drumandbass(X).