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

Method setUp

Lib/test/test_pathlib/test_pathlib.py:1130–1167  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1128 can_symlink = os_helper.can_symlink()
1129
1130 def setUp(self):
1131 name = self.id().split('.')[-1]
1132 if name in _tests_needing_symlinks and not self.can_symlink:
1133 self.skipTest('requires symlinks')
1134 super().setUp()
1135 os.mkdir(self.base)
1136 os.mkdir(os.path.join(self.base, 'dirA'))
1137 os.mkdir(os.path.join(self.base, 'dirB'))
1138 os.mkdir(os.path.join(self.base, 'dirC'))
1139 os.mkdir(os.path.join(self.base, 'dirC', 'dirD'))
1140 os.mkdir(os.path.join(self.base, 'dirE'))
1141 with open(os.path.join(self.base, 'fileA'), 'wb') as f:
1142 f.write(b"this is file A\n")
1143 with open(os.path.join(self.base, 'dirB', 'fileB'), 'wb') as f:
1144 f.write(b"this is file B\n")
1145 with open(os.path.join(self.base, 'dirC', 'fileC'), 'wb') as f:
1146 f.write(b"this is file C\n")
1147 with open(os.path.join(self.base, 'dirC', 'novel.txt'), 'wb') as f:
1148 f.write(b"this is a novel\n")
1149 with open(os.path.join(self.base, 'dirC', 'dirD', 'fileD'), 'wb') as f:
1150 f.write(b"this is file D\n")
1151 os.chmod(os.path.join(self.base, 'dirE'), 0)
1152 if self.can_symlink:
1153 # Relative symlinks.
1154 os.symlink('fileA', os.path.join(self.base, 'linkA'))
1155 os.symlink('non-existing', os.path.join(self.base, 'brokenLink'))
1156 os.symlink('dirB',
1157 os.path.join(self.base, 'linkB'),
1158 target_is_directory=True)
1159 os.symlink(os.path.join('..', 'dirB'),
1160 os.path.join(self.base, 'dirA', 'linkC'),
1161 target_is_directory=True)
1162 # This one goes upwards, creating a loop.
1163 os.symlink(os.path.join('..', 'dirB'),
1164 os.path.join(self.base, 'dirB', 'linkD'),
1165 target_is_directory=True)
1166 # Broken symlink (pointing to itself).
1167 os.symlink('brokenLinkLoop', os.path.join(self.base, 'brokenLinkLoop'))
1168
1169 def tearDown(self):
1170 os.chmod(os.path.join(self.base, 'dirE'), 0o777)

Callers

nothing calls this directly

Calls 9

superClass · 0.85
skipTestMethod · 0.80
openFunction · 0.50
splitMethod · 0.45
idMethod · 0.45
mkdirMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
chmodMethod · 0.45

Tested by

no test coverage detected