コード例 #1
0
ファイル: test_utils.py プロジェクト: zwdiscover/scanpy
def test_descend_classes_and_funcs():
    # create module hierarchy
    a = ModuleType('a')
    a.b = ModuleType('a.b')

    # populate with classes
    a.A = type('A', (), {})
    a.A.__module__ = a.__name__
    a.b.B = type('B', (), {})
    a.b.B.__module__ = a.b.__name__

    # create a loop to check if that gets caught
    a.b.a = a

    assert {a.A, a.b.B} == set(descend_classes_and_funcs(a, 'a'))
コード例 #2
0
import inspect
import os
from types import FunctionType
from pathlib import Path

import pytest
from scanpy._utils import descend_classes_and_funcs

# CLI is locally not imported by default but on travis it is?
import scanpy.cli

mod_dir = Path(scanpy.__file__).parent
proj_dir = mod_dir.parent

scanpy_functions = [
    c_or_f for c_or_f in descend_classes_and_funcs(scanpy, "scanpy")
    if isinstance(c_or_f, FunctionType)
]


@pytest.fixture
def in_project_dir():
    wd_orig = Path.cwd()
    os.chdir(proj_dir)
    try:
        yield proj_dir
    finally:
        os.chdir(wd_orig)


@pytest.mark.parametrize("f", scanpy_functions)