Beispiel #1
0
    def test_hotfix_module_exception(self):
        shutil.copy(self.module_file_v1, self.module_file)

        sys.modules.pop("module_test", None)
        import module_test

        self.assertEqual(module_test.NO_HOTFIX_DATA, 1)
        self.assertEqual(module_test.HOTFIX_DATA, 1)

        self.assertEqual(module_test.no_hotfix_func(), 1)
        self.assertEqual(module_test.hotfix_func(), 1)

        self.assertFalse(hasattr(module_test, "new_func"))
        self.assertFalse(hasattr(module_test, "new_func_and_skip"))

        self.assertFalse(hasattr(module_test, "NEW_DATA"))
        self.assertFalse(hasattr(module_test, "NEW_HOTFIX_DATA"))

        self.assertEqual(module_test.OBJECT_CREATED_WHEN_HOTFIXING.func(), 1)
        obj_id = id(module_test.OBJECT_CREATED_WHEN_HOTFIXING)

        self.assertEqual(module_test.HotfixClass.func(), 1)
        self.assertEqual(id(module_test.HOTFIX_CLASS_REF), id(module_test.HotfixClass))

        shutil.copy(self.module_file_v2, self.module_file)
        hotfix(["module_exception_test", "module_test"])

        self.assertEqual(module_test.NO_HOTFIX_DATA, 1)
        self.assertEqual(module_test.HOTFIX_DATA, 2)

        self.assertEqual(module_test.no_hotfix_func(), 1)
        self.assertEqual(module_test.hotfix_func(), 2)

        self.assertEqual(module_test.new_func(), 2)
        self.assertFalse(hasattr(module_test, "new_func_and_skip"))

        self.assertFalse(hasattr(module_test, "NEW_DATA"))
        self.assertEqual(module_test.NEW_HOTFIX_DATA, 2)

        self.assertEqual(module_test.OBJECT_CREATED_WHEN_HOTFIXING.func(), 2)
        self.assertEqual(obj_id, id(module_test.OBJECT_CREATED_WHEN_HOTFIXING))

        self.assertEqual(module_test.HotfixClass.func(), 2)
        self.assertEqual(module_test.HOTFIX_CLASS_REF, module_test.HotfixClass)

        self.assertEqual(module_test.NewClass.func(), 2)
        self.assertEqual(module_test.NEW_CLASS_REF, module_test.NewClass)
    def test_hotfix_function(self):
        shutil.copy(self.module_file_v1, self.module_file)
        sys.modules.pop("function_test", None)

        import function_test

        obj_default1 = function_test.hotfix_func_with_obj_default()
        self.assertEqual(function_test.closure_func1(), 1)
        self.assertEqual(function_test.closure_func2(), 1)

        shutil.copy(self.module_file_v2, self.module_file)
        hotfix(["function_test"])

        obj_default2 = function_test.hotfix_func_with_obj_default()
        self.assertEqual(function_test.closure_func1(), 2)
        self.assertEqual(function_test.closure_func2(), 4)

        self.assertEqual(obj_default1.__class__,  obj_default2.__class__)
Beispiel #3
0
    def test_skip_hotfix_module(self):
        shutil.copy(self.module_file_v1, self.module_file)

        sys.modules.pop("module_skip_test", None)
        import module_skip_test

        self.assertEqual(module_skip_test.NO_HOTFIX_DATA, 1)
        self.assertEqual(module_skip_test.HOTFIX_DATA, 1)

        self.assertEqual(module_skip_test.no_hotfix_func(), 1)
        self.assertEqual(module_skip_test.hotfix_func(), 1)

        shutil.copy(self.module_file_v2, self.module_file)
        hotfix(["module_skip_test"])

        self.assertEqual(module_skip_test.NO_HOTFIX_DATA, 1)
        self.assertEqual(module_skip_test.HOTFIX_DATA, 1)

        self.assertEqual(module_skip_test.no_hotfix_func(), 1)
        self.assertEqual(module_skip_test.hotfix_func(), 1)
