Ejemplo n.º 1
0
    def testInfer(self):
        self.assertIsa(int, api.infer("5 + 5"))

        # Test that IO needs to be explicit.
        self.assertEqual(protocol.AnyType,
                         api.infer("csv(path, decode_header:true)"))
        self.assertIsa(dict, api.infer("csv(path, decode_header:true)",
                                       libs=("stdcore", "stdio")))
Ejemplo n.º 2
0
def main():
    for description, query in QUERIES:
        print("# %s\n%s" % (description, query))

        # We can find out what the EFILTER query will return by using the type
        # inference system. If it is a repeated value, we can render it in
        # multiple rows.
        result_type = api.infer(query,
                                replacements=[CATALOG_PATH],
                                libs=("stdcore", "stdio"))
        print("# Return type will be %s." % (result_type.__name__,))

        # api.apply will give us the actual result of running the query, which
        # should be of the type we got above.
        results = api.apply(query,
                            replacements=[CATALOG_PATH],
                            allow_io=True,
                            # We provide the top level variables in a 'vars'
                            # argument. To bind 'parsec2ly' to the function of
                            # the same name, we have to also wrap it in the
                            # EFILTER user_func. This prevents EFILTER from
                            # accidentally calling regular Python functions.
                            vars={"parsec2ly": api.user_func(parsec2ly)})

        # Because we don't know the cardinality of the query in 'query' we can
        # use 'getvalues' to always receive an iterator of results. This is just
        # a convenience function.
        for n, result in enumerate(api.getvalues(results)):
            print("%d - %r" % (n + 1, result))

        print("\n\n")
Ejemplo n.º 3
0
 def testInference(self):
     """Test that infer_type correctly uses reflection on stdlib."""
     self.assertEqual(api.infer("count((1, 2, 3))"), int)
Ejemplo n.º 4
0
 def testInference(self):
     """Test that infer_type correctly uses reflection on stdlib."""
     self.assertEqual(api.infer("count((1, 2, 3))"), int)