def test_patching(self): import astroNN.data from astroNN.shared.patch_util import Patch diff = os.path.join(astroNN.data.datapath(), 'tf1_12.patch') patch = Patch(diff) patch_file_path = "travis_tf_1_12.py" if os.path.exists(patch_file_path) is False: patch_file_path = os.path.join("tests", "travis_tf_1_12.py") with open(patch_file_path, 'r') as f: original_text = f.read() patch.apply(patch_file_path) with open(patch_file_path, 'r') as f: patched_text = f.read() patch.apply(patch_file_path) with open(patch_file_path, 'r') as f: patched_twice_text = f.read() patch.revert(patch_file_path) with open(patch_file_path, 'r') as f: unpatched_text = f.read() patch.revert(patch_file_path) with open(patch_file_path, 'r') as f: unpatched_twice_text = f.read() # assert patching, patching twice and unpatching work correctly self.assertNotEqual(original_text, patched_text) self.assertEqual(patched_twice_text, patched_text) self.assertEqual(original_text, unpatched_text) self.assertEqual(unpatched_twice_text, unpatched_text)
def __master_patch(path, diffpatch): # generate patch and patch patch = Patch(diffpatch) if method == 'patch': action_name = 'Patched' err = patch.apply(path) elif method == 'unpatch': action_name = 'Unpatched' err = patch.revert(path) else: raise ValueError(f"Unknown method={method}") if err == 0: print(f"{action_name} Successfully at {path}!") else: print("Error Occurred!")