def test_complex_jython(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): # to avoid timeout on appveyor return download_java_standalone() assert is_java_installed() this = os.path.abspath(os.path.dirname(__file__)) temp = os.path.join(this, "temp_jython") if not os.path.exists(temp): os.mkdir(temp) jyt = os.path.join(temp, "jy2.py") with open(jyt, "w", encoding="utf8") as f: f.write(''' if __name__ != '__lib__': def outputSchema(dont_care): def wrapper(func): def inner(*args, **kwargs): return func(*args, **kwargs) return inner return wrapper import datetime #@outputSchema("brow: (available_bike_stands:chararray, available_bikes:chararray, lat:chararray, lng:chararray, name:chararray, status:chararray)") @outputSchema("brow:chararray") def extract_columns_from_js(row): cols = ["available_bike_stands","available_bikes","lat","lng","name","status"] js = eval(row) res = [ ] for station in js: vals = [ str(station[c]) for c in cols ] res.append( tuple(vals) ) return res if __name__ != '__lib__': import sys for row in sys.stdin: row = row.strip() res = extract_columns_from_js(row) sys.stdout.write(str(res)) sys.stdout.write("\\n") sys.stdout.flush() '''.replace(" ", "")) sin = ''' [{'address': 'RUE DES CHAMPEAUX (PRES DE LA GARE ROUTIERE) - 93170 BAGNOLET', 'collect_date': datetime.datetime(2014, 11, 11, 22, 2, 18, 47270), 'lng': 2.416170724425901, 'contract_name': 'Paris', 'name': '31705 - CHAMPEAUX (BAGNOLET)', 'banking': 0, 'lat': 48.8645278209514, 'bonus': 0, 'status': 'OPEN', 'available_bikes': 1, 'last_update': datetime.datetime(2014, 11, 11, 21, 55, 22), 'number': 31705, 'available_bike_stands': 49, 'bike_stands': 50}] [{'address': 'RUE DES CHAMPEAUX (PRES DE LA GARE ROUTIERE) - 93170 BAGNOLET', 'collect_date': datetime.datetime(2014, 11, 11, 22, 2, 18, 47270), 'lng': 2.416170724425901, 'contract_name': 'Paris', 'name': '31705 - CHAMPEAUX (BAGNOLET)', 'banking': 0, 'lat': 48.8645278209514, 'bonus': 0, 'status': 'OPEN', 'available_bikes': 1, 'last_update': datetime.datetime(2014, 11, 11, 21, 55, 22), 'number': 31705, 'available_bike_stands': 49, 'bike_stands': 50}] '''.replace(" ", "").strip("\r\n ") out, err = run_jython(jyt, sin=sin, fLOG=fLOG) fLOG("OUT:\n", out) fLOG("ERR:\n", err) exp = "[('49', '1', '48.864527821'," if exp not in out: raise Exception("OUT:\n{0}\nERR:\n{1}\n".format(out, err))
def test_complex_jython(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if "travis" in sys.executable: return download_java_standalone() assert is_java_installed() this = os.path.abspath(os.path.dirname(__file__)) temp = os.path.join(this, "temp_jython") if not os.path.exists(temp): os.mkdir(temp) jyt = os.path.join(temp, "jy2.py") with open(jyt, "w", encoding="utf8") as f: f.write(''' if __name__ != '__lib__': def outputSchema(dont_care): def wrapper(func): def inner(*args, **kwargs): return func(*args, **kwargs) return inner return wrapper import datetime #@outputSchema("brow: (available_bike_stands:chararray, available_bikes:chararray, lat:chararray, lng:chararray, name:chararray, status:chararray)") @outputSchema("brow:chararray") def extract_columns_from_js(row): cols = ["available_bike_stands","available_bikes","lat","lng","name","status"] js = eval(row) res = [ ] for station in js: vals = [ str(station[c]) for c in cols ] res.append( tuple(vals) ) return res if __name__ != '__lib__': import sys for row in sys.stdin: row = row.strip() res = extract_columns_from_js(row) sys.stdout.write(str(res)) sys.stdout.write("\\n") sys.stdout.flush() '''.replace(" ", "")) sin = ''' [{'address': 'RUE DES CHAMPEAUX (PRES DE LA GARE ROUTIERE) - 93170 BAGNOLET', 'collect_date': datetime.datetime(2014, 11, 11, 22, 2, 18, 47270), 'lng': 2.416170724425901, 'contract_name': 'Paris', 'name': '31705 - CHAMPEAUX (BAGNOLET)', 'banking': 0, 'lat': 48.8645278209514, 'bonus': 0, 'status': 'OPEN', 'available_bikes': 1, 'last_update': datetime.datetime(2014, 11, 11, 21, 55, 22), 'number': 31705, 'available_bike_stands': 49, 'bike_stands': 50}] [{'address': 'RUE DES CHAMPEAUX (PRES DE LA GARE ROUTIERE) - 93170 BAGNOLET', 'collect_date': datetime.datetime(2014, 11, 11, 22, 2, 18, 47270), 'lng': 2.416170724425901, 'contract_name': 'Paris', 'name': '31705 - CHAMPEAUX (BAGNOLET)', 'banking': 0, 'lat': 48.8645278209514, 'bonus': 0, 'status': 'OPEN', 'available_bikes': 1, 'last_update': datetime.datetime(2014, 11, 11, 21, 55, 22), 'number': 31705, 'available_bike_stands': 49, 'bike_stands': 50}] '''.replace(" ", "").strip("\r\n ") out, err = run_jython(jyt, sin=sin, fLOG=fLOG) fLOG("OUT:\n", out) fLOG("ERR:\n", err) exp = "[('49', '1', '48.864527821'," if exp not in out: raise Exception("OUT:\n{0}\nERR:\n{1}\n".format(out, err))
def test_simple_jython(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): return download_java_standalone() assert is_java_installed() this = os.path.abspath(os.path.dirname(__file__)) temp = os.path.join(this, "temp_jython") if not os.path.exists(temp): os.mkdir(temp) jyt = os.path.join(temp, "jy1.py") with open(jyt, "w", encoding="utf8") as f: f.write('print("first try with jython")') out, err = run_jython(jyt, fLOG=fLOG) if "first try with jython" not in out: raise Exception("OUT:\n{0}\nERR:\n{1}\n".format(out, err))
def test_simple_jython(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): return download_java_standalone() assert is_java_installed() this = os.path.abspath(os.path.dirname(__file__)) temp = os.path.join(this, "temp_jython") if not os.path.exists(temp): os.mkdir(temp) jyt = os.path.join(temp, "jy1.py") with open(jyt, "w", encoding="utf8") as f: f.write('print("first try with jython")') out, err = run_jython(jyt, fLOG=fLOG) if "first try with jython" not in out: raise Exception("OUT:\n{0}\nERR:\n{1}\n".format(out, err))