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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 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_faulthandler.py ('k') | Lib/test/test_fnmatch.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 os, filecmp, shutil, tempfile 1 import os, filecmp, shutil, tempfile
2 import unittest 2 import unittest
3 from test import support 3 from test import support
4 4
5 class FileCompareTestCase(unittest.TestCase): 5 class FileCompareTestCase(unittest.TestCase):
6 def setUp(self): 6 def setUp(self):
7 self.name = support.TESTFN 7 self.name = support.TESTFN
8 self.name_same = support.TESTFN + '-same' 8 self.name_same = support.TESTFN + '-same'
9 self.name_diff = support.TESTFN + '-diff' 9 self.name_diff = support.TESTFN + '-diff'
10 data = 'Contents of file go here.\n' 10 data = 'Contents of file go here.\n'
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 output.close() 75 output.close()
76 76
77 def tearDown(self): 77 def tearDown(self):
78 for dir in (self.dir, self.dir_same, self.dir_diff): 78 for dir in (self.dir, self.dir_same, self.dir_diff):
79 shutil.rmtree(dir) 79 shutil.rmtree(dir)
80 80
81 def test_default_ignores(self): 81 def test_default_ignores(self):
82 self.assertIn('.hg', filecmp.DEFAULT_IGNORES) 82 self.assertIn('.hg', filecmp.DEFAULT_IGNORES)
83 83
84 def test_cmpfiles(self): 84 def test_cmpfiles(self):
85 self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file']) == 85 self.assertEqual(filecmp.cmpfiles(self.dir, self.dir, ['file']),
86 (['file'], [], []), 86 (['file'], [], []),
87 "Comparing directory to itself fails") 87 "Comparing directory to itself fails")
88 self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file']) == 88 self.assertEqual(filecmp.cmpfiles(self.dir, self.dir_same, ['file']),
89 (['file'], [], []), 89 (['file'], [], []),
90 "Comparing directory to same fails") 90 "Comparing directory to same fails")
91 91
92 # Try it with shallow=False 92 # Try it with shallow=False
93 self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file'], 93 self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file'],
94 shallow=False) == 94 shallow=False) ==
95 (['file'], [], []), 95 (['file'], [], []),
96 "Comparing directory to itself fails") 96 "Comparing directory to itself fails")
97 self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file'], 97 self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file'],
98 shallow=False), 98 shallow=False),
(...skipping 14 matching lines...) Expand all
113 # Check attributes for comparison of two identical directories 113 # Check attributes for comparison of two identical directories
114 left_dir, right_dir = self.dir, self.dir_same 114 left_dir, right_dir = self.dir, self.dir_same
115 d = filecmp.dircmp(left_dir, right_dir) 115 d = filecmp.dircmp(left_dir, right_dir)
116 self.assertEqual(d.left, left_dir) 116 self.assertEqual(d.left, left_dir)
117 self.assertEqual(d.right, right_dir) 117 self.assertEqual(d.right, right_dir)
118 if self.caseinsensitive: 118 if self.caseinsensitive:
119 self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) 119 self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
120 else: 120 else:
121 self.assertEqual([d.left_list, d.right_list],[['file'], ['file']]) 121 self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
122 self.assertEqual(d.common, ['file']) 122 self.assertEqual(d.common, ['file'])
123 self.assertTrue(d.left_only == d.right_only == []) 123 self.assertEqual(d.left_only, [])
124 self.assertEqual(d.left_only, [])
124 self.assertEqual(d.same_files, ['file']) 125 self.assertEqual(d.same_files, ['file'])
125 self.assertEqual(d.diff_files, []) 126 self.assertEqual(d.diff_files, [])
126 127
127 # Check attributes for comparison of two different directories 128 # Check attributes for comparison of two different directories
128 left_dir, right_dir = self.dir, self.dir_diff 129 left_dir, right_dir = self.dir, self.dir_diff
129 d = filecmp.dircmp(left_dir, right_dir) 130 d = filecmp.dircmp(left_dir, right_dir)
130 self.assertEqual(d.left, left_dir) 131 self.assertEqual(d.left, left_dir)
131 self.assertEqual(d.right, right_dir) 132 self.assertEqual(d.right, right_dir)
132 self.assertEqual(d.left_list, ['file']) 133 self.assertEqual(d.left_list, ['file'])
133 self.assertTrue(d.right_list == ['file', 'file2']) 134 self.assertTrue(d.right_list == ['file', 'file2'])
(...skipping 10 matching lines...) Expand all
144 d = filecmp.dircmp(self.dir, self.dir_diff) 145 d = filecmp.dircmp(self.dir, self.dir_diff)
145 self.assertEqual(d.same_files, ['file']) 146 self.assertEqual(d.same_files, ['file'])
146 self.assertEqual(d.diff_files, ['file2']) 147 self.assertEqual(d.diff_files, ['file2'])
147 148
148 149
149 def test_main(): 150 def test_main():
150 support.run_unittest(FileCompareTestCase, DirCompareTestCase) 151 support.run_unittest(FileCompareTestCase, DirCompareTestCase)
151 152
152 if __name__ == "__main__": 153 if __name__ == "__main__":
153 test_main() 154 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_faulthandler.py ('k') | Lib/test/test_fnmatch.py » ('j') | no next file with comments »

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