test_get_commit_patches.py (1650B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import mozunit 6 7 from mozversioncontrol import get_repository_object 8 9 STEPS = { 10 "hg": [ 11 """ 12 echo bar >> bar 13 hg commit -m "FIRST PATCH" 14 """, 15 """ 16 printf "baz\\r\\nqux" > baz 17 hg add baz 18 hg commit -m "SECOND PATCH" 19 """, 20 ], 21 "git": [ 22 """ 23 echo bar >> bar 24 git add bar 25 git commit -m "FIRST PATCH" 26 """, 27 """ 28 printf "baz\\r\\nqux" > baz 29 git -c core.autocrlf=false add baz 30 git commit -m "SECOND PATCH" 31 """, 32 ], 33 "jj": [ 34 """ 35 jj new -m "FIRST PATCH" 36 echo bar >> bar 37 """, 38 # snapshot, since bug 1962245 suppresses automatic ones 39 """ 40 jj new -m "SECOND PATCH" 41 printf "baz\\r\\nqux" > baz 42 jj log -n0 43 """, 44 ], 45 } 46 47 48 def test_get_commit_patches(repo): 49 vcs = get_repository_object(repo.dir) 50 nodes = [] 51 52 # Create some commits and note the SHAs. 53 repo.execute_next_step() 54 nodes.append(vcs.head_ref) 55 56 repo.execute_next_step() 57 nodes.append(vcs.head_ref) 58 59 patches = vcs.get_commit_patches(nodes) 60 61 assert len(patches) == 2 62 # Assert the patches are returned in the correct order. 63 assert b"FIRST PATCH" in patches[0] 64 assert b"SECOND PATCH" in patches[1] 65 # Assert the CRLF are correctly preserved. 66 assert b"baz\r\n" in patches[1] 67 68 69 if __name__ == "__main__": 70 mozunit.main()