from __future__ import print_function
from builtins import range
import sys
sys.path.insert(1,"../../../")
import h2o
from tests import pyunit_utils
import string
import random
import time
'''
The below function will test if the exporting of a file in H2O is NOT asynchronous. Meaning the h2o.export_file()
waits for the entire process to finish before exiting.
'''
def export_time():
    pros_hex = h2o.upload_file(pyunit_utils.locate("bigdata/laptop/citibike-nyc/2013-07.csv"))

    def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
        return ''.join(random.choice(chars) for _ in range(size))

    fname = id_generator() + "_prediction.csv"

    path = pyunit_utils.locate("results")
    dname = path + "/" + fname

    start = time.time()
    h2o.export_file(pros_hex,dname)
    end = time.time()
    time_to_export = end-start
    print("Time to export is",time_to_export,"seconds.")
    assert time_to_export > 2, "File export happened instantly (less than 2 seconds). Please check if h2o.export() properly exported file"

if __name__ == "__main__":
    pyunit_utils.standalone_test(export_time)
else:
    export_time()




@@ -177,20 +177,57 @@
 %0Aimport 
-time
+pandas as pd%0Aimport numpy as np%0Aimport os
 %0A'''%0AThe
@@ -400,58 +400,62 @@
 '''%0A
+%0A%0A
 def 
+test_
 export_
-time():%0A    pros_hex = h2o.upload_file(
+not_asynchronous():%0A    orig_path = 
 pyun
@@ -512,16 +512,57 @@
 07.csv%22)
+%0A    pros_hex = h2o.upload_file(orig_path
 )%0A%0A    d
@@ -707,434 +707,790 @@
     
-fname = id_generator() + %22_prediction.csv%22%0A%0A    path = pyunit_utils.locate(%22results%22)%0A    dname = path + %22/%22 + fname%0A%0A    start = time.time()%0A    h2o.export_file(pros_hex,dname)%0A    end = time.time()%0A    time_to
+export_path = pyunit_utils.locate(%22results%22) + %22/%22 + %22test_export_not_async_%22 + id_generator() + %22.csv%22%0A%0A    h2o.export_file(pros_hex, export_path)%0A    export_size1 = os.stat(export_path).st_size%0A%0A    pandas_df
 _export
+ed
  = 
-end-start%0A    print(%22Time to export is%22,time_to_export,%22seconds.%22)%0A    assert time_to_export %3E 2, %22File export happened instantly (less than 2 seconds). Please check if h2o.export() properly exported file%22
+pd.read_csv(export_path)%0A    pandas_df_exported = pandas_df_exported.drop(columns=%5B'starttime', 'stoptime'%5D) # H2O exports these as timestamps%0A    pandas_df_orig = pd.read_csv(orig_path, dtype=%7B'birth year': np.float64%7D, na_values=%22%5CN%22)%0A    pandas_df_orig = pandas_df_orig.drop(columns=%5B'starttime', 'stoptime'%5D)%0A%0A    pd.testing.assert_frame_equal(pandas_df_orig, pandas_df_exported)%0A    export_size2 = os.stat(export_path).st_size%0A%0A    # Show that file size didn't change in the mean time =%3E export is not asynchronous%0A    assert export_size1 == export_size2%0A
 %0A%0Aif
@@ -1547,27 +1547,44 @@
 ne_test(
+test_
 export_
-time
+not_asynchronous
 )%0Aelse:%0A
@@ -1591,19 +1591,36 @@
     
+test_
 export_
-time
+not_asynchronous
 ()%0A%0A

Fix export test to show the export is not asynchronous without using times