def test_quakeml_regex(self): """ Tests that regex used to check for QuakeML validatity actually works. """ # This one contains all valid characters. It should pass the # validation. res_id = ( "smi:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" "1234567890-.*()_~'/abcdefghijklmnopqrstuvwxyzABCDEFGHIKLMNOPQR" "STUVWXYZ0123456789-.*()_~'+?=,;&") res = ResourceIdentifier(res_id) self.assertEqual(res_id, res.get_quakeml_uri()) # The id has to valid from start to end. Due to the spaces this cannot # automatically be converted to a correct one. res_id = ("something_before smi:local/something something_after") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri) # A colon is an invalid character. res_id = ("smi:local/hello:yea") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri) # Space as well res_id = ("smi:local/hello yea") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri) # Dots are fine res_id = ("smi:local/hello....yea") res = ResourceIdentifier(res_id) self.assertEqual(res_id, res.get_quakeml_uri()) # Hats not res_id = ("smi:local/hello^^yea") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri)
def test_quakeml_regex(self): """ Tests that regex used to check for QuakeML validatity actually works. """ # This one contains all valid characters. It should pass the # validation. res_id = ( "smi:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" "1234567890-.*()_~'/abcdefghijklmnopqrstuvwxyzABCDEFGHIKLMNOPQR" "STUVWXYZ0123456789-.*()_~'+?=,;&") res = ResourceIdentifier(res_id) self.assertEqual(res_id, res.get_quakeml_uri()) # The id has to valid from start to end. Due to the spaces this cannot # automatically be converted to a correct one. res_id = ("something_before smi:local/something something_after") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri) # A colon is an invalid character. res_id = ("smi:local/hello:yea") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri) # Space as well res_id = ("smi:local/hello yea") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri) # Dots are fine res_id = ("smi:local/hello....yea") res = ResourceIdentifier(res_id) self.assertEqual(res_id, res.get_quakeml_uri()) # Hats not res_id = ("smi:local/hello^^yea") res = ResourceIdentifier(res_id) self.assertRaises(ValueError, res.get_quakeml_uri)
def test_resource_id_valid_quakemluri(self): """ Test that a resource identifier per default (i.e. no arguments to __init__()) gets set up with a QUAKEML conform ID. """ rid = ResourceIdentifier() self.assertEqual(rid.id, rid.get_quakeml_uri())
def test_resource_id_valid_quakemluri(self): """ Test that a resource identifier per default (i.e. no arguments to __init__()) gets set up with a QUAKEML conform ID. """ rid = ResourceIdentifier() self.assertEqual(rid.id, rid.get_quakeml_uri())
def test_error_message_for_failing_quakeml_id_conversion(self): """ Converting an id to a QuakeML compatible id might fail. Test the error message. """ invalid_id = "http://example.org" rid = ResourceIdentifier(invalid_id) with self.assertRaises(ValueError) as e: rid.get_quakeml_uri() self.assertEqual( e.exception.args[0], "The id 'http://example.org' is not a valid QuakeML resource " "identifier. ObsPy tried modifying it to " "'smi:local/http://example.org' but it is still not valid. Please " "make sure all resource ids are either valid or can be made valid " "by prefixing them with 'smi:<authority_id>/'. Valid ids are " "specified in the QuakeML manual section 3.1 and in particular " "exclude colons for the final part.")
def test_error_message_for_failing_quakeml_id_conversion(self): """ Converting an id to a QuakeML compatible id might fail. Test the error message. """ invalid_id = "http://example.org" rid = ResourceIdentifier(invalid_id) with self.assertRaises(ValueError) as e: rid.get_quakeml_uri() self.assertEqual( e.exception.args[0], "The id 'http://example.org' is not a valid QuakeML resource " "identifier. ObsPy tried modifying it to " "'smi:local/http://example.org' but it is still not valid. Please " "make sure all resource ids are either valid or can be made valid " "by prefixing them with 'smi:<authority_id>/'. Valid ids are " "specified in the QuakeML manual section 3.1 and in particular " "exclude colons for the final part.")