MCPcopy
hub / github.com/saltstack/salt / setUp

Method setUp

tests/unit/test_loader.py:1156–1199  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1154 os.makedirs(RUNTIME_VARS.TMP)
1155
1156 def setUp(self):
1157 self.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
1158 self.addCleanup(shutil.rmtree, self.tmp_dir, ignore_errors=True)
1159 os.makedirs(self.module_dir)
1160
1161 self.lib_count = collections.defaultdict(int) # mapping of path -> count
1162
1163 # bootstrap libs
1164 with salt.utils.files.fopen(
1165 os.path.join(self.module_dir, "__init__.py"), "w"
1166 ) as fh:
1167 # No .decode() needed here as deep_init_base is defined as str and
1168 # not bytes.
1169 fh.write(
1170 salt.utils.stringutils.to_str(deep_init_base.format(self.module_name))
1171 )
1172 fh.flush()
1173 os.fsync(fh.fileno()) # flush to disk
1174
1175 self.lib_paths = {}
1176 dir_path = self.module_dir
1177 for lib_name in self.libs:
1178 dir_path = os.path.join(dir_path, lib_name)
1179 self.lib_paths[lib_name] = dir_path
1180 os.makedirs(dir_path)
1181 self.update_lib(lib_name)
1182
1183 opts = copy.deepcopy(self.opts)
1184 dirs = salt.loader._module_dirs(opts, "modules", "module")
1185 dirs.append(self.tmp_dir)
1186 self.utils = salt.loader.utils(opts)
1187 self.proxy = salt.loader.proxy(opts)
1188 self.minion_mods = salt.loader.minion_mods(opts)
1189 self.loader = salt.loader.LazyLoader(
1190 dirs,
1191 copy.deepcopy(opts),
1192 tag="module",
1193 pack={
1194 "__utils__": self.utils,
1195 "__proxy__": self.proxy,
1196 "__salt__": self.minion_mods,
1197 },
1198 )
1199 self.assertIn(f"{self.module_name}.top", self.loader)
1200
1201 def tearDown(self):
1202 del self.tmp_dir

Callers

nothing calls this directly

Calls 6

update_libMethod · 0.95
formatMethod · 0.80
writeMethod · 0.45
flushMethod · 0.45
filenoMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected