From 1776c3aa4583ebb48e42f72a8d5489ef88edf1ae Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 23 Jan 2020 14:34:12 +0100 Subject: [PATCH] Add test for fixup_module_metadata --- fbchat/_fix_module_metadata.py | 6 ++++++ tests/test_module_renaming.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/test_module_renaming.py diff --git a/fbchat/_fix_module_metadata.py b/fbchat/_fix_module_metadata.py index d2faa38..f3e1618 100644 --- a/fbchat/_fix_module_metadata.py +++ b/fbchat/_fix_module_metadata.py @@ -13,6 +13,12 @@ import os def fixup_module_metadata(namespace): def fix_one(qualname, name, obj): + # Custom extension, to handle classmethods, staticmethods and properties + if isinstance(obj, (classmethod, staticmethod)): + obj = obj.__func__ + if isinstance(obj, property): + obj = obj.fget + mod = getattr(obj, "__module__", None) if mod is not None and mod.startswith("fbchat."): obj.__module__ = "fbchat" diff --git a/tests/test_module_renaming.py b/tests/test_module_renaming.py new file mode 100644 index 0000000..f92aa52 --- /dev/null +++ b/tests/test_module_renaming.py @@ -0,0 +1,16 @@ +import fbchat + + +def test_module_renaming(): + assert fbchat.Message.__module__ == "fbchat" + assert fbchat.Group.__module__ == "fbchat" + assert fbchat.Event.__module__ == "fbchat" + assert fbchat.User.block.__module__ == "fbchat" + assert fbchat.Session.login.__func__.__module__ == "fbchat" + assert fbchat.Session._from_session.__func__.__module__ == "fbchat" + assert fbchat.Message.session.fget.__module__ == "fbchat" + assert fbchat.Session.__repr__.__module__ == "fbchat" + + +def test_did_not_rename(): + assert fbchat._graphql.queries_to_json.__module__ != "fbchat"