def test_exposure_csv_set_column_get_column_error_checking(self): file_name = tempfile.mktemp(".csv") file = open(file_name,"w") file.write("LONGITUDE , LATITUDE, sound , speed \n\ 150.916666667, -34.5, splat, 0.0\n\ 150.0, -34.0, pow, 10.0\n") file.close() e1 = Exposure(file_name) os.remove(file_name) new_title = "sound" new_values = [12.5,7.6] try: e1.set_column(new_title, new_values) except TitleValueError: pass else: self.assertTrue(0 ==1, 'Error not thrown error!') e1.set_column(new_title, new_values, overwrite=True) returned_values = e1.get_column(new_title) self.assertTrue(returned_values == new_values, ' Error!') new2_title = "short list" new2_values = [12.5] try: e1.set_column(new2_title, new2_values) except DataMissingValuesError: pass else: self.assertTrue(0 ==1, 'Error not thrown error!') new2_title = "long list" new2_values = [12.5, 7,8] try: e1.set_column(new2_title, new2_values) except DataMissingValuesError: pass else: self.assertTrue(0 ==1, 'Error not thrown error!') file_name2 = tempfile.mktemp(".csv") e1.save(file_name = file_name2) e2 = Exposure(file_name2) returned_values = e2.get_column(new_title) for returned, new in map(None, returned_values, new_values): self.assertTrue(returned == str(new), ' Error!') #self.assertTrue(returned_values == new_values, ' Error!') os.remove(file_name2) try: e1.get_column("toe jam") except TitleValueError: pass else: self.assertTrue(0 ==1, 'Error not thrown error!')
def test_exposure_csv_set_column_get_column_error_checking(self): file_name = tempfile.mktemp(".csv") file = open(file_name, "w", newline="") file.write("LONGITUDE , LATITUDE, sound , speed \n\ 150.916666667, -34.5, splat, 0.0\n\ 150.0, -34.0, pow, 10.0\n") file.close() e1 = Exposure(file_name) os.remove(file_name) new_title = "sound" new_values = [12.5, 7.6] try: e1.set_column(new_title, new_values) except TitleValueError: pass else: self.assertTrue(0 == 1, 'Error not thrown error!') e1.set_column(new_title, new_values, overwrite=True) returned_values = e1.get_column(new_title) self.assertTrue(returned_values == new_values, ' Error!') new2_title = "short list" new2_values = [12.5] try: e1.set_column(new2_title, new2_values) except DataMissingValuesError: pass else: self.assertTrue(0 == 1, 'Error not thrown error!') new2_title = "long list" new2_values = [12.5, 7, 8] try: e1.set_column(new2_title, new2_values) except DataMissingValuesError: pass else: self.assertTrue(0 == 1, 'Error not thrown error!') file_name2 = tempfile.mktemp(".csv") e1.save(file_name=file_name2) e2 = Exposure(file_name2) returned_values = e2.get_column(new_title) for returned, new in zip(returned_values, new_values): self.assertTrue(returned == str(new), ' Error!') #self.assertTrue(returned_values == new_values, ' Error!') os.remove(file_name2) try: e1.get_column("toe jam") except TitleValueError: pass else: self.assertTrue(0 == 1, 'Error not thrown error!')
def test_exposure_csv_loading(self): file_name = tempfile.mktemp(".csv") file = open(file_name, "w", newline="") file.write("LATITUDE, LONGITUDE ,sound , speed \n\ 115.0, -21.0, splat, 0.0\n\ 114.0, -21.7, pow, 10.0\n\ 114.5, -21.4, bang, 40.0\n") file.close() exposure = Exposure(file_name, title_check_list=['speed', 'sound']) exposure.get_column("sound") self.assertTrue(exposure._attribute_dic['sound'][2] == ' bang', 'FAILED!') self.assertTrue(exposure._attribute_dic['speed'][2] == ' 40.0', 'FAILED!') os.remove(file_name)
def test_exposure_csv_loading(self): file_name = tempfile.mktemp(".csv") file = open(file_name,"w") file.write("LATITUDE, LONGITUDE ,sound , speed \n\ 115.0, -21.0, splat, 0.0\n\ 114.0, -21.7, pow, 10.0\n\ 114.5, -21.4, bang, 40.0\n") file.close() exposure = Exposure(file_name, title_check_list = ['speed','sound']) exposure.get_column("sound") self.assertTrue(exposure._attribute_dic['sound'][2]==' bang', 'FAILED!') self.assertTrue(exposure._attribute_dic['speed'][2]==' 40.0', 'FAILED!') os.remove(file_name)
def test_exposure_csv_set_column_get_column(self): file_name = tempfile.mktemp(".csv") file = open(file_name, "w", newline="") file.write("LONGITUDE , LATITUDE, sound , speed \n\ 150.916666667, -34.5, splat, 0.0\n\ 150.0, -34.0, pow, 10.0\n") file.close() e1 = Exposure(file_name) os.remove(file_name) new_title = "feast" new_values = ["chicken", "soup"] e1.set_column(new_title, new_values) returned_values = e1.get_column(new_title) self.assertTrue(returned_values == new_values, ' Error!') file_name2 = tempfile.mktemp(".csv") e1.save(file_name=file_name2) e2 = Exposure(file_name2) returned_values = e2.get_column(new_title) self.assertTrue(returned_values == new_values, ' Error!') os.remove(file_name2)
def test_exposure_csv_set_column_get_column(self): file_name = tempfile.mktemp(".csv") file = open(file_name,"w") file.write("LONGITUDE , LATITUDE, sound , speed \n\ 150.916666667, -34.5, splat, 0.0\n\ 150.0, -34.0, pow, 10.0\n") file.close() e1 = Exposure(file_name) os.remove(file_name) new_title = "feast" new_values = ["chicken","soup"] e1.set_column(new_title, new_values) returned_values = e1.get_column(new_title) self.assertTrue(returned_values == new_values, ' Error!') file_name2 = tempfile.mktemp(".csv") e1.save(file_name = file_name2) e2 = Exposure(file_name2) returned_values = e2.get_column(new_title) self.assertTrue(returned_values == new_values, ' Error!') os.remove(file_name2)