MCPcopy Index your code
hub / github.com/python/cpython / setUp

Method setUp

Lib/test/test_filecmp.py:80–126  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

78
79class DirCompareTestCase(unittest.TestCase):
80 def setUp(self):
81 tmpdir = tempfile.gettempdir()
82 self.dir = os.path.join(tmpdir, 'dir')
83 self.dir_same = os.path.join(tmpdir, 'dir-same')
84 self.dir_diff = os.path.join(tmpdir, 'dir-diff')
85 self.dir_diff_file = os.path.join(tmpdir, 'dir-diff-file')
86 self.dir_same_shallow = os.path.join(tmpdir, 'dir-same-shallow')
87
88 # Another dir is created under dir_same, but it has a name from the
89 # ignored list so it should not affect testing results.
90 self.dir_ignored = os.path.join(self.dir_same, '.hg')
91
92 self.caseinsensitive = os.path.normcase('A') == os.path.normcase('a')
93 data = 'Contents of file go here.\n'
94
95 shutil.rmtree(self.dir, True)
96 os.mkdir(self.dir)
97 subdir_path = os.path.join(self.dir, 'subdir')
98 os.mkdir(subdir_path)
99 dir_file_path = os.path.join(self.dir, "file")
100 with open(dir_file_path, 'w', encoding="utf-8") as output:
101 output.write(data)
102
103 for dir in (self.dir_same, self.dir_same_shallow,
104 self.dir_diff, self.dir_diff_file):
105 shutil.rmtree(dir, True)
106 os.mkdir(dir)
107 subdir_path = os.path.join(dir, 'subdir')
108 os.mkdir(subdir_path)
109 if self.caseinsensitive and dir is self.dir_same:
110 fn = 'FiLe' # Verify case-insensitive comparison
111 else:
112 fn = 'file'
113
114 file_path = os.path.join(dir, fn)
115
116 if dir is self.dir_same_shallow:
117 _create_file_shallow_equal(dir_file_path, file_path)
118 else:
119 shutil.copy2(dir_file_path, file_path)
120
121 with open(os.path.join(self.dir_diff, 'file2'), 'w', encoding="utf-8") as output:
122 output.write('An extra file.\n')
123
124 # Add different file2 with respect to dir_diff
125 with open(os.path.join(self.dir_diff_file, 'file2'), 'w', encoding="utf-8") as output:
126 output.write('Different contents.\n')
127
128
129 def tearDown(self):

Callers

nothing calls this directly

Calls 6

normcaseMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
mkdirMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected