(self, source, depth, mod_base="runpy_test",
*, namespace=False, parent_namespaces=False)
| 229 | return pkg_fname |
| 230 | |
| 231 | def _make_pkg(self, source, depth, mod_base="runpy_test", |
| 232 | *, namespace=False, parent_namespaces=False): |
| 233 | # Enforce a couple of internal sanity checks on test cases |
| 234 | if (namespace or parent_namespaces) and not depth: |
| 235 | raise RuntimeError("Can't mark top level module as a " |
| 236 | "namespace package") |
| 237 | pkg_name = "__runpy_pkg__" |
| 238 | test_fname = mod_base+os.extsep+"py" |
| 239 | pkg_dir = sub_dir = os.path.realpath(tempfile.mkdtemp()) |
| 240 | if verbose > 1: print(" Package tree in:", sub_dir) |
| 241 | sys.path.insert(0, pkg_dir) |
| 242 | if verbose > 1: print(" Updated sys.path:", sys.path[0]) |
| 243 | if depth: |
| 244 | namespace_flags = [parent_namespaces] * depth |
| 245 | namespace_flags[-1] = namespace |
| 246 | for namespace_flag in namespace_flags: |
| 247 | sub_dir = os.path.join(sub_dir, pkg_name) |
| 248 | pkg_fname = self._add_pkg_dir(sub_dir, namespace_flag) |
| 249 | if verbose > 1: print(" Next level in:", sub_dir) |
| 250 | if verbose > 1: print(" Created:", pkg_fname) |
| 251 | mod_fname = os.path.join(sub_dir, test_fname) |
| 252 | with open(mod_fname, "w") as mod_file: |
| 253 | mod_file.write(source) |
| 254 | if verbose > 1: print(" Created:", mod_fname) |
| 255 | mod_name = (pkg_name+".")*depth + mod_base |
| 256 | mod_spec = importlib.util.spec_from_file_location(mod_name, |
| 257 | mod_fname) |
| 258 | return pkg_dir, mod_fname, mod_name, mod_spec |
| 259 | |
| 260 | def _del_pkg(self, top): |
| 261 | for entry in list(sys.modules): |
no test coverage detected