Beispiel #4
0
    def test_hotfix_class(self):
        shutil.copy(self.module_file_v1, self.module_file)
        sys.modules.pop("class_test", None)

        import class_test

        hotfix_class_obj = class_test.HotfixClass()
        self.assertEqual(hotfix_class_obj.no_hotfix_data, 1)
        self.assertEqual(hotfix_class_obj.hotfix_data, 1)

        self.assertEqual(hotfix_class_obj.no_hotfix_method(), 1)
        self.assertEqual(hotfix_class_obj.hotfix_method(), 1)

        self.assertEqual(hotfix_class_obj.no_hotfix_classmethod(), 1)
        self.assertEqual(hotfix_class_obj.hotfix_classmethod(), 1)

        self.assertEqual(hotfix_class_obj.hotfix_property, 1)
        self.assertEqual(hotfix_class_obj.no_hotfix_property, 1)

        self.assertEqual(hotfix_class_obj.replace_data_with_func, 1)
        self.assertEqual(hotfix_class_obj.replace_data_with_static_method, 1)
        self.assertEqual(hotfix_class_obj.replace_data_with_class_method, 1)

        self.assertEqual(class_test.HotfixClass.InnerClass1.func(), 1)
        self.assertEqual(class_test.HotfixClass.InnerClass2.func(), 1)
        self.assertEqual(class_test.HotfixClass.InnerClass,
                         class_test.HotfixClass.InnerClass1)

        no_hotfix_class_obj = class_test.NoHotfixClass()
        self.assertEqual(no_hotfix_class_obj.no_hotfix_data, 1)
        self.assertEqual(no_hotfix_class_obj.no_hotfix_method(), 1)

        another_no_hotfix_class_obj = class_test.AnotherNoHotfixClass()
        self.assertEqual(another_no_hotfix_class_obj.no_hotfix_data, 1)
        self.assertEqual(another_no_hotfix_class_obj.no_hotfix_method(), 1)

        shutil.copy(self.module_file_v2, self.module_file)
        hotfix(["class_test"])

        self.assertEqual(hotfix_class_obj.no_hotfix_data, 1)
        self.assertEqual(hotfix_class_obj.hotfix_data, 2)

        self.assertEqual(hotfix_class_obj.no_hotfix_method(), 1)
        self.assertEqual(hotfix_class_obj.hotfix_method(), 2)

        self.assertEqual(hotfix_class_obj.no_hotfix_classmethod(), 1)
        self.assertEqual(hotfix_class_obj.hotfix_classmethod(), 2)

        self.assertEqual(hotfix_class_obj.no_hotfix_property, 1)
        self.assertEqual(hotfix_class_obj.hotfix_property, 2)

        self.assertEqual(hotfix_class_obj.replace_data_with_func(), 2)
        self.assertEqual(hotfix_class_obj.replace_data_with_static_method(), 2)
        self.assertEqual(hotfix_class_obj.replace_data_with_class_method(), 2)

        self.assertEqual(class_test.HotfixClass.InnerClass1.func(), 2)
        self.assertEqual(class_test.HotfixClass.InnerClass2.func(), 2)
        self.assertEqual(class_test.HotfixClass.InnerClass,
                         class_test.HotfixClass.InnerClass2)

        no_hotfix_class_obj = class_test.NoHotfixClass()
        self.assertEqual(no_hotfix_class_obj.no_hotfix_data, 1)
        self.assertEqual(no_hotfix_class_obj.no_hotfix_method(), 1)

        another_no_hotfix_class_obj = class_test.AnotherNoHotfixClass()
        self.assertEqual(another_no_hotfix_class_obj.no_hotfix_data, 1)
        self.assertEqual(another_no_hotfix_class_obj.no_hotfix_method(), 1)