def test_update_constant_with_custom_code2(self): SAMPLE_CODE1 = """ class B(object): CONSTANT = 1 def foo(self): return self.CONSTANT """ SAMPLE_CODE2 = """ class B(object): CONSTANT = 2 def __xreload_old_new__(cls, name, old, new): if name == 'CONSTANT': cls.CONSTANT = new __xreload_old_new__ = classmethod(__xreload_old_new__) def foo(self): return self.CONSTANT """ self.make_mod(sample=SAMPLE_CODE1) import x # @UnresolvedImport foo = x.B().foo self.assertEqual(foo(), 1) self.make_mod(sample=SAMPLE_CODE2) pydevd_reload.xreload(x) self.assertEqual(foo(), 2) #Actually updated it now!
def test_reload_custom_code_after_changes_in_class(self): SAMPLE_CODE1 = """ class B(object): CONSTANT = 1 def foo(self): return self.CONSTANT """ SAMPLE_CODE2 = """ class B(object): CONSTANT = 1 @classmethod def __xreload_after_reload_update__(cls): cls.CONSTANT = 2 def foo(self): return self.CONSTANT """ self.make_mod(sample=SAMPLE_CODE1) import x # @UnresolvedImport foo = x.B().foo self.assertEqual(foo(), 1) self.make_mod(sample=SAMPLE_CODE2) pydevd_reload.xreload(x) self.assertEqual(foo(), 2) #Actually updated it now!
def test_update_constant_with_custom_code(self): SAMPLE_CODE1 = """ CONSTANT = 1 class B(object): def foo(self): return CONSTANT """ SAMPLE_CODE2 = """ CONSTANT = 2 def __xreload_old_new__(namespace, name, old, new): if name == 'CONSTANT': namespace[name] = new class B(object): def foo(self): return CONSTANT """ self.make_mod(sample=SAMPLE_CODE1) import x # @UnresolvedImport foo = x.B().foo self.assertEqual(foo(), 1) self.make_mod(sample=SAMPLE_CODE2) pydevd_reload.xreload(x) self.assertEqual(foo(), 2) #Actually updated it now!
def test_reload_custom_code_after_changes(self): SAMPLE_CODE1 = """ CONSTANT = 1 class B(object): def foo(self): return CONSTANT """ SAMPLE_CODE2 = """ CONSTANT = 1 def __xreload_after_reload_update__(namespace): namespace['CONSTANT'] = 2 class B(object): def foo(self): return CONSTANT """ self.make_mod(sample=SAMPLE_CODE1) import x # @UnresolvedImport foo = x.B().foo self.assertEqual(foo(), 1) self.make_mod(sample=SAMPLE_CODE2) pydevd_reload.xreload(x) self.assertEqual(foo(), 2) #Actually updated it now!
def test_update_constant(self): SAMPLE_CODE1 = """ CONSTANT = 1 class B(object): def foo(self): return CONSTANT """ SAMPLE_CODE2 = """ CONSTANT = 2 class B(object): def foo(self): return CONSTANT """ self.make_mod(sample=SAMPLE_CODE1) import x # @UnresolvedImport foo = x.B().foo self.assertEqual(foo(), 1) self.make_mod(sample=SAMPLE_CODE2) pydevd_reload.xreload(x) self.assertEqual(foo(), 1) #Just making it explicit we don't reload constants.