def test_unpatch(self, attribute):
     """
     Test that unpatch gracefully handles unpatched functions
     """
     patch()
     self.assertTrue(is_patched())
     self.unpatch_all()
     self.assertFalse(is_patched())
     old_attribute = getattr(_trans, attribute)
     self.unpatch_all()
     new_attribute = getattr(_trans, attribute)
     self.assertIs(old_attribute, new_attribute)
     self.assertFalse(is_patched())
예제 #2
0
 def test_unpatch(self, attribute):
     """
     Test that unpatch gracefully handles unpatched functions
     """
     patch()
     self.assertTrue(is_patched())
     self.unpatch_all()
     self.assertFalse(is_patched())
     old_attribute = getattr(_trans, attribute)
     self.unpatch_all()
     new_attribute = getattr(_trans, attribute)
     self.assertIs(old_attribute, new_attribute)
     self.assertFalse(is_patched())
 def test_patch_attributes(self, attribute):
     """
     Test that patch changes the attribute
     """
     self.unpatch_all()
     self.assertFalse(is_patched())
     old_attribute = getattr(_trans, attribute)
     patch()
     new_attribute = getattr(_trans, attribute)
     self.assertIsNot(old_attribute, new_attribute)
     self.assertTrue(is_patched())
     old_attribute = getattr(_trans, attribute)
     patch()
     new_attribute = getattr(_trans, attribute)
     self.assertIsNot(old_attribute, new_attribute)
     self.assertTrue(is_patched())
예제 #4
0
 def test_patch_attributes(self, attribute):
     """
     Test that patch changes the attribute
     """
     self.unpatch_all()
     self.assertFalse(is_patched())
     old_attribute = getattr(_trans, attribute)
     patch()
     new_attribute = getattr(_trans, attribute)
     self.assertIsNot(old_attribute, new_attribute)
     self.assertTrue(is_patched())
     old_attribute = getattr(_trans, attribute)
     patch()
     new_attribute = getattr(_trans, attribute)
     self.assertIsNot(old_attribute, new_attribute)
     self.assertTrue(is_patched())
    def assert_translations(self):
        """
        Assert that the empty and nonempty translations are correct

        The `empty = empty[:]` syntax is intentional. Since subclasses
        may implement a lazy translation, we must perform a "string
        operation" to coerce it to a string value. We don't use `str` or
        `unicode` because we also assert the string type.
        """
        empty, nonempty = self.get_translations()
        empty = empty[:]
        nonempty = nonempty[:]
        if self.is_unicode:
            self.assertTrue(isinstance(empty, unicode))
            self.assertTrue(isinstance(nonempty, unicode))
        else:
            self.assertTrue(isinstance(empty, str))
            self.assertTrue(isinstance(nonempty, str))
        if self.needs_patched and not is_patched():
            self.assertIn(self.header, empty)
        else:
            self.assertNotIn(self.header, empty)
        self.assertNotIn(self.header, nonempty)
예제 #6
0
    def assert_translations(self):
        """
        Assert that the empty and nonempty translations are correct

        The `empty = empty[:]` syntax is intentional. Since subclasses
        may implement a lazy translation, we must perform a "string
        operation" to coerce it to a string value. We don't use `str` or
        `unicode` because we also assert the string type.
        """
        empty, nonempty = self.get_translations()
        empty = empty[:]
        nonempty = nonempty[:]
        if self.is_unicode:
            self.assertTrue(isinstance(empty, unicode))
            self.assertTrue(isinstance(nonempty, unicode))
        else:
            self.assertTrue(isinstance(empty, str))
            self.assertTrue(isinstance(nonempty, str))
        if self.needs_patched and not is_patched():
            self.assertIn(self.header, empty)
        else:
            self.assertNotIn(self.header, empty)
        self.assertNotIn(self.header, nonempty)
 def unpatch_all(self):
     """
     Unpatch the module recursively
     """
     while is_patched():
         unpatch()
예제 #8
0
 def unpatch_all(self):
     """
     Unpatch the module recursively
     """
     while is_patched():
         unpatch()