def test_obj_id_str(self): oa = OA.objectarray("test") a = OA.testobject("Auto", "a", "power", flag_verbose = self.flag_verbose) oa.add_object(a, flag_verbose = self.flag_verbose) DEBUG.verbose("\nOverwrite warning is intentional", True) oa.save_objectarray(self.path_and_filename, flag_overwrite = True, flag_verbose = self.flag_verbose)
def test_obj_id_unicode(self): """ This testcase may be unnecesary. If you use from __future__ import unicode_literals, then somes strings are suddenly unicode, giving problems when saving the database. However, in Python 3.3 they removed this. Without the __future__ thingy it also works fine in Python 2.7. """ oa = OA.objectarray("test") l = ["auto"] a = OA.testobject(l[0], "a", "power", flag_verbose = self.flag_verbose) oa.add_object(a, flag_verbose = self.flag_verbose) DEBUG.verbose("\nOverwrite warning is intentional", True) oa.save_objectarray(self.path_and_filename, flag_overwrite = True, flag_verbose = self.flag_verbose)
def setUp(self): self.flag_verbose = args.verbose self.flag_verbose = args.verbose self.pickle_path_and_filename = "/Users/robbert/Developer/Crocodile/temp/lineshape_test.pickle" if not os.path.exists(self.pickle_path_and_filename): generate_pickle(self.pickle_path_and_filename, flag_verbose = self.flag_verbose) self.oa1 = OA.objectarray("object1") self.oa1.import_db(self.pickle_path_and_filename, flag_verbose = self.flag_verbose) self.oa2 = OA.objectarray("object2") self.oa2.import_db(self.pickle_path_and_filename, flag_verbose = self.flag_verbose) self.la = [[2075,2125],[2100,2125],[2075,2125],[2075,2100]]
def test_add_object_correct(self): """ Add object with new obj_id """ a = OA.testobject("Brommer", "d", "power", flag_verbose = self.flag_verbose) result = self.oa.add_object(a, flag_verbose = self.flag_verbose) self.assertTrue(["a", "b", "c", "d"] == self.oa.obj_id_array and result == True)
def setUp(self): """ Set up an objectarray object for reuse in the tests. Toggle verbose using the command line. """ self.flag_verbose = args.verbose self.oa = OA.objectarray("test") a = OA.testobject("Auto", "a", "power", flag_verbose = self.flag_verbose) b = OA.testobject("Boot", "b", "power", flag_verbose = self.flag_verbose) c = OA.testobject("Fiets", "c", "human", flag_verbose = self.flag_verbose) self.oa.add_object(a, flag_verbose = self.flag_verbose) self.oa.add_object(b, flag_verbose = self.flag_verbose) self.oa.add_object(c, flag_verbose = self.flag_verbose)
def test_load_objectarray_1(self): """ Test if object are correctly ordered. obj_id_array_in is same as pickle """ oa = OA.objectarray("test_new") oa.load_objectarray(self.path_and_filename, obj_id_array_in = self.obj_id_array, flag_verbose = self.flag_verbose) self.assertTrue(["a", "b", "c"] == oa.obj_id_array)
def test_add_object_without_obj_id(self): """ Add object without obj_id """ oa = OA.objectarray("test_new") DEBUG.verbose("\nError is intentional", True) result = oa.add_object(1, flag_verbose = self.flag_verbose) self.assertFalse(result)
def test_add_object_with_same_obj_id(self): """ Add object with same obj_id """ a = OA.testobject("Boot", "a", "power", flag_verbose = self.flag_verbose) DEBUG.verbose("\nError is intentional", True) result = self.oa.add_object(a, flag_verbose = self.flag_verbose) self.assertTrue(["a", "b", "c"] == self.oa.obj_id_array and result == False)
def test_load_objectarray_4(self): """ Test if object are correctly ordered. obj_id_array_in has one element too much compared to pickle. The object array will only contain the elements of the pickle """ obj_id_array = ["a", "b", "d"] oa = OA.objectarray("test_new") oa.load_objectarray(self.path_and_filename, obj_id_array_in = obj_id_array, flag_verbose = self.flag_verbose) self.assertTrue(["a", "b"] == oa.obj_id_array)
def test_load_objectarray_2(self): """ Test if object are correctly ordered. obj_id_array_in misses one obj_id compared to pickle. The object array should miss that object. """ obj_id_array = ["a", "b"] oa = OA.objectarray("test_new") oa.load_objectarray(self.path_and_filename, obj_id_array_in = obj_id_array, flag_verbose = self.flag_verbose) self.assertTrue(["a", "b"] == oa.obj_id_array)
def setUp(self): """ Set up a pickle for use in this function. """ self.path_and_filename = "/Users/robbert/Developer/PythonTools/temp/test.pickle" self.flag_verbose = args.verbose oa = OA.objectarray("test") a = OA.testobject("Auto", "a", "power", flag_verbose = self.flag_verbose) b = OA.testobject("Boot", "b", "power", flag_verbose = self.flag_verbose) c = OA.testobject("Fiets", "c", "human", flag_verbose = self.flag_verbose) oa.add_object(a, flag_verbose = self.flag_verbose) oa.add_object(b, flag_verbose = self.flag_verbose) oa.add_object(c, flag_verbose = self.flag_verbose) DEBUG.verbose("\nOverwrite warning is intentional", True) oa.save_objectarray(self.path_and_filename, flag_overwrite = True, flag_verbose = self.flag_verbose) self.obj_id_array = oa.obj_id_array
def generate_pickle(pickle_path_and_filename, flag_verbose = False): DEBUG.verbose("Generating pickle", flag_verbose) aha = PETW.pe_LV("aha", "PI99aha", 1626, 300) aha.path = "/Users/robbert/Developer/Crocodile/Tests/Test_resources/PI99aha_1626_T300/" aha.import_data() aha.zeropad_by = 4 aha.absorptive() aha.r = [0,0] buf = PETW.pe_LV("buf", "PI99buf", 1617, 300) buf.path = "/Users/robbert/Developer/Crocodile/Tests/Test_resources/PI99buf_1617_T300/" buf.import_data() buf.zeropad_by = 4 buf.absorptive() buf.r = [0,0] m = PEME.pe_merge("merge", class_plus = [aha], class_min = [buf]) oa = OA.objectarray("merge") oa.add_object(m) oa.save_objectarray(pickle_path_and_filename, flag_overwrite = True)
pickle_paf_r = pickle_path + pickle_base_name + "_r.pickle" pickle_paf_s = pickle_path + pickle_base_name + "_s.pickle" pickle_paf_m = pickle_path + pickle_base_name + "_m.pickle" oar = False oas = False oam = False ############### # IMPORT DATA # ############### if activity == "import" or activity == "import_only" or activity == "all": # if oar already exists, don't bother to re-import it if not oar: oar = OA.objectarray(str(mess_date) + "_r", flag_verbose = flag_verbose) import_pickle(oar, pickle_paf_r, mess_array, flag_verbose = flag_verbose) # import the data, then save for m in mess_array: if m[0] not in oar.obj_id_array: mess = PETW.pe_LV(m[0], m[1], m[2], m[3], flag_verbose = flag_verbose) mess.path = data_path + mess.base_filename + "/" mess.import_data(flag_verbose = flag_verbose) mess.r_correction[2] = w3_correction oar.add_object(mess, flag_verbose = flag_verbose) oar.save_objectarray(pickle_paf_r, flag_verbose = flag_verbose) ######################## # CALCULATE ABSORPTIVE #