本文整理汇总了Python中obspy.core.event.ResourceIdentifier.getReferredObject方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceIdentifier.getReferredObject方法的具体用法?Python ResourceIdentifier.getReferredObject怎么用?Python ResourceIdentifier.getReferredObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core.event.ResourceIdentifier
的用法示例。
在下文中一共展示了ResourceIdentifier.getReferredObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_same_resource_id_different_referred_object
# 需要导入模块: from obspy.core.event import ResourceIdentifier [as 别名]
# 或者: from obspy.core.event.ResourceIdentifier import getReferredObject [as 别名]
def test_same_resource_id_different_referred_object(self):
"""
Tests the handling of the case that different ResourceIdentifier
instances are created that have the same resource id but different
objects. This should not happen and thus a warning should be emitted.
Skipped for Python 2.5 because it does not have the catch_warnings
context manager.
"""
object_a = UTCDateTime()
object_b = UTCDateTime()
self.assertEqual(object_a is object_b, False)
resource_id = 'obspy.org/tests/test_resource'
res_a = ResourceIdentifier(resource_id=resource_id,
referred_object=object_a)
# Now create a new resource with the same id but a different object.
# This will raise a warning.
with warnings.catch_warnings(record=True):
warnings.simplefilter('error', UserWarning)
self.assertRaises(UserWarning, ResourceIdentifier,
resource_id=resource_id,
referred_object=object_b)
# Now ignore the warning and actually create the new
# ResourceIdentifier.
warnings.simplefilter('ignore', UserWarning)
res_b = ResourceIdentifier(resource_id=resource_id,
referred_object=object_b)
# Object b was the last to added, thus all resource identifiers will
# now point to it.
self.assertEqual(object_b is res_a.getReferredObject(), True)
self.assertEqual(object_b is res_b.getReferredObject(), True)
示例2: test_resources_in_global_dict_get_garbage_collected
# 需要导入模块: from obspy.core.event import ResourceIdentifier [as 别名]
# 或者: from obspy.core.event.ResourceIdentifier import getReferredObject [as 别名]
def test_resources_in_global_dict_get_garbage_collected(self):
"""
Tests that the ResourceIdentifiers in the class level resource dict get
deleted if they have no other reference and the object they refer to
goes out of scope.
"""
obj_a = UTCDateTime()
obj_b = UTCDateTime()
res1 = ResourceIdentifier(referred_object=obj_a)
res2 = ResourceIdentifier(referred_object=obj_b)
# Now two keys should be in the global dict.
rdict = ResourceIdentifier._ResourceIdentifier__resource_id_weak_dict
self.assertEqual(len(rdict.keys()), 2)
# Deleting the objects should also remove the from the dictionary.
del obj_a, obj_b
self.assertEqual(len(rdict.keys()), 0)
# references are still around but no longer have associates objects.
self.assertEqual(res1.getReferredObject(), None)
self.assertEqual(res2.getReferredObject(), None)
示例3: test_adding_a_referred_object_after_creation
# 需要导入模块: from obspy.core.event import ResourceIdentifier [as 别名]
# 或者: from obspy.core.event.ResourceIdentifier import getReferredObject [as 别名]
def test_adding_a_referred_object_after_creation(self):
"""
Check that the referred objects can also be made available after the
ResourceIdentifier instances have been created.
"""
obj = UTCDateTime()
obj_id = id(obj)
res_id = "obspy.org/time/test"
ref_a = ResourceIdentifier(res_id)
ref_b = ResourceIdentifier(res_id)
ref_c = ResourceIdentifier(res_id)
# All three will have no resource attached.
self.assertEqual(ref_a.getReferredObject(), None)
self.assertEqual(ref_b.getReferredObject(), None)
self.assertEqual(ref_c.getReferredObject(), None)
# Setting the object for one will make it available to all other
# instances.
ref_b.setReferredObject(obj)
self.assertEqual(id(ref_a.getReferredObject()), obj_id)
self.assertEqual(id(ref_b.getReferredObject()), obj_id)
self.assertEqual(id(ref_c.getReferredObject()), obj_id)