# Path: etb/terms.py
# def mk_subst(**bindings):
#     """Named arguments constructor for substitutions. It builds
#     terms from its named arguments.
# 
#     >>> mk_subst(X=mk_numberconst(42), Y=mk_array([mk_numberconst(1),mk_numberconst(2),mk_numberconst(3)]))
#     subst(X = 42, Y = [1, 2, 3])
#     """
#     term_bindings = dict((mk_var(k), v) for k, v in bindings.iteritems())
#     return Subst(term_bindings)
# 
# def mk_map(entries):
#     """
#     Make a map from the given pairs. Pairs are converted to
#     pairs of terms if needed.
#     """
#     if isinstance(entries, Map):
#         return entries.hashcons()
#     else:
#         t = Map(entries)
#         return t.hashcons()
# 
# def mk_stringconst(val):
#     """
#     Make a string constant term out of the given value
#     :parameters:
#     - `val`: a basestring or a StringConst
#     :returntype:
#     - a hashconsed `StringConst` instance
#     """
#     if isinstance(val, StringConst):
#         return val.hashcons()
#     else:
#         t = StringConst(val)
#         return t.hashcons()
# 
# def mk_idconst(val):
#     """
#     Make an id constant term out of the given string value.
#     :parameters:
#     - `val`: a basestring or an IdConst
#     :returntype:
#     - a hashconsed `IdConst` instance
#     """
#     if isinstance(val, IdConst):
#         return val.hashcons()
#     else:
#         t = IdConst(val)
#         return t.hashcons()
# 
# def mk_numberconst(val):
#     """
#     Make a number constant term out of the given value
#     :parameters:
#     - `val`: a basestring or a NumberConst
#     :returntype:
#     - a hashconsed `NumberConst` instance
#     """
#     if isinstance(val, NumberConst):
#         return val.hashcons()
#     else:
#         t = NumberConst(val)
#         return t.hashcons()
# 
# def mk_claim(lit, reason):
#     """Constructor for claims"""
#     return Claim(lit, reason)
# 
# def mk_literal(pred, args):
#     """
#     Makes a literal from pred (a string) and args (a list or tuple of terms)
#     """
#     l = Literal(pred, args)
#     return l.hashcons()
# 
# Path: etb/parser.py
# def parse_literal(text):
#   lit = parse(text, 'literal')
#   return lit


from etb_manager import ETBNetwork
from etb_tests import etb_test, ETBTest
from etb.terms import mk_subst, mk_map, mk_stringconst, mk_idconst, mk_numberconst, mk_claim, mk_literal
from etb.parser import parse_literal


