Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(10)

Side by Side Diff: Lib/test/test_tarfile.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_sys.py ('k') | Lib/test/test_threaded_import.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import sys 1 import sys
2 import os 2 import os
3 import io 3 import io
4 import shutil 4 import shutil
5 import io 5 import io
6 from hashlib import md5 6 from hashlib import md5
7 import errno 7 import errno
8 8
9 import unittest 9 import unittest
10 import tarfile 10 import tarfile
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 self.assertTrue(tar.getnames() == [], "added the archive to itself") 886 self.assertTrue(tar.getnames() == [], "added the archive to itself")
887 finally: 887 finally:
888 tar.close() 888 tar.close()
889 889
890 def test_exclude(self): 890 def test_exclude(self):
891 tempdir = os.path.join(TEMPDIR, "exclude") 891 tempdir = os.path.join(TEMPDIR, "exclude")
892 os.mkdir(tempdir) 892 os.mkdir(tempdir)
893 try: 893 try:
894 for name in ("foo", "bar", "baz"): 894 for name in ("foo", "bar", "baz"):
895 name = os.path.join(tempdir, name) 895 name = os.path.join(tempdir, name)
896 support.create_empty_file(name) 896 open(name, "wb").close()
897 897
898 exclude = os.path.isfile 898 exclude = os.path.isfile
899 899
900 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") 900 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
901 try: 901 try:
902 with support.check_warnings(("use the filter argument", 902 with support.check_warnings(("use the filter argument",
903 DeprecationWarning)): 903 DeprecationWarning)):
904 tar.add(tempdir, arcname="empty_dir", exclude=exclude) 904 tar.add(tempdir, arcname="empty_dir", exclude=exclude)
905 finally: 905 finally:
906 tar.close() 906 tar.close()
907 907
908 tar = tarfile.open(tmpname, "r") 908 tar = tarfile.open(tmpname, "r")
909 try: 909 try:
910 self.assertEqual(len(tar.getmembers()), 1) 910 self.assertEqual(len(tar.getmembers()), 1)
911 self.assertEqual(tar.getnames()[0], "empty_dir") 911 self.assertEqual(tar.getnames()[0], "empty_dir")
912 finally: 912 finally:
913 tar.close() 913 tar.close()
914 finally: 914 finally:
915 shutil.rmtree(tempdir) 915 shutil.rmtree(tempdir)
916 916
917 def test_filter(self): 917 def test_filter(self):
918 tempdir = os.path.join(TEMPDIR, "filter") 918 tempdir = os.path.join(TEMPDIR, "filter")
919 os.mkdir(tempdir) 919 os.mkdir(tempdir)
920 try: 920 try:
921 for name in ("foo", "bar", "baz"): 921 for name in ("foo", "bar", "baz"):
922 name = os.path.join(tempdir, name) 922 name = os.path.join(tempdir, name)
923 support.create_empty_file(name) 923 open(name, "wb").close()
924 924
925 def filter(tarinfo): 925 def filter(tarinfo):
926 if os.path.basename(tarinfo.name) == "bar": 926 if os.path.basename(tarinfo.name) == "bar":
927 return 927 return
928 tarinfo.uid = 123 928 tarinfo.uid = 123
929 tarinfo.uname = "foo" 929 tarinfo.uname = "foo"
930 return tarinfo 930 return tarinfo
931 931
932 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") 932 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
933 try: 933 try:
(...skipping 18 matching lines...) Expand all
952 952
953 # Guarantee that stored pathnames are not modified. Don't 953 # Guarantee that stored pathnames are not modified. Don't
954 # remove ./ or ../ or double slashes. Still make absolute 954 # remove ./ or ../ or double slashes. Still make absolute
955 # pathnames relative. 955 # pathnames relative.
956 # For details see bug #6054. 956 # For details see bug #6054.
957 def _test_pathname(self, path, cmp_path=None, dir=False): 957 def _test_pathname(self, path, cmp_path=None, dir=False):
958 # Create a tarfile with an empty member named path 958 # Create a tarfile with an empty member named path
959 # and compare the stored name with the original. 959 # and compare the stored name with the original.
960 foo = os.path.join(TEMPDIR, "foo") 960 foo = os.path.join(TEMPDIR, "foo")
961 if not dir: 961 if not dir:
962 support.create_empty_file(foo) 962 open(foo, "w").close()
963 else: 963 else:
964 os.mkdir(foo) 964 os.mkdir(foo)
965 965
966 tar = tarfile.open(tmpname, self.mode) 966 tar = tarfile.open(tmpname, self.mode)
967 try: 967 try:
968 tar.add(foo, arcname=path) 968 tar.add(foo, arcname=path)
969 finally: 969 finally:
970 tar.close() 970 tar.close()
971 971
972 tar = tarfile.open(tmpname, "r") 972 tar = tarfile.open(tmpname, "r")
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 ] 1804 ]
1805 1805
1806 try: 1806 try:
1807 support.run_unittest(*tests) 1807 support.run_unittest(*tests)
1808 finally: 1808 finally:
1809 if os.path.exists(TEMPDIR): 1809 if os.path.exists(TEMPDIR):
1810 shutil.rmtree(TEMPDIR) 1810 shutil.rmtree(TEMPDIR)
1811 1811
1812 if __name__ == "__main__": 1812 if __name__ == "__main__":
1813 test_main() 1813 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_sys.py ('k') | Lib/test/test_threaded_import.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+