示例#1
0
    def test_singletons_can_be_reset(self):
        instance_a = Singleton.singleton()
        Singleton.reset_singleton()
        instance_b = Singleton.singleton()

        self.assertTrue(instance_a is not instance_b,
                        'Singleton.singleton() should return a different instance after reset.')
示例#2
0
    def test_singletons_can_be_reset(self):
        instance_a = Singleton.singleton()
        Singleton.reset_singleton()
        instance_b = Singleton.singleton()

        self.assertTrue(
            instance_a is not instance_b,
            'Singleton.singleton() should return a different instance after reset.'
        )
示例#3
0
    def test_singleton_raises_error_on_multiple_instantiations(self):
        instance_a = Singleton.singleton()

        with self.assertRaises(
                SingletonError,
                msg='Instantiating more than once should raise an error.'):
            instance_b = Singleton()
示例#4
0
 def test_singleton_returns_same_instance_every_time(self):
     instance_a = Singleton.singleton()
     instance_b = Singleton.singleton()
     self.assertIs(
         instance_a, instance_b,
         'Singleton.singleton() should return the same instance.')
示例#5
0
 def test_singleton_returns_same_instance_every_time(self):
     instance_a = Singleton.singleton()
     instance_b = Singleton.singleton()
     self.assertIs(instance_a, instance_b, 'Singleton.singleton() should return the same instance.')
示例#6
0
    def test_singleton_raises_error_on_multiple_instantiations(self):
        instance_a = Singleton.singleton()

        with self.assertRaises(SingletonError, msg='Instantiating more than once should raise an error.'):
            instance_b = Singleton()