class TestWellMarkerClass(unittest.TestCase): """ a unittest for WellMarker class """ def setUp(self): # type: () -> None """ Initialise a temporary database connection for all test cases and fill the database with test data :return: None """ # initialise a in-memory sqlite database self.handler = DBHandler(connection="sqlite://", echo=False) self.session = self.handler.get_session() # add test data to the database self.wells = [ { "name": "Well_1", "short_name": "W1", "comment": "A drilled well", "east": 1234.56, "north": 123.45, "altitude": 10.5, "depth": 555, "marker": ((10, "mu", 4, ""), (15, "so", 3, "Comment 1"), (16, "sm", 2, ""), (17, "su", 1, "Comment 2"), (5, "mm", 5, "Comment 3")) }, { "name": "Well_2", "short_name": "W2", "comment": "", "east": 1000.23, "north": 2300.34, "altitude": 342.23, "depth": 341, "marker": ((12, "mo", 6, ""), (120, "mm", 5, "Comment 1"), (300, "Fault", 0, "Comment 2"), (320, "mo", 6, "")) }, { "name": "Well_3", "short_name": "W3", "comment": "A third well", "east": 3454.34, "north": 2340.22, "altitude": 342.20, "depth": 645.21, "marker": ((34, "mu", 4, ""), (234, "so", 3, "Comment 1"), (345, "Fault", 0, "Comment 2"), (635, "mu", 4, "Comment 3")) } ] for well in self.wells: new_well = Well(well["name"], well["short_name"], well["depth"], "spatial_reference_unknown", well["east"], well["north"], well["altitude"], self.session, "well_set", well["comment"]) new_well.save_to_db() for mark in well["marker"]: new_well.marker.append( WellMarker(mark[0], StratigraphicObject.init_stratigraphy(self.session, mark[1], mark[2], False), self.session, well["name"], mark[3])) new_well.marker[-1].save_to_db() def test_WellMarker_init(self): # type: () -> None """ Test the initialisation of the database :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ marker = self.session.query(WellMarker).all() self.assertEqual(len(marker), 13) self.assertEqual(marker[3].horizon.statigraphic_name, "su") self.assertEqual(marker[4].horizon.statigraphic_name, "mm") def test_WellMarker_setter_and_getter(self): # type: () -> None """ Test setter and getter functionality :return: Nothing :raises AssertionError: Raises Assertion Error if a test fails """ marker = WellMarker.load_all_from_db(self.session) self.assertEqual(len(marker), 13) test_string = "abcdefghijklmnopqrstuvwxyz1234567890" # first part: test setter functionality marker[0].comment = "This is a new comment" marker[1].comment = 4 * test_string marker[2].depth = 123.43 marker[3].depth = "2345.54" with (self.assertRaises(ValueError)): marker[4].depth = "Test" marker[4].horizon = StratigraphicObject.init_stratigraphy(self.session, "z", 50, False) with (self.assertRaises(TypeError)): marker[5].horizon = "test" # second part: getter functionality marker = WellMarker.load_all_from_db(self.session) self.assertEqual(marker[0].comment, "This is a new comment") self.assertEqual(len(marker[1].comment), 100) self.assertEqual(marker[3].comment, "Comment 2") self.assertEqual(marker[2].depth, 123.43) self.assertEqual(marker[1].depth, 15) self.assertEqual(marker[4].horizon.statigraphic_name, "z") self.assertEqual(marker[5].horizon.statigraphic_name, "mo") def test_WellMarker_to_GeoPoint(self): # type: () -> None """ Test WellMarker.to_GeoPoint functionality :return: Nothing :raises AssertionError: Raises Assertion Error if a test fails """ marker = WellMarker.load_all_from_db(self.session)[0] point = marker.to_geopoint() self.assertEqual(point.easting, 1234.56) self.assertEqual(point.northing, 123.45) self.assertEqual(point.altitude, 0.5) self.assertEqual(point.name, "Well_1") self.assertEqual(point.horizon.statigraphic_name, "mu") def tearDown(self): # type: () -> None """ Close session after testruns :return: Nothing """ self.handler.close_last_session()
class TestPropertyClass(unittest.TestCase): """ a unittest for Property class """ def setUp(self): # type: () -> None """ Initialise a temporary database connection for all test cases and fill the database with test data :return: None """ # initialise a in-memory sqlite database self.handler = DBHandler(connection="sqlite://", echo=False) self.session = self.handler.get_session() # add test data to the database point = GeoPoint(StratigraphicObject.init_stratigraphy(self.session, "mu", 1), True, "", 1, 2, 3, self.session, "test", "") point.save_to_db() point.add_property(Property(0, PropertyTypes.INT, "test prop", "test unit", self.session)) point.add_property(Property(0, PropertyTypes.FLOAT, "test prop 2", "test unit 2", self.session)) point.add_property(Property(0, PropertyTypes.STRING, "test prop 3", "test unit 3", self.session)) def test_init(self): # type: () -> None """ Test the initialisation of the class :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ point = GeoPoint.load_all_from_db(self.session)[0] self.assertEqual(3, len(point.properties)) self.assertEqual("test prop", point.properties[0].property_name) self.assertEqual("test prop 2", point.properties[1].property_name) self.assertEqual("test prop 3", point.properties[2].property_name) self.assertEqual("test unit", point.properties[0].property_unit) self.assertEqual("test unit 2", point.properties[1].property_unit) self.assertEqual("test unit 3", point.properties[2].property_unit) self.assertEqual(PropertyTypes.INT, point.properties[0].property_type) self.assertEqual(PropertyTypes.FLOAT, point.properties[1].property_type) self.assertEqual(PropertyTypes.STRING, point.properties[2].property_type) def test_setter_and_getter(self): # type: () -> None """ Test the setter and getter functionality :return: Nothing :raises AssertionError: Raises Assertion Error when a test fails """ point = GeoPoint.load_all_from_db(self.session)[0] point.properties[0].property_value = 342 point.properties[1].property_value = "345.34" point.properties[2].property_value = "Test" point.properties[1].name = "some text information" point.properties[1].comment = "unused" point.properties[2].property_type = PropertyTypes.FLOAT with self.assertRaises(ValueError): point.properties[0].property_value = "string" with self.assertRaises(ValueError): point.properties[0].property_value = 234.34 del point point = GeoPoint.load_all_from_db(self.session)[0] self.assertEqual(342, point.properties[0].property_value) self.assertEqual(345.34, point.properties[1].property_value) self.assertEqual(None, point.properties[2].property_value) # type changed to PropertyTypes.FLOAT point.properties[2].property_type = PropertyTypes.STRING self.assertEqual("Test", point.properties[2].property_value) self.assertEqual("some text information", point.properties[1].name) self.assertEqual("unused", point.properties[1].comment) def tearDown(self): # type: () -> None """ Close session after testruns :return: Nothing """ self.handler.close_last_session()
class TestWellClass(unittest.TestCase): """ a unittest for Well class """ def setUp(self): # type: () -> None """ Initialise a temporary database connection for all test cases and fill the database with test data :return: None """ # initialise a in-memory sqlite database # self.handler = DBHandler(connection="sqlite:///D:\\data.db", echo=False) self.handler = DBHandler(connection="sqlite://", echo=False) # self.handler = DBHandler(connection="mysql://*****:*****@localhost:3306/stdonn") self.session = self.handler.get_session() # add test data to the database self.wells = [ { "name" : "Well_1", "short_name": "W1", "comment" : "A drilled well", "east" : 1234.56, "north" : 123.45, "altitude" : 10.5, "depth" : 555, "marker" : ((10, "mu", 4, ""), (15, "so", 3, "Comment 1"), (16, "sm", 2, ""), (17, "su", 1, "Comment 2"), (5, "mm", 5, "Comment 3")) }, { "name" : "Well_2", "short_name": "W2", "comment" : "", "east" : 1000.23, "north" : 2300.34, "altitude" : 342.23, "depth" : 341, "marker" : ((12, "mo", 6, ""), (120, "mm", 5, "Comment 1"), (300, "Fault", 0, "Comment 2"), (320, "mo", 6, "")) }, { "name" : "Well_3", "short_name": "W3", "comment" : "A third well", "east" : 3454.34, "north" : 2340.22, "altitude" : 342.20, "depth" : 751.13, "marker" : ((34, "mu", 4, ""), (234, "so", 3, "Comment 1"), (345, "Fault", 0, "Comment 2"), (635, "mu", 4, "Comment 3"), (636, "Fault", 0, ""), (645, "mu", 4, ""), (665, "Fault", 0, ""), (699, "so", 3, "Comment 1")) }, { "name" : "Well_4", "short_name": "W4", "comment" : "A fourth well", "east" : 234, "north" : 5645.45, "altitude" : 234.63, "depth" : 645.21, "marker" : ((34, "mu", 4, ""), (65, "so", 3, "Comment 1"), (70, "Fault", 0, "Comment 2"), (85, "so", 3, "Comment 1"), (105, "mu", 4, ""), (123, "mu", 4, ""), (201, "so", 3, "Comment 1")) } ] for well in self.wells: new_well = Well(well["name"], well["short_name"], well["depth"], "spatial_reference_unknown", well["east"], well["north"], well["altitude"], self.session, "well_set", well["comment"]) new_well.save_to_db() for mark in well["marker"]: new_well.marker.append(WellMarker(mark[0], StratigraphicObject.init_stratigraphy(self.session, mark[1], mark[2], False), self.session, well["name"], mark[3])) new_well.marker[-1].save_to_db() def test_well_markers_to_thickness(self): # type: () -> None """ Tests the Requests.well_markers_to_thickness(...) function :return: Nothing :raises AssertionError: if a test fails """ result = Requests.well_markers_to_thickness(self.session, "mu", "so", summarise_multiple=False, use_faulted=False, fault_name="Fault", extent=None) self.assertEqual(len(result), 4) self.assertTrue(result[0].has_property("thickness")) self.assertFalse(result[0].has_property("faulted")) self.assertFalse(result[0].has_property("summarised")) self.assertEqual(result[0].get_property("thickness").property_value, 5) self.assertEqual(result[1].get_property("thickness").property_value, 200) self.assertEqual(result[2].get_property("thickness").property_value, 31) self.assertEqual(result[3].get_property("thickness").property_value, 78) self.assertEqual(result[0].easting, 1234.56) self.assertEqual(result[0].northing, 123.45) self.assertEqual(result[0].altitude, 10.5 - 10) self.assertEqual(result[0].name, "Well_1") self.assertEqual(result[1].name, "Well_3") self.assertEqual(result[2].name, "Well_4") self.assertEqual(result[3].name, "Well_4") del result result = Requests.well_markers_to_thickness(self.session, "mu", "so", summarise_multiple=False, use_faulted=True, extent=None) self.assertEqual(len(result), 5) self.assertTrue(result[0].has_property("thickness")) self.assertTrue(result[0].has_property("faulted")) self.assertFalse(result[0].has_property("summarised")) self.assertEqual(result[0].get_property("thickness").property_value, 5) self.assertEqual(result[0].get_property("faulted").property_value, 0) self.assertEqual(result[1].get_property("thickness").property_value, 200) self.assertEqual(result[1].get_property("faulted").property_value, 0) self.assertEqual(result[2].get_property("thickness").property_value, 54) self.assertEqual(result[2].get_property("faulted").property_value, 1) self.assertEqual(result[3].get_property("thickness").property_value, 31) self.assertEqual(result[3].get_property("faulted").property_value, 0) self.assertEqual(result[4].get_property("thickness").property_value, 78) self.assertEqual(result[4].get_property("faulted").property_value, 0) self.assertEqual(result[0].name, "Well_1") self.assertEqual(result[1].easting, 3454.34) self.assertEqual(result[1].northing, 2340.22) self.assertEqual(result[1].altitude, 342.20 - 34) self.assertEqual(result[1].name, "Well_3") self.assertEqual(result[2].altitude, 342.20 - 645) self.assertEqual(result[2].name, "Well_3") self.assertEqual(result[3].name, "Well_4") self.assertEqual(result[4].name, "Well_4") del result result = Requests.well_markers_to_thickness(self.session, "mu", "so", summarise_multiple=True, use_faulted=False, fault_name="Fault", extent=None) self.assertEqual(len(result), 1) self.assertTrue(result[0].has_property("thickness")) self.assertFalse(result[0].has_property("faulted")) self.assertTrue(result[0].has_property("summarised")) self.assertEqual(result[0].get_property("thickness").property_value, 5) self.assertEqual(result[0].get_property("summarised").property_value, 0) self.assertEqual(result[0].easting, 1234.56) self.assertEqual(result[0].northing, 123.45) self.assertEqual(result[0].altitude, 10.5 - 10) self.assertEqual(result[0].name, "Well_1") del result result = Requests.well_markers_to_thickness(self.session, "mu", "so", summarise_multiple=True, use_faulted=True, extent=None) self.assertEqual(len(result), 3) self.assertTrue(result[0].has_property("thickness")) self.assertTrue(result[0].has_property("faulted")) self.assertTrue(result[0].has_property("summarised")) self.assertEqual(result[0].get_property("thickness").property_value, 5) self.assertEqual(result[0].get_property("faulted").property_value, 0) self.assertEqual(result[0].get_property("summarised").property_value, 0) self.assertEqual(result[1].get_property("thickness").property_value, 665) self.assertEqual(result[1].get_property("faulted").property_value, 3) self.assertEqual(result[1].get_property("summarised").property_value, 1) self.assertEqual(result[2].get_property("thickness").property_value, 167) self.assertEqual(result[2].get_property("faulted").property_value, 1) self.assertEqual(result[2].get_property("summarised").property_value, 1) self.assertEqual(result[0].name, "Well_1") self.assertEqual(result[1].name, "Well_3") self.assertEqual(result[2].name, "Well_4") self.assertEqual(result[2].easting, 234) self.assertEqual(result[2].northing, 5645.45) self.assertEqual(result[2].altitude, 234.63 - 34) del result extent = [1000, 1500, 0, 3000] # Well_1 and Well_2, 1 marker from Well_1 result = Requests.well_markers_to_thickness(self.session, "mu", "so", summarise_multiple=True, use_faulted=True, extent=extent) self.assertEqual(len(result), 1) self.assertEqual(result[0].name, "Well_1") del result extent = [1000, 1500, 2000, 3000] # only Well_2, no marker result = Requests.well_markers_to_thickness(self.session, "mu", "so", summarise_multiple=True, use_faulted=True, extent=extent) self.assertEqual(len(result), 0) del result extent = [0, 500, 5000, 6000] # only Well_4 result = Requests.well_markers_to_thickness(self.session, "mu", "so", summarise_multiple=False, use_faulted=True, extent=extent) self.assertEqual(len(result), 2) self.assertEqual(result[0].name, "Well_4") self.assertTrue(result[0].has_property("thickness")) self.assertEqual(result[0].get_property("thickness").property_value, 31) self.assertEqual(result[1].name, "Well_4") self.assertTrue(result[1].has_property("thickness")) self.assertEqual(result[1].get_property("thickness").property_value, 78) del result # test failures and exceptions """ :raises AttributeError: if marker_1 and marker_2 are equal :raises DatabaseException: if the database query results in less than 2 marker of a well_id :raises DatabaseRequestException: if an unexpected query result occurs :raises FaultException: if a fault is inside the section and use_faulted is False :raises TypeError: if session is not an instance of SQLAlchemy session :raises ValueError: if a parameter is not compatible with the required type """ self.assertRaises(AttributeError, Requests.well_markers_to_thickness, self.session, "mu", "mu", summarise_multiple=False, use_faulted=True, extent=None) self.assertRaises(TypeError, Requests.well_markers_to_thickness, "wrong type", "mu", "so", summarise_multiple=False, use_faulted=True, extent=None) self.assertRaises(TypeError, Requests.well_markers_to_thickness, self.session, "mu", "so", summarise_multiple=False, use_faulted=True, extent="ab") self.assertRaises(ValueError, Requests.well_markers_to_thickness, self.session, "mu", "so", summarise_multiple=False, use_faulted=True, extent=[1,2,3]) self.assertRaises(ValueError, Requests.well_markers_to_thickness, self.session, "mu", "so", summarise_multiple=False, use_faulted=True, extent=[1, 2, 3, "ab"]) def tearDown(self): # type: () -> None """ Close session after testruns :return: Nothing """ self.handler.close_last_session()
class TestLineClass(unittest.TestCase): """ This is a unittest class for the Resources.Geometries.Line class """ def setUp(self): # type: () -> None """ Initialise a temporary database connection for all test cases and fill the database with test data :return: None """ # initialise a in-memory sqlite database self.handler = DBHandler(connection="sqlite://", echo=False) self.session = self.handler.get_session() # handler = DBHandler( # connection="sqlite:////Users/stephan/Documents/data.db", # debug=False) # handler = DBHandler(connection="sqlite:///D:\\data.db", debug=False) # add test data to the database self.lines = [{ "closed": False, "horizon": "mu", "age": 3, "update": False, "points": ((1204067.0548148106, 634617.5980860253), (1204067.0548148106, 620742.1035724243), (1215167.4504256917, 620742.1035724243), (1215167.4504256917, 634617.5980860253), (1204067.0548148106, 634617.5980860253)), "name": "Line_1" }, { "closed": True, "horizon": "so", "age": 2, "update": True, "points": ((1179553.6811741155, 647105.5431482664), (1179553.6811741155, 626292.3013778647), (1194354.20865529, 626292.3013778647), (1194354.20865529, 647105.5431482664)), "name": "Line_2" }, { "closed": False, "horizon": "mm", "age": 4, "update": True, "points": ((1179091.1646903288, 712782.8838459781), (1161053.0218226474, 667456.2684348812), (1214704.933941905, 641092.8288590391), (1228580.428455506, 682719.3123998424), (1218405.0658121984, 721108.1805541387)), "name": "Line_3" }, { "closed": False, "horizon": "mo", "age": 5, "update": True, "points": ((1149490.1097279799, 691044.6091080031), (1149490.1097279799, 648030.5761158396), (1191579.1097525698, 648030.5761158396), (1149490.1097279799, 648030.5761158396), (1191579.1097525698, 691044.6091080031), (1149490.1097279799, 691044.6091080031)), "name": "Line_2" }] for line in self.lines: points = list() for point in line["points"]: points.append( GeoPoint(None, False, "", point[0], point[1], 0, self.session, line["name"], "")) new_line = Line( line["closed"], StratigraphicObject.init_stratigraphy(self.session, line["horizon"], line["age"], line["update"]), points, self.session, line["name"], "") new_line.save_to_db() def test_init(self): # type: () -> None """ Test the initialisation of the database :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ pnts = 0 for line in self.lines: pnts += len(line["points"]) # 2 points will be automatically deleted and the lines will be closed pnts -= 2 count_points = self.session.query(GeoPoint).count() lines = self.session.query(Line) count_lines = lines.count() lines = lines.all() stored_horizons = [ x.unit_name for x in self.session.query(StratigraphicObject.unit_name).all() ] # expected number of horizons horizons = set([x["horizon"] for x in self.lines]) self.assertEqual( count_points, pnts, "Number of points {} doesn't match the number of stored database points {}!" .format(count_points, pnts)) self.assertEqual( count_lines, len(self.lines), "Number of lines {} doesn't match the number of stored database lines {}!" .format(count_lines, len(self.lines))) if sys.version_info[0] == 2: self.assertItemsEqual( horizons, stored_horizons, "Horizons doesn't match.\nDatabase: {}\nShould be: {}".format( stored_horizons, horizons)) else: self.assertCountEqual( horizons, stored_horizons, "Horizons doesn't match.\nDatabase: {}\nShould be: {}".format( stored_horizons, horizons)) self.assertEqual( len(lines[0].points), 4, "Number of points of the line with ID 1 should be {}, but is {}". format(4, len(lines[0].points))) self.assertTrue(lines[0].is_closed, "line with ID 1 should be closed...") self.assertEqual( len(lines[1].points), 4, "Number of points of the line with ID 2 should be {}, but is {}". format(4, len(lines[1].points))) self.assertTrue(lines[1].is_closed, "line with ID 2 should be closed...") self.assertEqual( len(lines[2].points), 5, "Number of points of the line with ID 3 should be {}, but is {}". format(5, len(lines[2].points))) self.assertFalse(lines[2].is_closed, "line with ID 3 should not be closed...") self.assertEqual( len(lines[3].points), 5, "Number of points of the line with ID 4 should be {}, but is {}". format(5, len(lines[3].points))) self.assertTrue(lines[3].is_closed, "line with ID 4 should be closed...") def test_insert_one(self): # type: () -> None """ Test the insertion of one point. Additionally test get_point_index(point) function :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ insert_point = GeoPoint( StratigraphicObject.init_stratigraphy(self.session, "mu"), False, "", 1204200, 620800, 0, self.session) line_query = self.session.query(Line).filter_by(id=1) count = line_query.count() self.assertEqual( count, 1, "Get more than one expected result for line-id-request ({})". format(count)) line = line_query.one() line.session = self.session line.insert_point(insert_point, 1) self.assertEqual(line.points[1].line_pos, 1) # point is inserted, now delete insert details del count del line del line_query # test the insertion-process line_query = self.session.query(Line).filter_by(id=1) count = line_query.count() self.assertEqual( count, 1, "Get more than one expected result for line-id-request ({})". format(count)) line = line_query.one() # 20 Point initially, 2 removed, new point is Nr 19 -> id=19 # !!!ATTENTION!!! counting starts with 1 not 0 in sqlite-DB! # line-pos and get_point_index should be 1 self.assertEqual( line.points[1].id, 19, "Wrong id ({}) for new point (should be {})".format( line.points[1].id, 19)) self.assertEqual( line.points[1].line_pos, 1, "Wrong position of the new point ({}) in the line (should be {})". format(line.points[1].line_pos, 1)) self.assertEqual( line.get_point_index(insert_point), 1, "Wrong get_point_index(...) value ({}) in the line (should be {})". format(line.get_point_index(insert_point), 1)) self.assertEqual( line.points[1].easting, 1204200, "Wrong easting ({} / should be {})".format(line.points[1].easting, 1204200)) self.assertEqual( line.points[1].northing, 620800, "Wrong northing ({} / should be {})".format( line.points[1].northing, 620800)) self.assertEqual( line.points[1].altitude, 0, "Wrong altitude ({} / should be {})".format( line.points[1].altitude, 0)) self.assertEqual( line.points[1].has_z, False, "Wrong has_z ({} / should be {})".format(line.points[1].has_z, False)) # test Exception handling self.assertRaises(TypeError, line.insert_point, "string", 1) self.assertRaises(ValueError, line.insert_points, insert_point, "abc") def test_insert_multiple(self): # type: () -> None """ Test the insertion of multiple points. Although test remove of doubled values in a line. :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ insert_point_1 = GeoPoint( StratigraphicObject.init_stratigraphy(self.session, "mu"), False, "", 1204200, 620800, 0, self.session) insert_point_2 = GeoPoint( StratigraphicObject.init_stratigraphy(self.session, "mu"), False, "", 1204500, 621200, 0, self.session) insert_point_3 = GeoPoint( StratigraphicObject.init_stratigraphy(self.session, "mu"), False, "", 1204700, 621000, 0, self.session) insert_point_4 = GeoPoint( StratigraphicObject.init_stratigraphy(self.session, "mu"), False, "", 1204700, 621000, 0, self.session) points = [ insert_point_1, insert_point_2, insert_point_3, insert_point_4 ] line_query = self.session.query(Line).filter_by(id=1) count = line_query.count() self.assertEqual( count, 1, "Get more than one expected result for line-id-request ({})". format(count)) line = line_query.one() line.session = self.session line.insert_points(points, 1) line.save_to_db() # point is inserted, now delete insert details del count del insert_point_1, insert_point_2, insert_point_3 del line del line_query # test the insertion-process line_query = self.session.query(Line).filter_by(id=1) count = line_query.count() self.assertEqual( count, 1, "Get more than one expected result for line-id-request ({})". format(count)) line = line_query.one() # 20 Point initially, 2 removed, new point are Nr 19-21 -> id=19 to 21 # !!!ATTENTION!!! counting starts with 1 not 0 in sqlite-DB! # line-pos should be 1, 2 and 3 self.assertEqual( line.points[1].id, 19, "Wrong id ({}) for new point (should be {})".format( line.points[1].id, 19)) self.assertEqual( line.points[2].id, 20, "Wrong id ({}) for new point (should be {})".format( line.points[2].id, 20)) self.assertEqual( line.points[3].id, 21, "Wrong id ({}) for new point (should be {})".format( line.points[3].id, 21)) self.assertEqual( line.points[4].id, 2, "Wrong id ({}) for point after insert (should be {})".format( line.points[4].id, 2)) self.assertEqual( line.points[1].line_pos, 1, "Wrong position of the new point ({}) in the line (should be {})". format(line.points[1].line_pos, 1)) self.assertEqual( line.points[2].line_pos, 2, "Wrong position of the new point ({}) in the line (should be {})". format(line.points[2].line_pos, 2)) self.assertEqual( line.points[3].line_pos, 3, "Wrong position of the new point ({}) in the line (should be {})". format(line.points[3].line_pos, 3)) self.assertEqual( line.points[1].easting, 1204200, "Wrong easting ({} / should be {})".format(line.points[1].easting, 1204200)) self.assertEqual( line.points[1].northing, 620800, "Wrong northing ({} / should be {})".format( line.points[1].northing, 620800)) self.assertEqual( line.points[1].altitude, 0, "Wrong altitude ({} / should be {})".format( line.points[1].altitude, 0)) self.assertEqual( line.points[1].has_z, False, "Wrong has_z ({} / should be {})".format(line.points[1].has_z, False)) # test Exception handling self.assertRaises(ValueError, line.insert_points, points, "abc") points.append("cde") self.assertRaises(TypeError, line.insert_points, points, 2) def test_delete_point(self): # type: () -> None """ Test the deletion of a point. /1/ the point itself /2/ delete by coordinates /3/ test auto-removal of doubled points after deletion :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ line_query = self.session.query(Line).filter_by(id=2) count = line_query.count() self.assertEqual( count, 1, "Get more than one expected result for line-id-request ({})". format(count)) line = line_query.one() line.session = self.session line.delete_point(line.points[2]) # save deletion and reload line, test afterwards line.save_to_db() del count del line del line_query line = self.session.query(Line).filter_by(id=2).one() self.assertEqual( len(line.points), 3, "Wrong Nr of points ({}), should be {}".format( len(line.points), 3)) # test exception handling self.assertRaises(TypeError, line.delete_point, "string") self.assertRaises( ValueError, line.delete_point, GeoPoint(None, False, "", 1, 2, 0, self.session, "", "")) del line # /2/ test deletion by coordinates line_query = self.session.query(Line).filter_by(id=3) count = line_query.count() self.assertEqual( count, 1, "Get more than one expected result for line-id-request ({})". format(count)) line = line_query.one() line.session = self.session line.delete_point_by_coordinates(1214704.933941905, 641092.8288590391, 0) # save deletion and reload line, test afterwards line.save_to_db() del count del line del line_query line = self.session.query(Line).filter_by(id=3).one() self.assertEqual( len(line.points), 4, "Wrong Nr of points ({}), should be {}".format( len(line.points), 4)) self.assertEqual( line.points[1].id, 10, "First point before deleted point should have id {} but has {}". format(10, line.points[1].id)) self.assertEqual( line.points[2].id, 12, "First point after deleted point should have id {} but has {}". format(12, line.points[2].id)) # test exception handling self.assertRaises(ValueError, line.delete_point_by_coordinates, 123, 456, "test") self.assertRaises(ValueError, line.delete_point_by_coordinates, 123, 456, 789) # /3/ test auto-removal of doubled points after deletion line_query = self.session.query(Line).filter_by(id=4) count = line_query.count() self.assertEqual( count, 1, "Get more than one expected result for line-id-request ({})". format(count)) line = line_query.one() line.session = self.session line.delete_point_by_coordinates(1191579.1097525698, 648030.5761158396, 0) # save deletion and reload line, test afterwards line.save_to_db() del count del line del line_query line = self.session.query(Line).filter_by(id=4).one() self.assertEqual( len(line.points), 3, "Wrong Nr of points ({}), should be {}".format( len(line.points), 3)) self.assertEqual( line.points[1].id, 15, "First point before deleted point should have id {} but has {}". format(15, line.points[1].id)) self.assertEqual( line.points[2].id, 18, "First point after deleted point should have id {} but has {}". format(18, line.points[2].id)) def test_loading(self): # type: () -> None """ Test the different types of loading of lines from the db. Part 1: load all lines from the database Part 2: load line by id Part 3: load lines by ame Part 4: load lines with minimal one point in given extent :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ # Part 1: load all lines from the database lines = Line.load_all_from_db(self.session) self.assertEqual( len(lines), 4, "Wrong number of lines ({}), should be {}".format(len(lines), 4)) self.assertEqual( lines[0].id, 1, "First line has wrong id ({}), should be {}".format( lines[0].id, 1)) self.assertEqual(len(lines[0].points), 4, "Number of points ({}) of the first line is wrong. Should be {}". \ format(len(lines[0].points), 4)) self.assertEqual( lines[3].id, 4, "First line has wrong id ({}), should be {}".format( lines[3].id, 4)) self.assertEqual(len(lines[3].points), 5, "Number of points ({}) of the first line is wrong. Should be {}". \ format(len(lines[3].points), 5)) # test exception handling self.assertRaises(TypeError, Line.load_all_from_db, "test") del lines # Part 2: load line by id line = Line.load_by_id_from_db(2, self.session) self.assertEqual( line.id, 2, "line id is wrong ({}), should be {}".format(line.id, 2)) self.assertEqual(len(line.points), 4, "Number of points ({}) of the line with id=2 is wrong. Should be {}". \ format(len(line.points), 4)) self.assertEqual(line.points[0].id, 5, "first point in line with id=2 should have id {}, is {}". \ format(5, line.points[0].id)) self.assertEqual(line.points[-1].id, 8, "last point in line with id=2 should have id {}, is {}". \ format(8, line.points[-1].id)) # test exception handling self.assertRaises(DatabaseRequestException, Line.load_by_id_from_db, 25, self.session) del line # Part 3: load lines by name lines = Line.load_by_name_from_db("Line_3", self.session) self.assertEqual( len(lines), 1, "Wrong number of lines ({}), should be {}".format(len(lines), 1)) self.assertEqual( lines[0].id, 3, "Returned line has wrong id ({}), should be {}".format( lines[0].id, 3)) del lines lines = Line.load_by_name_from_db("Line_2", self.session) self.assertEqual( len(lines), 2, "Wrong number of lines ({}), should be {}".format(len(lines), 2)) self.assertEqual( lines[0].id, 2, "Returned line has wrong id ({}), should be {}".format( lines[0].id, 2)) self.assertEqual( lines[1].id, 4, "Returned line has wrong id ({}), should be {}".format( lines[0].id, 4)) del lines lines = Line.load_by_name_from_db("Test", self.session) self.assertEqual( len(lines), 0, "Wrong number of lines ({}), should be {}".format(len(lines), 0)) del lines # Part 4: load lines with minimal one point in given extent # x -> 1174000 - 1200000 # y -> 613500 - 651000 # should return 2 lines with id 2 and 4 ("Line_2") lines = Line.load_in_extent_from_db(self.session, 1174000, 1200000, 613500, 651000) self.assertEqual( len(lines), 2, "Wrong number of lines ({}), should be {}".format(len(lines), 2)) self.assertEqual( lines[0].id, 2, "Returned line has wrong id ({}), should be {}".format( lines[0].id, 2)) self.assertEqual( lines[1].id, 4, "Returned line has wrong id ({}), should be {}".format( lines[0].id, 4)) del lines lines = Line.load_in_extent_from_db(self.session, 0, 1, 0, 1) self.assertEqual( len(lines), 0, "Wrong number of lines ({}), should be {}".format(len(lines), 9)) del lines def test_setter_and_getter(self): # type: () -> None """ Test the setter and getter functions of class Line :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ lines = Line.load_all_from_db(self.session) lines[0].is_closed = True lines[1].horizon = StratigraphicObject.init_stratigraphy( self.session, "mu") lines[2].name = "Line_2" session_2 = lines[3].session lines[3].session = session_2 for line in lines: line.save_to_db() del lines lines = Line.load_all_from_db(self.session) line_with_name = Line.load_by_name_from_db("Line_2", self.session) self.assertTrue(lines[0].is_closed, "First line should be changed to closed.") self.assertEqual( lines[1].horizon.statigraphic_name, "mu", "Second line has wrong horizon ({}). Should have {}.".format( lines[1].horizon.statigraphic_name, "mu")) self.assertEqual( lines[2].name, "Line_2", "Third line has wrong line name ({}). Should have {}".format( lines[2].name, "Line_2")) self.assertEqual(len(line_with_name), 3, "Wrong Number of lines with line name 'Line_2' ({}). Should be {}". \ format(len(line_with_name), 3)) def tearDown(self): # type: () -> None """ Close session after testruns :return: Nothing """ self.handler.close_last_session() if __name__ == "__main__": unittest.main()
class TestStratigraphyClass(unittest.TestCase): def setUp(self): # type: () -> None """ Initialise a temporary database connection for all test cases and fill the database with test data :return: None """ # initialise a in-memory sqlite database self.handler = DBHandler(connection='sqlite://', echo=False) self.session = self.handler.get_session() units = [{ 'statigraphic_name': 'mo', 'age': 1, 'update': False }, { 'statigraphic_name': 'mm', 'age': 2, 'update': True }, { 'statigraphic_name': 'mu', 'age': 25, 'update': False }, { 'statigraphic_name': 'so', 'age': 4, 'update': False }, { 'statigraphic_name': 'mu', 'age': 3, 'update': True }, { 'statigraphic_name': 'so', 'age': 5, 'update': False }] for unit in units: new_unit = StratigraphicObject.init_stratigraphy( self.session, unit['statigraphic_name'], unit['age'], unit['update']) new_unit.save_to_db() def test_init(self): # type: () -> None """ Test the initialisation :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ result = self.session.query(StratigraphicObject).all() self.assertEqual( len(result), 4, "Wrong number of entries ({}). Should be {}.".format( len(result), 4)) def test_loading(self): # type: () -> None """ Test the loading functions of the stratigraphy class /1/ load all from database /2/ load by statigraphic_name from database /3/ load in age range from database :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ # /1/ load all from database # additionally update value is tested for mu / so unit result = { unit.statigraphic_name: unit for unit in StratigraphicObject.load_all_from_db(self.session) } self.assertEqual( len(result), 4, "Wrong number of entries ({}). Should be {}.".format( len(result), 4)) self.assertEqual( result['mu'].age, 3, "Wrong age for mu ({}). Should be {}".format(result['mu'].age, 3)) self.assertEqual( result['so'].age, 4, "Wrong age for so ({}). Should be {}".format(result['so'].age, 4)) del result # /2/ load by statigraphic_name from database result = StratigraphicObject.load_by_stratigraphic_name_from_db( 'mo', self.session) self.assertEqual( result.age, 1, "Wrong age for mo ({}). Should be {}".format(result.age, 3)) del result result = StratigraphicObject.load_by_stratigraphic_name_from_db( 'sm', self.session) self.assertIsNone( result, 'Result for sm is not None, but should be: {}'.format(str(result))) del result # /3/ load in age range from database result = StratigraphicObject.load_by_age_from_db(2, 3, self.session) self.assertEqual( len(result), 2, "Wrong number of query results ({}). Should be {}.".format( len(result), 2)) self.assertEqual( result[0].statigraphic_name, 'mm', "Wrong statigraphic_name of first horizon ({}). Should be {}.". format(result[0], 'mm')) self.assertEqual( result[1].statigraphic_name, 'mu', "Wrong statigraphic_name of second horizon ({}). Should be {}.". format(result[1], 'mu')) self.assertEqual( result[1].age, 3, "Wrong age for second horizon ({}). Should be {}.".format( result[1].age, 3)) del result result = StratigraphicObject.load_by_age_from_db(4, 4, self.session) self.assertEqual( len(result), 1, "Wrong number of query results ({}). Should be {}.".format( len(result), 1)) self.assertEqual( result[0].statigraphic_name, 'so', "Wrong statigraphic_name of first horizon ({}). Should be {}.". format(result[0], 'so')) del result result = StratigraphicObject.load_by_age_from_db(5, 10, self.session) self.assertEqual( len(result), 0, "Wrong number of query results ({}). Should be {}.".format( len(result), 0)) def test_setter_and_getter(self): # type: () -> None """ Test setter and getters of class StratigraphicObject :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ result = StratigraphicObject.load_by_stratigraphic_name_from_db( 'mo', self.session) result.age = 10 result.save_to_db() del result result = StratigraphicObject.load_by_stratigraphic_name_from_db( 'mo', self.session) self.assertEqual( result.age, 10, "Wrong age for horizon 'mo' ({}). Should be {}.".format( result.age, 10)) result.statigraphic_name = 'Blubb' result.save_to_db() del result result = StratigraphicObject.load_by_age_from_db(10, 10, self.session) self.assertEqual( len(result), 1, "Wrong number of query results ({}). Should be {}.".format( len(result), 1)) self.assertEqual( result[0].statigraphic_name, 'Blubb', "Wrong statigraphic_name of stratigraphic unit ({}). Should be {}". format(result[0].statigraphic_name, 'Blubb')) def tearDown(self): # type: () -> None """ Close session after testruns :return: Nothing """ self.handler.close_last_session()
class TestGeoPointClass(unittest.TestCase): """ This is a unittest class for the Resources.Geometries.GeoPoint class """ def setUp(self): # type: () -> None """ Initialise a temporary database connection for all test cases and fill the database with test data :return: None """ # initialise a in-memory sqlite database self.handler = DBHandler(connection="sqlite://", echo=False) self.session = self.handler.get_session() # add test data to the database self.points = [{ "coords": (1234134, 5465462, 123), "horizon": "mu", "age": 3, "name": "", "update": False }, { "coords": (1254367, 5443636, 156), "horizon": "so", "age": 23, "name": "", "update": False }, { "coords": (1265469, 5467929, None), "horizon": "sm", "age": 5, "name": "point set", "update": False }, { "coords": (1273456, 5449672, 101), "horizon": "mu", "age": 26, "name": "point set", "update": True }] self.lines = [{ "closed": False, "horizon": "mu", "age": 3, "update": False, "points": ((1204067.0548148106, 634617.5980860253), (1204067.0548148106, 620742.1035724243), (1215167.4504256917, 620742.1035724243), (1215167.4504256917, 634617.5980860253), (1204067.0548148106, 634617.5980860253)), "name": "Line_1" }, { "closed": True, "horizon": "so", "age": 2, "update": True, "points": ((1179553.6811741155, 647105.5431482664), (1179553.6811741155, 626292.3013778647), (1194354.20865529, 626292.3013778647), (1194354.20865529, 647105.5431482664)), "name": "Line_2" }, { "closed": False, "horizon": "mm", "age": 4, "update": True, "points": ((1179091.1646903288, 712782.8838459781), (1161053.0218226474, 667456.2684348812), (1214704.933941905, 641092.8288590391), (1228580.428455506, 682719.3123998424), (1218405.0658121984, 721108.1805541387)), "name": "Line_3" }, { "closed": False, "horizon": "mo", "age": 5, "update": True, "points": ((1149490.1097279799, 691044.6091080031), (1149490.1097279799, 648030.5761158396), (1191579.1097525698, 648030.5761158396), (1149490.1097279799, 648030.5761158396), (1191579.1097525698, 691044.6091080031), (1149490.1097279799, 691044.6091080031)), "name": "Line_2" }] for point in self.points: strat = StratigraphicObject.init_stratigraphy( self.session, point["horizon"], point["age"], point["update"]) new_point = GeoPoint( strat, False if (point["coords"][2] is None) else True, "", point["coords"][0], point["coords"][1], 0 if (point["coords"][2] is None) else point["coords"][2], self.session, point["name"], "") new_point.save_to_db() for line in self.lines: points = list() for point in line["points"]: points.append( GeoPoint(None, False, "", point[0], point[1], 0, self.session, line["name"], "")) new_line = Line( line["closed"], StratigraphicObject.init_stratigraphy(self.session, line["horizon"], line["age"], line["update"]), points, self.session, line["name"], "") new_line.save_to_db() def test_init(self): # type: () -> None """ Test the initialisation of the database :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ pnts = len(self.points) for line in self.lines: pnts += len(line["points"]) # 2 points will be automatically deleted and the lines will be closed pnts -= 2 points = self.session.query(GeoPoint) count_points = points.count() points = points.all() stored_horizons = self.session.query(StratigraphicObject).all() stored_horizons = [x.statigraphic_name for x in stored_horizons] # expected number of horizons horizons = set([x["horizon"] for x in self.lines] + [x["horizon"] for x in self.points]) # for point in points: # print(str(point)) self.assertEqual( count_points, pnts, "Number of points {} doesn't match the number of stored database points {}!" .format(count_points, pnts)) if sys.version_info[0] == 2: self.assertItemsEqual( horizons, stored_horizons, "Horizons doesn't match.\nDatabase: {}\nShould be: {}".format( stored_horizons, horizons)) else: self.assertCountEqual( horizons, stored_horizons, "Horizons doesn't match.\nDatabase: {}\nShould be: {}".format( stored_horizons, horizons)) self.assertEqual( points[0].id, 1, "Wrong ID {} for first point. Should be {}".format( points[0].id, 1)) self.assertEqual( points[0].horizon.statigraphic_name, "mu", "Wrong name of stratigraphic unit ({}) of first point. Should be ". format(points[0].horizon.statigraphic_name, "mu")) self.assertEqual( points[0].horizon.age, 26, "Wrong age for stratigraphic unit ({}) of first point. Should be {}" .format(points[0].horizon.age, 26)) def test_loading(self): # type: () -> None """ Test the loading functions of the GeoPoint class /1/ load all from database /2/ load by name /3/ load in extent :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ # /1/ load all from database points = GeoPoint.load_all_from_db(self.session) pnts_count = len(self.points) for line in self.lines: pnts_count += len(line["points"]) # 2 points have been automatically deleted and the lines will be closed pnts_count -= 2 self.assertEqual( len(points), pnts_count, "Wrong point count ({}). Should be {}.".format( len(points), pnts_count)) self.assertEqual( points[0].id, 1, "First point should have id {}, but has {}.".format( 1, points[0].id)) self.assertTrue( math.fabs(float(points[-1].easting) - 1191579.1097525698) < float_precision, "Wrong easting difference to large ( |{} - {}| = {} > {}).".format( float(points[-1].easting), 1191579.1097525698, math.fabs(float(points[-1].easting) - 1191579.1097525698), float_precision)) self.assertTrue( math.fabs(float(points[-1].northing) - 691044.6091080031) < float_precision, "Wrong northing difference to large ( |{} - {}| = {} > {}).". format(float(points[-1].northing), 691044.6091080031, math.fabs(float(points[-1].northing) - 691044.6091080031), float_precision)) del points points = GeoPoint.load_all_without_lines_from_db(self.session) pnts_count = len( self.points ) # only points which doesn"t belong to a line are loaded self.assertEqual( len(points), pnts_count, "Wrong point count ({}). Should be {}.".format( len(points), pnts_count)) self.assertEqual( points[0].id, 1, "First point should have id {}, but has {}.".format( 1, points[0].id)) self.assertTrue( math.fabs(float(points[-1].easting) - 1273456) < float_precision, "Wrong easting difference to large ( |{} - {}| = {} > {}).".format( float(points[-1].easting), 1273456, math.fabs(float(points[-1].easting) - 1273456), float_precision)) self.assertTrue( math.fabs(float(points[-1].northing) - 5449672) < float_precision, "Wrong northing difference to large ( |{} - {}| = {} > {}).". format(float(points[-1].northing), 5449672, math.fabs(float(points[-1].northing) - 5449672), float_precision)) self.assertEqual( points[-1].horizon.statigraphic_name, "mu", "Wrong horizon ({}). Should be {}.".format( points[-1].horizon.statigraphic_name, "mu")) del points # /2/ load by name points = GeoPoint.load_by_name_from_db("", self.session) pnts_count = len(self.points) # Added line name as points set name, so we have to comment the line points out... # for line in self.lines: # pnts_count += len(line["points"]) # 2 points will be automatically deleted and the lines will be closed # pnts_count -= 2 # 2 points have another name (obviously they have a name) pnts_count -= 2 self.assertEqual( len(points), pnts_count, "Wrong point count ({}). Should be {}.".format( len(points), pnts_count)) self.assertEqual( points[0].id, 1, "First point should have id {}, but has {}.".format( 1, points[0].id)) self.assertTrue( math.fabs(float(points[-1].easting) - 1254367) < float_precision, "Wrong easting difference to large ( |{} - {}| = {} > {}).".format( float(points[-1].easting), 1254367, math.fabs(float(points[-1].easting) - 1254367), float_precision)) self.assertTrue( math.fabs(float(points[-1].northing) - 5443636) < float_precision, "Wrong northing difference to large ( |{} - {}| = {} > {}).". format(float(points[-1].northing), 5443636, math.fabs(float(points[-1].northing) - 5443636), float_precision)) del points points = GeoPoint.load_by_name_without_lines_from_db("", self.session) pnts_count = len(self.points) # 2 points have another name (obviously they have a name) pnts_count -= 2 self.assertEqual( len(points), pnts_count, "Wrong point count ({}). Should be {}.".format( len(points), pnts_count)) self.assertEqual( points[0].id, 1, "First point should have id {}, but has {}.".format( 1, points[0].id)) self.assertTrue( math.fabs(float(points[-1].easting) - 1254367) < float_precision, "Wrong easting difference to large ( |{} - {}| = {} > {}).".format( float(points[-1].easting), 1254367, math.fabs(float(points[-1].easting) - 1254367), float_precision)) self.assertTrue( math.fabs(float(points[-1].northing) - 5443636) < float_precision, "Wrong northing difference to large ( |{} - {}| = {} > {}).". format(float(points[-1].northing), 5443636, math.fabs(float(points[-1].northing) - 5443636), float_precision)) self.assertEqual( points[-1].horizon.statigraphic_name, "so", "Wrong horizon ({}). Should be {}.".format( points[-1].horizon.statigraphic_name, "so")) del points # /3/ load points in given extent # x -> 1174000 - 1200000 # y -> 613500 - 651000 # should return points of 2 lines with line-ids 2 (all points) and 4 (1 point) points = GeoPoint.load_in_extent_from_db(self.session, 1174000, 1200000, 613500, 651000) self.assertEqual( len(points), 5, "Wrong number of points ({}), should be {}".format(len(points), 5)) self.assertTrue( math.fabs(float(points[0].easting) - 1179553.6811741155) < float_precision, "Wrong easting difference to large ( |{} - {}| = {} > {}).".format( float(points[0].easting), 1179553.6811741155, math.fabs(float(points[0].easting) - 1179553.6811741155), float_precision)) self.assertTrue( math.fabs(float(points[0].northing) - 647105.5431482664) < float_precision, "Wrong northing difference to large ( |{} - {}| = {} > {}).". format(float(points[0].northing), 647105.5431482664, math.fabs(float(points[0].northing) - 647105.5431482664), float_precision)) self.assertEqual( points[0].horizon.statigraphic_name, "so", "Wrong horizon ({}). Should be {}.".format( points[-1].horizon.statigraphic_name, "so")) del points points = GeoPoint.load_in_extent_without_lines_from_db( self.session, 0, 1, 0, 1) self.assertEqual( len(points), 0, "Wrong number of points ({}), should be {}".format(len(points), 0)) del points def test_setter_and_getter(self): # type: () -> None """ Test the setter and getter functions of class GeoPoint :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ # points = GeoPoint.load_all_from_db(self.session) points = GeoPoint.load_all_without_lines_from_db(self.session) self.assertEqual( len(points), len(self.points), "Wrong point length ({}). Should be {}.".format( len(points), len(self.points))) points[0].easting = 1 points[1].northing = 2 points[2].altitude = 3 points[2].use_z() points[3].horizon = StratigraphicObject.init_stratigraphy( self.session, "so", 10, False) points[0].name = "point set name" points[1].del_z() for point in points: point.save_to_db() del points points = GeoPoint.load_all_without_lines_from_db(self.session) self.assertEqual( len(points), len(self.points), "Wrong point length ({}). Should be {}.".format( len(points), len(self.points))) self.assertEqual( points[0].easting, 1, "Wrong easting value ({}). Should be {}.".format( points[0].easting, 1)) self.assertEqual( points[1].northing, 2, "Wrong northing value ({}). Should be {}.".format( points[1].northing, 2)) self.assertEqual( points[2].altitude, 3, "Wrong altitude value ({}). Should be {}.".format( points[2].altitude, 3)) self.assertTrue( points[2].has_z, "Third point has no z-value...") # Third point got z-value self.assertEqual( points[3].horizon.statigraphic_name, "so", "Wrong horizon ({}). Should be {}.".format( points[3].horizon.statigraphic_name, "so")) self.assertEqual( points[0].name, "point set name", "Wrong point name ({}). Should be {}.".format( points[0].name, "point set name")) self.assertFalse(points[1].has_z, "Second point has a z-value...") self.assertEqual( points[1].altitude, 0, "Wrong altitude value ({}). Should be {}.".format( points[1].altitude, 0)) def test_add_and_delete_properties(self): # type: () -> None """ Test the add_property and delete_property function :return: Nothing :raises AssertionError: Raises AssertionError if a test fails """ point = GeoPoint.load_all_from_db(self.session)[0] point.add_property( Property(0, PropertyTypes.INT, "test prop", "test unit", self.session)) point.add_property( Property(0, PropertyTypes.INT, "test prop 2", "test unit 2", self.session)) self.assertRaises(TypeError, point.add_property, "string") del point point = GeoPoint.load_all_from_db(self.session)[0] self.assertEqual(2, len(point.properties)) self.assertEqual("test prop", point.properties[0].property_name) self.assertEqual("test prop 2", point.properties[1].property_name) self.assertEqual("test unit", point.properties[0].property_unit) self.assertEqual("test unit 2", point.properties[1].property_unit) self.assertTrue(point.has_property("test prop 2")) self.assertEqual("test unit 2", point.get_property("test prop 2").property_unit) prop = point.properties[0] point.delete_property(prop) self.assertRaises(TypeError, point.delete_property, "string") self.assertRaises(ValueError, point.delete_property, prop) self.assertEqual(1, len(point.properties)) self.assertEqual("test prop 2", point.properties[0].property_name) self.assertEqual("test unit 2", point.properties[0].property_unit) del point point = GeoPoint.load_all_from_db(self.session)[0] self.assertEqual(1, len(point.properties)) self.assertEqual("test prop 2", point.properties[0].property_name) self.assertEqual("test unit 2", point.properties[0].property_unit) def tearDown(self): # type: () -> None """ Close session after testruns :return: Nothing """ self.handler.close_last_session()