class RemoteTest(ETBTest):

    @etb_test
    def invalid(self):
        query = self.etb.etb().query('between(1,4,12)')
        self.etb.etb().query_wait(query)
        return (self.etb.query_answers(query), [])

    @etb_test
    def invalid_claims(self):
        query = self.etb.etb().query('between(1,4,12)')
        self.etb.etb().query_wait(query)
        return (self.etb.query_claims(query), [])
    
    @etb_test
    def valid(self):
        query = self.etb.etb().query('between(1,4,3)')
        self.etb.etb().query_wait(query)
        return (self.etb.query_answers(query), [mk_subst()])
    
    @etb_test
    def valid_claims(self):
        query = self.etb.etb().query('between(1,4,2)')
        self.etb.etb().query_wait(query)
        return (self.etb.all_claims(),
                [mk_claim(parse_literal('between(1,4,2)'),
                          'from rule between(1,4,2) :- yices({"file": "between.yices", "sha1": "99d4cf6b60c327ca84c809fce0c236c13fcc6845"},"sat") with facts: yices({"file": "between.yices", "sha1": "99d4cf6b60c327ca84c809fce0c236c13fcc6845"},"sat")'),

# Path: etb/terms.py
# def mk_subst(**bindings):
#     """Named arguments constructor for substitutions. It builds
#     terms from its named arguments.
# 
#     >>> mk_subst(X=mk_numberconst(42), Y=mk_array([mk_numberconst(1),mk_numberconst(2),mk_numberconst(3)]))
#     subst(X = 42, Y = [1, 2, 3])
#     """
#     term_bindings = dict((mk_var(k), v) for k, v in bindings.iteritems())
#     return Subst(term_bindings)
# 
# def mk_map(entries):
#     """
#     Make a map from the given pairs. Pairs are converted to
#     pairs of terms if needed.
#     """
#     if isinstance(entries, Map):
#         return entries.hashcons()
#     else:
#         t = Map(entries)
#         return t.hashcons()
# 
# def mk_stringconst(val):
#     """
#     Make a string constant term out of the given value
#     :parameters:
#     - `val`: a basestring or a StringConst
#     :returntype:
#     - a hashconsed `StringConst` instance
#     """
#     if isinstance(val, StringConst):
#         return val.hashcons()
#     else:
#         t = StringConst(val)
#         return t.hashcons()
# 
# def mk_idconst(val):
#     """
#     Make an id constant term out of the given string value.
#     :parameters:
#     - `val`: a basestring or an IdConst
#     :returntype:
#     - a hashconsed `IdConst` instance
#     """
#     if isinstance(val, IdConst):
#         return val.hashcons()
#     else:
#         t = IdConst(val)
#         return t.hashcons()
# 
# def mk_numberconst(val):
#     """
#     Make a number constant term out of the given value
#     :parameters:
#     - `val`: a basestring or a NumberConst
#     :returntype:
#     - a hashconsed `NumberConst` instance
#     """
#     if isinstance(val, NumberConst):
#         return val.hashcons()
#     else:
#         t = NumberConst(val)
#         return t.hashcons()
# 
# def mk_claim(lit, reason):
#     """Constructor for claims"""
#     return Claim(lit, reason)
# 
# def mk_literal(pred, args):
#     """
#     Makes a literal from pred (a string) and args (a list or tuple of terms)
#     """
#     l = Literal(pred, args)
#     return l.hashcons()
# 
# Path: etb/parser.py
# def parse_literal(text):
#   lit = parse(text, 'literal')
#   return lit


# Path: tests/remote_queries.py
from etb_manager import ETBNetwork
from etb_tests import etb_test, ETBTest
from etb.terms import mk_subst, mk_map, mk_stringconst, mk_idconst, mk_numberconst, mk_claim, mk_literal
from etb.parser import parse_literal



class RemoteTest(ETBTest):

    @etb_test
    def invalid(self):
        query = self.etb.etb().query('between(1,4,12)')
        self.etb.etb().query_wait(query)
        return (self.etb.query_answers(query), [])

    @etb_test
    def invalid_claims(self):
        query = self.etb.etb().query('between(1,4,12)')
        self.etb.etb().query_wait(query)
        return (self.etb.query_claims(query), [])
    
    @etb_test
    def valid(self):
        query = self.etb.etb().query('between(1,4,3)')
        self.etb.etb().query_wait(query)
        return (self.etb.query_answers(query), [mk_subst()])
    
    @etb_test
    def valid_claims(self):
        query = self.etb.etb().query('between(1,4,2)')
        self.etb.etb().query_wait(query)
        return (self.etb.all_claims(),
                [mk_claim(parse_literal('between(1,4,2)'),
                          'from rule between(1,4,2) :- yices({"file": "between.yices", "sha1": "99d4cf6b60c327ca84c809fce0c236c13fcc6845"},"sat") with facts: yices({"file": "between.yices", "sha1": "99d4cf6b60c327ca84c809fce0c236c13fcc6845"},"sat")'),

                 mk_claim(parse_literal('yices({"file": "between.yices", "sha1": "99d4cf6b60c327ca84c809fce0c236c13fcc6845"},"sat")'), 'yices({"file": "between.yices", "sha1": "99d4cf6b60c327ca84c809fce0c236c13fcc6845"},"sat")')])