Compare commits
3 Commits
7f602db50d
...
b461b94f05
| Author | SHA1 | Date |
|---|---|---|
|
|
b461b94f05 | |
|
|
4d6645d25d | |
|
|
da6f0aeef3 |
|
|
@ -4,7 +4,6 @@
|
||||||
'''
|
'''
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
from types import ModuleType
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import tractor
|
import tractor
|
||||||
|
|
@ -58,32 +57,28 @@ def test_implicit_mod_name_applied_for_child(
|
||||||
mod_code: str = (
|
mod_code: str = (
|
||||||
f'import tractor\n'
|
f'import tractor\n'
|
||||||
f'\n'
|
f'\n'
|
||||||
# if you need to trace `testdir` stuff @ import-time..
|
# f'breakpoint()\n' # if you want to trace it all
|
||||||
# f'breakpoint()\n'
|
|
||||||
f'log = tractor.log.get_logger(pkg_name="{proj_name}")\n'
|
f'log = tractor.log.get_logger(pkg_name="{proj_name}")\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
# create a sub-module for each pkg layer
|
# create a sub-module for each pkg layer
|
||||||
_lib = testdir.mkpydir(proj_name)
|
_lib = testdir.mkpydir(proj_name)
|
||||||
pkg: Path = Path(_lib)
|
pkg: Path = Path(_lib)
|
||||||
pkg_init_mod: Path = pkg / "__init__.py"
|
|
||||||
pkg_init_mod.write_text(mod_code)
|
|
||||||
|
|
||||||
subpkg: Path = pkg / 'subpkg'
|
subpkg: Path = pkg / 'subpkg'
|
||||||
subpkg.mkdir()
|
subpkg.mkdir()
|
||||||
subpkgmod: Path = subpkg / "__init__.py"
|
|
||||||
subpkgmod.touch()
|
pkgmod: Path = subpkg / "__init__.py"
|
||||||
subpkgmod.write_text(mod_code)
|
pkgmod.touch()
|
||||||
|
|
||||||
_submod: Path = testdir.makepyfile(
|
_submod: Path = testdir.makepyfile(
|
||||||
_mod=mod_code,
|
_mod=mod_code,
|
||||||
)
|
)
|
||||||
|
|
||||||
pkg_submod = pkg / 'mod.py'
|
pkg_mod = pkg / 'mod.py'
|
||||||
pkg_subpkg_submod = subpkg / 'submod.py'
|
pkg_subpkg_submod = subpkg / 'submod.py'
|
||||||
shutil.copyfile(
|
shutil.copyfile(
|
||||||
_submod,
|
_submod,
|
||||||
pkg_submod,
|
pkg_mod,
|
||||||
)
|
)
|
||||||
shutil.copyfile(
|
shutil.copyfile(
|
||||||
_submod,
|
_submod,
|
||||||
|
|
@ -96,11 +91,10 @@ def test_implicit_mod_name_applied_for_child(
|
||||||
# XXX NOTE, once the "top level" pkg mod has been
|
# XXX NOTE, once the "top level" pkg mod has been
|
||||||
# imported, we can then use `import` syntax to
|
# imported, we can then use `import` syntax to
|
||||||
# import it's sub-pkgs and modules.
|
# import it's sub-pkgs and modules.
|
||||||
subpkgmod: ModuleType = _code_load.load_module_from_path(
|
pkgmod = _code_load.load_module_from_path(
|
||||||
Path(pkg / '__init__.py'),
|
Path(pkg / '__init__.py'),
|
||||||
module_name=proj_name,
|
module_name=proj_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
pkg_root_log = log.get_logger(
|
pkg_root_log = log.get_logger(
|
||||||
pkg_name=proj_name,
|
pkg_name=proj_name,
|
||||||
mk_sublog=False,
|
mk_sublog=False,
|
||||||
|
|
@ -113,31 +107,16 @@ def test_implicit_mod_name_applied_for_child(
|
||||||
# ^TODO! test this same output but created via a `get_logger()`
|
# ^TODO! test this same output but created via a `get_logger()`
|
||||||
# call in the `snakelib.__init__py`!!
|
# call in the `snakelib.__init__py`!!
|
||||||
|
|
||||||
# NOTE, the pkg-level "init mod" should of course
|
# a first-pkg-level module should only
|
||||||
# have the same name as the package ns-path.
|
# use
|
||||||
import snakelib as init_mod
|
|
||||||
assert init_mod.log.name == proj_name
|
|
||||||
|
|
||||||
# NOTE, a first-pkg-level sub-module should only
|
|
||||||
# use the package-name since the leaf-node-module
|
|
||||||
# will be included in log headers by default.
|
|
||||||
from snakelib import mod
|
from snakelib import mod
|
||||||
assert mod.log.name == proj_name
|
assert mod.log.name == proj_name
|
||||||
|
|
||||||
from snakelib import subpkg
|
|
||||||
assert (
|
|
||||||
subpkg.log.name
|
|
||||||
==
|
|
||||||
subpkg.__package__
|
|
||||||
==
|
|
||||||
f'{proj_name}.subpkg'
|
|
||||||
)
|
|
||||||
|
|
||||||
from snakelib.subpkg import submod
|
from snakelib.subpkg import submod
|
||||||
assert (
|
assert (
|
||||||
submod.log.name
|
submod.log.name
|
||||||
==
|
==
|
||||||
submod.__package__
|
submod.__package__ # ?TODO, use this in `.get_logger()` instead?
|
||||||
==
|
==
|
||||||
f'{proj_name}.subpkg'
|
f'{proj_name}.subpkg'
|
||||||
)
|
)
|
||||||
|
|
@ -146,6 +125,8 @@ def test_implicit_mod_name_applied_for_child(
|
||||||
assert len(sub_logs) == 1 # only one nested sub-pkg module
|
assert len(sub_logs) == 1 # only one nested sub-pkg module
|
||||||
assert submod.log.logger in sub_logs
|
assert submod.log.logger in sub_logs
|
||||||
|
|
||||||
|
# breakpoint()
|
||||||
|
|
||||||
|
|
||||||
# TODO, moar tests against existing feats:
|
# TODO, moar tests against existing feats:
|
||||||
# ------ - ------
|
# ------ - ------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue