general: add an adhoc test for checking mixin behaviour with namespace packages and __init__.py hack

also use that hack in my.fbmessenger
This commit is contained in:
Dima Gerasimov 2022-06-01 21:57:36 +01:00 committed by karlicoss
parent 179b657eea
commit 8336d18434
4 changed files with 30 additions and 2 deletions

View file

@ -59,7 +59,7 @@ check_warn('-c', 'from my.fbmessenger import *')
# note: dump_chat_history should really be deprecated, but it's a quick way to check we actually fell back to fbmessenger/export.py
# NOTE: this is the most common legacy usecase
check_warn('-c', 'from my.fbmessenger import messages, dump_chat_history')
check_warn('-m', 'my.core', 'query' , 'my.fbmessenger.messages')
check_warn('-m', 'my.core', 'query' , 'my.fbmessenger.messages', '-o', 'pprint', '--limit=10')
check_warn('-m', 'my.core', 'doctor', 'my.fbmessenger')
# todo kinda annoying it doesn't work when executed as -c (but does as script!)
@ -69,8 +69,14 @@ check_ok ('-c', 'from my.fbmessenger import export', run_as_cmd=False)
check_ok ('-c', 'import my.fbmessenger.export')
check_ok ('-c', 'from my.fbmessenger.export import *')
check_ok ('-c', 'from my.fbmessenger.export import messages, dump_chat_history')
check_ok ('-m', 'my.core', 'query' , 'my.fbmessenger.export.messages')
check_ok ('-m', 'my.core', 'query' , 'my.fbmessenger.export.messages', '-o', 'pprint', '--limit=10')
check_ok ('-m', 'my.core', 'doctor', 'my.fbmessenger.export')
# NOTE:
# to check that overlays work, run something like
# PYTHONPATH=misc/overlay_for_init_py_test/ hpi query my.fbmessenger.all.messages -s -o pprint --limit=10
# you should see 1, 2, 3 from mixin.py
# TODO would be nice to add an automated test for this
# TODO with reddit, currently these don't work properly at all
# only when imported from scripts etc?

View file

@ -0,0 +1,7 @@
from my.fbmessenger import export
from . import mixin
def messages():
yield from mixin.messages()
yield from export.messages()

View file

@ -0,0 +1,2 @@
def messages():
yield from ['1', '2', '3']

View file

@ -57,3 +57,16 @@ REQUIRES = [
# to prevent it from apprearing in modules list/doctor
from ..core import __NOT_HPI_MODULE__
###
# this is to trick mypy into treating this as a proper namespace package
# should only be used for backwards compatibility on packages that are convernted into namespace & all.py pattern
# - https://www.python.org/dev/peps/pep-0382/#namespace-packages-today
# - https://github.com/karlicoss/hpi_namespace_experiment
# - discussion here https://memex.zulipchat.com/#narrow/stream/279601-hpi/topic/extending.20HPI/near/269946944
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# 'this' source tree ends up first in the pythonpath when we extend_path()
# so we need to move 'this' source tree towards the end to make sure we prioritize overlays
__path__ = __path__[1:] + __path__[:1]
###