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

Delta Between Two Patch Sets: Lib/test/test_filecmp.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 12 months ago
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_faulthandler.py ('k') | Lib/test/test_fnmatch.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 20 matching lines...) Expand all
31 self.assertTrue(filecmp.cmp(self.name, self.name, shallow=False), 31 self.assertTrue(filecmp.cmp(self.name, self.name, shallow=False),
32 "Comparing file to identical file fails") 32 "Comparing file to identical file fails")
33 self.assertTrue(filecmp.cmp(self.name, self.name), 33 self.assertTrue(filecmp.cmp(self.name, self.name),
34 "Comparing file to identical file fails") 34 "Comparing file to identical file fails")
35 35
36 def test_different(self): 36 def test_different(self):
37 self.assertFalse(filecmp.cmp(self.name, self.name_diff), 37 self.assertFalse(filecmp.cmp(self.name, self.name_diff),
38 "Mismatched files compare as equal") 38 "Mismatched files compare as equal")
39 self.assertFalse(filecmp.cmp(self.name, self.dir), 39 self.assertFalse(filecmp.cmp(self.name, self.dir),
40 "File and directory compare as equal") 40 "File and directory compare as equal")
41
42 def test_cache_clear(self):
43 first_compare = filecmp.cmp(self.name, self.name_same, shallow=False)
44 second_compare = filecmp.cmp(self.name, self.name_diff, shallow=False)
45 filecmp.clear_cache()
46 self.assertTrue(len(filecmp._cache) == 0,
47 "Cache not cleared after calling clear_cache")
41 48
42 class DirCompareTestCase(unittest.TestCase): 49 class DirCompareTestCase(unittest.TestCase):
43 def setUp(self): 50 def setUp(self):
44 tmpdir = tempfile.gettempdir() 51 tmpdir = tempfile.gettempdir()
45 self.dir = os.path.join(tmpdir, 'dir') 52 self.dir = os.path.join(tmpdir, 'dir')
46 self.dir_same = os.path.join(tmpdir, 'dir-same') 53 self.dir_same = os.path.join(tmpdir, 'dir-same')
47 self.dir_diff = os.path.join(tmpdir, 'dir-diff') 54 self.dir_diff = os.path.join(tmpdir, 'dir-diff')
48 55
49 # Another dir is created under dir_same, but it has a name from the 56 # Another dir is created under dir_same, but it has a name from the
50 # ignored list so it should not affect testing results. 57 # ignored list so it should not affect testing results.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 # Check attributes for comparison of two identical directories 113 # Check attributes for comparison of two identical directories
107 left_dir, right_dir = self.dir, self.dir_same 114 left_dir, right_dir = self.dir, self.dir_same
108 d = filecmp.dircmp(left_dir, right_dir) 115 d = filecmp.dircmp(left_dir, right_dir)
109 self.assertEqual(d.left, left_dir) 116 self.assertEqual(d.left, left_dir)
110 self.assertEqual(d.right, right_dir) 117 self.assertEqual(d.right, right_dir)
111 if self.caseinsensitive: 118 if self.caseinsensitive:
112 self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) 119 self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
113 else: 120 else:
114 self.assertEqual([d.left_list, d.right_list],[['file'], ['file']]) 121 self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
115 self.assertEqual(d.common, ['file']) 122 self.assertEqual(d.common, ['file'])
116 self.assertTrue(d.left_only == d.right_only == []) 123 self.assertEqual(d.left_only, [])
124 self.assertEqual(d.left_only, [])
117 self.assertEqual(d.same_files, ['file']) 125 self.assertEqual(d.same_files, ['file'])
118 self.assertEqual(d.diff_files, []) 126 self.assertEqual(d.diff_files, [])
119 127
120 # Check attributes for comparison of two different directories 128 # Check attributes for comparison of two different directories
121 left_dir, right_dir = self.dir, self.dir_diff 129 left_dir, right_dir = self.dir, self.dir_diff
122 d = filecmp.dircmp(left_dir, right_dir) 130 d = filecmp.dircmp(left_dir, right_dir)
123 self.assertEqual(d.left, left_dir) 131 self.assertEqual(d.left, left_dir)
124 self.assertEqual(d.right, right_dir) 132 self.assertEqual(d.right, right_dir)
125 self.assertEqual(d.left_list, ['file']) 133 self.assertEqual(d.left_list, ['file'])
126 self.assertTrue(d.right_list == ['file', 'file2']) 134 self.assertTrue(d.right_list == ['file', 'file2'])
(...skipping 10 matching lines...) Expand all
137 d = filecmp.dircmp(self.dir, self.dir_diff) 145 d = filecmp.dircmp(self.dir, self.dir_diff)
138 self.assertEqual(d.same_files, ['file']) 146 self.assertEqual(d.same_files, ['file'])
139 self.assertEqual(d.diff_files, ['file2']) 147 self.assertEqual(d.diff_files, ['file2'])
140 148
141 149
142 def test_main(): 150 def test_main():
143 support.run_unittest(FileCompareTestCase, DirCompareTestCase) 151 support.run_unittest(FileCompareTestCase, DirCompareTestCase)
144 152
145 if __name__ == "__main__": 153 if __name__ == "__main__":
146 test_main() 154 test_main()
LEFTRIGHT

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