Browse Source

try mocking FastAPI with a WhateverModule

Falko Schindler 2 months ago
parent
commit
557c71424f
1 changed files with 28 additions and 0 deletions
  1. 28 0
      profile_imports.py

+ 28 - 0
profile_imports.py

@@ -4,6 +4,7 @@
 
 import os
 import sys
+from types import ModuleType
 
 from line_profiler import LineProfiler
 
@@ -12,6 +13,33 @@ os.environ['MATPLOTLIB'] = 'false'
 profile = LineProfiler()
 sys.modules['__main__'].__dict__['profile'] = profile
 
+
+class WhateverModule(ModuleType):
+
+    def __getattr__(self, name):
+        return Whatever()
+
+
+class Whatever:
+
+    def __init__(self, *args, **kwargs):
+        pass
+
+    def __getattr__(self, name):
+        return Whatever()
+
+    def __call__(self, *args, **kwargs):
+        return Whatever()
+
+    def __mro_entries__(self, *args, **kwargs):
+        return (Whatever, )
+
+    def __add__(self, other):
+        return Whatever()
+
+
+sys.modules['fastapi'] = WhateverModule('fastapi')
+
 if True:
     import nicegui