Replace child_name's old definition with new_child, in the context of the given parent. The parent could be a module when the child is a function at module scope. Or the parent could be a class when a class' method is being replaced. The named child is set to new_child, while the
(self, parent, child_name, new_child)
| 110 | self.stubs = [] |
| 111 | |
| 112 | def Set(self, parent, child_name, new_child): |
| 113 | """Replace child_name's old definition with new_child, in the context |
| 114 | of the given parent. The parent could be a module when the child is a |
| 115 | function at module scope. Or the parent could be a class when a class' |
| 116 | method is being replaced. The named child is set to new_child, while |
| 117 | the prior definition is saved away for later, when UnsetAll() is called. |
| 118 | |
| 119 | This method supports the case where child_name is a staticmethod or a |
| 120 | classmethod of parent. |
| 121 | """ |
| 122 | old_child = getattr(parent, child_name) |
| 123 | |
| 124 | old_attribute = parent.__dict__.get(child_name) |
| 125 | if old_attribute is not None and isinstance(old_attribute, staticmethod): |
| 126 | old_child = staticmethod(old_child) |
| 127 | |
| 128 | self.cache.append((parent, old_child, child_name)) |
| 129 | setattr(parent, child_name, new_child) |
| 130 | |
| 131 | def UnsetAll(self): |
| 132 | """Reverses all the Set() calls, restoring things to their original |
no test coverage detected