def test_set_referred_object_warning(self): """ Setting a referred object equal to an object that is equal to the last referred object should not emit a warning. """ def assert_differnt_referred_object_warning_issued(w): """ assert the different referred object warning is emitted """ self.assertEqual(len(w), 1) self.assertIn('is not equal', str(w[0].message)) obj1 = UTCDateTime(10) obj2 = UTCDateTime(11) obj3 = UTCDateTime(10) rid1 = ResourceIdentifier('abc123', referred_object=obj1) # this should raise a warning as the new object != old object with WarningsCapture() as w: rid2 = ResourceIdentifier('abc123', referred_object=obj2) assert_differnt_referred_object_warning_issued(w) with WarningsCapture() as w: rid2.set_referred_object(obj1) assert_differnt_referred_object_warning_issued(w) # set the referred object back to previous state, this should warn with WarningsCapture() as w: ResourceIdentifier('abc123', referred_object=obj2) assert_differnt_referred_object_warning_issued(w) # this should not emit a warning since obj1 == obj3 with WarningsCapture() as w: rid1.set_referred_object(obj3) self.assertEqual(len(w), 0)
def test_set_referred_object_warning(self): """ Setting a referred object equal to an object that is equal to the last referred object should not emit a warning. """ def assert_differnt_referred_object_warning_issued(w): """ assert the different referred object warning is emitted """ self.assertEqual(len(w), 1) self.assertIn('is not equal', str(w[0].message)) obj1 = UTCDateTime(10) obj2 = UTCDateTime(11) obj3 = UTCDateTime(10) rid1 = ResourceIdentifier('abc123', referred_object=obj1) # this should raise a warning as the new object != old object with WarningsCapture() as w: rid2 = ResourceIdentifier('abc123', referred_object=obj2) assert_differnt_referred_object_warning_issued(w) with WarningsCapture() as w: rid2.set_referred_object(obj1) assert_differnt_referred_object_warning_issued(w) # set the referred object back to previous state, this should warn with WarningsCapture() as w: ResourceIdentifier('abc123', referred_object=obj2) assert_differnt_referred_object_warning_issued(w) # this should not emit a warning since obj1 == obj3 with WarningsCapture() as w: rid1.set_referred_object(obj3) self.assertEqual(len(w), 0)
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() 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.get_referred_object(), None) self.assertEqual(ref_b.get_referred_object(), None) self.assertEqual(ref_c.get_referred_object(), None) # Setting the object for one will make it available to all other # instances, provided they weren't bound to specific objects. ref_b.set_referred_object(obj) self.assertIs(ref_a.get_referred_object(), obj) self.assertIs(ref_b.get_referred_object(), obj) self.assertIs(ref_c.get_referred_object(), obj)
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() 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.get_referred_object(), None) self.assertEqual(ref_b.get_referred_object(), None) self.assertEqual(ref_c.get_referred_object(), None) # Setting the object for one will make it available to all other # instances, provided they weren't bound to specific objects. ref_b.set_referred_object(obj) self.assertIs(ref_a.get_referred_object(), obj) self.assertIs(ref_b.get_referred_object(), obj) self.assertIs(ref_c.get_referred_object(), obj)