| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for gclient_scm.py.""" | 6 """Unit tests for gclient_scm.py.""" |
| 7 | 7 |
| 8 # pylint: disable=E1103 | 8 # pylint: disable=E1103 |
| 9 | 9 |
| 10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists | 775 gclient_scm.SVNWrapper.BinaryExists = self._original_SVNBinaryExists |
| 776 | 776 |
| 777 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): | 777 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): |
| 778 def testDir(self): | 778 def testDir(self): |
| 779 members = [ | 779 members = [ |
| 780 'BinaryExists', | 780 'BinaryExists', |
| 781 'FullUrlForRelativeUrl', | 781 'FullUrlForRelativeUrl', |
| 782 'GetRevisionDate', | 782 'GetRevisionDate', |
| 783 'GetUsableRev', | 783 'GetUsableRev', |
| 784 'RunCommand', | 784 'RunCommand', |
| 785 'UpdateSubmoduleConfig', |
| 785 'cleanup', | 786 'cleanup', |
| 786 'diff', | 787 'diff', |
| 787 'pack', | 788 'pack', |
| 788 'relpath', | 789 'relpath', |
| 789 'revert', | 790 'revert', |
| 790 'revinfo', | 791 'revinfo', |
| 791 'runhooks', | 792 'runhooks', |
| 792 'status', | 793 'status', |
| 793 'update', | 794 'update', |
| 794 'url', | 795 'url', |
| (...skipping 14 matching lines...) Expand all Loading... |
| 809 gclient_scm.os.remove(file_path) | 810 gclient_scm.os.remove(file_path) |
| 810 file_list = [] | 811 file_list = [] |
| 811 scm.revert(options, self.args, file_list) | 812 scm.revert(options, self.args, file_list) |
| 812 self.assertEquals(file_list, [file_path]) | 813 self.assertEquals(file_list, [file_path]) |
| 813 file_list = [] | 814 file_list = [] |
| 814 scm.diff(options, self.args, file_list) | 815 scm.diff(options, self.args, file_list) |
| 815 self.assertEquals(file_list, []) | 816 self.assertEquals(file_list, []) |
| 816 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 817 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
| 817 'Fast-forward\n a | 1 +\n b | 1 +\n' | 818 'Fast-forward\n a | 1 +\n b | 1 +\n' |
| 818 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 819 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
| 820 '________ running \'git submodule --quiet foreach git config -f ' |
| 821 '$toplevel/.git/config submodule.$name.ignore || git config -f ' |
| 822 '$toplevel/.git/config submodule.$name.ignore dirty\' in ' |
| 823 '\'%s\'\n\n' |
| 819 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 824 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
| 820 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.') | 825 'HEAD is now at a7142dc Personalized\n') % ( |
| 826 self.root_dir, join(self.root_dir, '.')) |
| 821 self.assertTrue(sys.stdout.getvalue().startswith(expectation)) | 827 self.assertTrue(sys.stdout.getvalue().startswith(expectation)) |
| 822 sys.stdout.close() | 828 sys.stdout.close() |
| 823 | 829 |
| 824 def testRevertNone(self): | 830 def testRevertNone(self): |
| 825 if not self.enabled: | 831 if not self.enabled: |
| 826 return | 832 return |
| 827 options = self.Options() | 833 options = self.Options() |
| 828 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 834 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 829 relpath=self.relpath) | 835 relpath=self.relpath) |
| 830 file_list = [] | 836 file_list = [] |
| 831 scm.update(options, None, file_list) | 837 scm.update(options, None, file_list) |
| 832 file_list = [] | 838 file_list = [] |
| 833 scm.revert(options, self.args, file_list) | 839 scm.revert(options, self.args, file_list) |
| 834 self.assertEquals(file_list, []) | 840 self.assertEquals(file_list, []) |
| 835 self.assertEquals(scm.revinfo(options, self.args, None), | 841 self.assertEquals(scm.revinfo(options, self.args, None), |
| 836 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 842 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 837 self.checkstdout( | 843 self.checkstdout( |
| 838 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 844 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
| 839 'Fast-forward\n a | 1 +\n b | 1 +\n' | 845 'Fast-forward\n a | 1 +\n b | 1 +\n' |
| 840 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 846 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
| 847 '________ running \'git submodule --quiet foreach git config -f ' |
| 848 '$toplevel/.git/config submodule.$name.ignore || git config -f ' |
| 849 '$toplevel/.git/config submodule.$name.ignore dirty\' in ' |
| 850 '\'%s\'\n\n' |
| 841 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 851 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
| 842 'HEAD is now at a7142dc Personalized\n') % | 852 'HEAD is now at a7142dc Personalized\n') % ( |
| 843 join(self.root_dir, '.')) | 853 self.root_dir, join(self.root_dir, '.'))) |
| 844 | 854 |
| 845 def testRevertModified(self): | 855 def testRevertModified(self): |
| 846 if not self.enabled: | 856 if not self.enabled: |
| 847 return | 857 return |
| 848 options = self.Options() | 858 options = self.Options() |
| 849 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 859 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 850 relpath=self.relpath) | 860 relpath=self.relpath) |
| 851 file_list = [] | 861 file_list = [] |
| 852 scm.update(options, None, file_list) | 862 scm.update(options, None, file_list) |
| 853 file_path = join(self.base_path, 'a') | 863 file_path = join(self.base_path, 'a') |
| 854 open(file_path, 'a').writelines('touched\n') | 864 open(file_path, 'a').writelines('touched\n') |
| 855 file_list = [] | 865 file_list = [] |
| 856 scm.revert(options, self.args, file_list) | 866 scm.revert(options, self.args, file_list) |
| 857 self.assertEquals(file_list, [file_path]) | 867 self.assertEquals(file_list, [file_path]) |
| 858 file_list = [] | 868 file_list = [] |
| 859 scm.diff(options, self.args, file_list) | 869 scm.diff(options, self.args, file_list) |
| 860 self.assertEquals(file_list, []) | 870 self.assertEquals(file_list, []) |
| 861 self.assertEquals(scm.revinfo(options, self.args, None), | 871 self.assertEquals(scm.revinfo(options, self.args, None), |
| 862 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 872 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 863 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 873 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
| 864 'Fast-forward\n a | 1 +\n b | 1 +\n' | 874 'Fast-forward\n a | 1 +\n b | 1 +\n' |
| 865 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 875 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
| 876 '________ running \'git submodule --quiet foreach git config -f ' |
| 877 '$toplevel/.git/config submodule.$name.ignore || git config -f ' |
| 878 '$toplevel/.git/config submodule.$name.ignore dirty\' in ' |
| 879 '\'%s\'\n\n' |
| 866 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 880 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
| 867 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.') | 881 'HEAD is now at a7142dc Personalized\n') % ( |
| 882 self.root_dir, join(self.root_dir, '.')) |
| 868 self.assertTrue(sys.stdout.getvalue().startswith(expectation)) | 883 self.assertTrue(sys.stdout.getvalue().startswith(expectation)) |
| 869 sys.stdout.close() | 884 sys.stdout.close() |
| 870 | 885 |
| 871 def testRevertNew(self): | 886 def testRevertNew(self): |
| 872 if not self.enabled: | 887 if not self.enabled: |
| 873 return | 888 return |
| 874 options = self.Options() | 889 options = self.Options() |
| 875 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 890 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 876 relpath=self.relpath) | 891 relpath=self.relpath) |
| 877 file_list = [] | 892 file_list = [] |
| 878 scm.update(options, None, file_list) | 893 scm.update(options, None, file_list) |
| 879 file_path = join(self.base_path, 'c') | 894 file_path = join(self.base_path, 'c') |
| 880 f = open(file_path, 'w') | 895 f = open(file_path, 'w') |
| 881 f.writelines('new\n') | 896 f.writelines('new\n') |
| 882 f.close() | 897 f.close() |
| 883 Popen(['git', 'add', 'c'], stdout=PIPE, | 898 Popen(['git', 'add', 'c'], stdout=PIPE, |
| 884 stderr=STDOUT, cwd=self.base_path).communicate() | 899 stderr=STDOUT, cwd=self.base_path).communicate() |
| 885 file_list = [] | 900 file_list = [] |
| 886 scm.revert(options, self.args, file_list) | 901 scm.revert(options, self.args, file_list) |
| 887 self.assertEquals(file_list, [file_path]) | 902 self.assertEquals(file_list, [file_path]) |
| 888 file_list = [] | 903 file_list = [] |
| 889 scm.diff(options, self.args, file_list) | 904 scm.diff(options, self.args, file_list) |
| 890 self.assertEquals(file_list, []) | 905 self.assertEquals(file_list, []) |
| 891 self.assertEquals(scm.revinfo(options, self.args, None), | 906 self.assertEquals(scm.revinfo(options, self.args, None), |
| 892 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 907 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 893 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 908 expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
| 894 'Fast-forward\n a | 1 +\n b | 1 +\n' | 909 'Fast-forward\n a | 1 +\n b | 1 +\n' |
| 895 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 910 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
| 911 '________ running \'git submodule --quiet foreach git config -f ' |
| 912 '$toplevel/.git/config submodule.$name.ignore || git config -f ' |
| 913 '$toplevel/.git/config submodule.$name.ignore dirty\' in ' |
| 914 '\'%s\'\n\n' |
| 896 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 915 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
| 897 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.') | 916 'HEAD is now at a7142dc Personalized\n') % ( |
| 917 self.root_dir, join(self.root_dir, '.')) |
| 898 self.assertTrue(sys.stdout.getvalue().startswith(expectation)) | 918 self.assertTrue(sys.stdout.getvalue().startswith(expectation)) |
| 899 sys.stdout.close() | 919 sys.stdout.close() |
| 900 | 920 |
| 901 def testStatusNew(self): | 921 def testStatusNew(self): |
| 902 if not self.enabled: | 922 if not self.enabled: |
| 903 return | 923 return |
| 904 options = self.Options() | 924 options = self.Options() |
| 905 file_path = join(self.base_path, 'a') | 925 file_path = join(self.base_path, 'a') |
| 906 open(file_path, 'a').writelines('touched\n') | 926 open(file_path, 'a').writelines('touched\n') |
| 907 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 927 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 962 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 943 relpath=self.relpath) | 963 relpath=self.relpath) |
| 944 file_list = [] | 964 file_list = [] |
| 945 scm.update(options, (), file_list) | 965 scm.update(options, (), file_list) |
| 946 self.assertEquals(file_list, expected_file_list) | 966 self.assertEquals(file_list, expected_file_list) |
| 947 self.assertEquals(scm.revinfo(options, (), None), | 967 self.assertEquals(scm.revinfo(options, (), None), |
| 948 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 968 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 949 self.checkstdout( | 969 self.checkstdout( |
| 950 '\n_____ . at refs/heads/master\n' | 970 '\n_____ . at refs/heads/master\n' |
| 951 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' | 971 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' |
| 952 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') | 972 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n' |
| 973 '\n________ running \'git submodule --quiet foreach git config -f ' |
| 974 '$toplevel/.git/config submodule.$name.ignore || git config -f ' |
| 975 '$toplevel/.git/config submodule.$name.ignore dirty\' in ' |
| 976 '\'%s\'\n' % self.root_dir) |
| 953 | 977 |
| 954 def testUpdateReset(self): | 978 def testUpdateReset(self): |
| 955 if not self.enabled: | 979 if not self.enabled: |
| 956 return | 980 return |
| 957 options = self.Options() | 981 options = self.Options() |
| 958 options.reset = True | 982 options.reset = True |
| 959 | 983 |
| 960 dir_path = join(self.base_path, 'c') | 984 dir_path = join(self.base_path, 'c') |
| 961 os.mkdir(dir_path) | 985 os.mkdir(dir_path) |
| 962 open(join(dir_path, 'nested'), 'w').writelines('new\n') | 986 open(join(dir_path, 'nested'), 'w').writelines('new\n') |
| 963 | 987 |
| 964 file_path = join(self.base_path, 'file') | 988 file_path = join(self.base_path, 'file') |
| 965 open(file_path, 'w').writelines('new\n') | 989 open(file_path, 'w').writelines('new\n') |
| 966 | 990 |
| 967 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 991 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 968 relpath=self.relpath) | 992 relpath=self.relpath) |
| 969 file_list = [] | 993 file_list = [] |
| 970 scm.update(options, (), file_list) | 994 scm.update(options, (), file_list) |
| 971 self.assert_(gclient_scm.os.path.isdir(dir_path)) | 995 self.assert_(gclient_scm.os.path.isdir(dir_path)) |
| 972 self.assert_(gclient_scm.os.path.isfile(file_path)) | 996 self.assert_(gclient_scm.os.path.isfile(file_path)) |
| 973 self.checkstdout( | 997 self.checkstdout( |
| 974 '\n________ running \'git reset --hard HEAD\' in \'%s\'' | 998 '\n________ running \'git reset --hard HEAD\' in \'%s\'' |
| 975 '\nHEAD is now at 069c602 A and B\n' | 999 '\nHEAD is now at 069c602 A and B\n' |
| 976 '\n_____ . at refs/heads/master\n' | 1000 '\n_____ . at refs/heads/master\n' |
| 977 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' | 1001 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' |
| 978 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n' | 1002 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n' |
| 979 % join(self.root_dir, '.')) | 1003 '\n________ running \'git submodule --quiet foreach git config -f ' |
| 1004 '$toplevel/.git/config submodule.$name.ignore || git config -f ' |
| 1005 '$toplevel/.git/config submodule.$name.ignore dirty\' in ' |
| 1006 '\'%s\'\n' % ( |
| 1007 join(self.root_dir, '.'), self.root_dir)) |
| 980 | 1008 |
| 981 def testUpdateResetDeleteUnversionedTrees(self): | 1009 def testUpdateResetDeleteUnversionedTrees(self): |
| 982 if not self.enabled: | 1010 if not self.enabled: |
| 983 return | 1011 return |
| 984 options = self.Options() | 1012 options = self.Options() |
| 985 options.reset = True | 1013 options.reset = True |
| 986 options.delete_unversioned_trees = True | 1014 options.delete_unversioned_trees = True |
| 987 | 1015 |
| 988 dir_path = join(self.base_path, 'dir') | 1016 dir_path = join(self.base_path, 'dir') |
| 989 os.mkdir(dir_path) | 1017 os.mkdir(dir_path) |
| 990 open(join(dir_path, 'nested'), 'w').writelines('new\n') | 1018 open(join(dir_path, 'nested'), 'w').writelines('new\n') |
| 991 | 1019 |
| 992 file_path = join(self.base_path, 'file') | 1020 file_path = join(self.base_path, 'file') |
| 993 open(file_path, 'w').writelines('new\n') | 1021 open(file_path, 'w').writelines('new\n') |
| 994 | 1022 |
| 995 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1023 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 996 relpath=self.relpath) | 1024 relpath=self.relpath) |
| 997 file_list = [] | 1025 file_list = [] |
| 998 scm.update(options, (), file_list) | 1026 scm.update(options, (), file_list) |
| 999 self.assert_(not gclient_scm.os.path.isdir(dir_path)) | 1027 self.assert_(not gclient_scm.os.path.isdir(dir_path)) |
| 1000 self.assert_(gclient_scm.os.path.isfile(file_path)) | 1028 self.assert_(gclient_scm.os.path.isfile(file_path)) |
| 1001 self.checkstdout( | 1029 self.checkstdout( |
| 1002 '\n________ running \'git reset --hard HEAD\' in \'%s\'' | 1030 '\n________ running \'git reset --hard HEAD\' in \'%s\'' |
| 1003 '\nHEAD is now at 069c602 A and B\n' | 1031 '\nHEAD is now at 069c602 A and B\n' |
| 1004 '\n_____ . at refs/heads/master\n' | 1032 '\n_____ . at refs/heads/master\n' |
| 1005 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' | 1033 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' |
| 1006 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n' | 1034 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n' |
| 1007 '\n_____ removing unversioned directory dir/\n' % join(self.root_dir, | 1035 '\n________ running \'git submodule --quiet foreach git config -f ' |
| 1008 '.')) | 1036 '$toplevel/.git/config submodule.$name.ignore || git config -f ' |
| 1037 '$toplevel/.git/config submodule.$name.ignore dirty\' in ' |
| 1038 '\'%s\'\n' |
| 1039 '\n_____ removing unversioned directory dir/\n' % ( |
| 1040 join(self.root_dir, '.'), self.root_dir)) |
| 1009 | 1041 |
| 1010 def testUpdateUnstagedConflict(self): | 1042 def testUpdateUnstagedConflict(self): |
| 1011 if not self.enabled: | 1043 if not self.enabled: |
| 1012 return | 1044 return |
| 1013 options = self.Options() | 1045 options = self.Options() |
| 1014 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1046 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 1015 relpath=self.relpath) | 1047 relpath=self.relpath) |
| 1016 file_path = join(self.base_path, 'b') | 1048 file_path = join(self.base_path, 'b') |
| 1017 open(file_path, 'w').writelines('conflict\n') | 1049 open(file_path, 'w').writelines('conflict\n') |
| 1018 try: | 1050 try: |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 | 1256 |
| 1225 if __name__ == '__main__': | 1257 if __name__ == '__main__': |
| 1226 if '-v' in sys.argv: | 1258 if '-v' in sys.argv: |
| 1227 logging.basicConfig( | 1259 logging.basicConfig( |
| 1228 level=logging.DEBUG, | 1260 level=logging.DEBUG, |
| 1229 format='%(asctime).19s %(levelname)s %(filename)s:' | 1261 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 1230 '%(lineno)s %(message)s') | 1262 '%(lineno)s %(message)s') |
| 1231 unittest.main() | 1263 unittest.main() |
| 1232 | 1264 |
| 1233 # vim: ts=2:sw=2:tw=80:et: | 1265 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |