-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_00_exports.py
42 lines (30 loc) · 1.33 KB
/
test_00_exports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
""" check the export list to ensure only the public API is exported by pgpy.__init__
"""
import pytest
import importlib
import inspect
modules = ['pgpy.constants',
'pgpy.decorators',
'pgpy.errors',
'pgpy.pgp',
'pgpy.symenc',
'pgpy.types',
'pgpy.packet.fields',
'pgpy.packet.packets',
'pgpy.packet.types',
'pgpy.packet.subpackets.signature',
'pgpy.packet.subpackets.types',
'pgpy.packet.subpackets.userattribute']
def get_module_objs(module):
# return a set of strings that represent the names of objects defined in that module
return { n for n, o in inspect.getmembers(module, lambda m: inspect.getmodule(m) is module) } | ({'FlagEnum',} if module is importlib.import_module('pgpy.types') else set()) # dirty workaround until six fixes metaclass stuff to support EnumMeta in Python >= 3.6
def get_module_all(module):
return set(getattr(module, '__all__', set()))
def test_pgpy_all():
import pgpy
# just check that everything in pgpy.__all__ is actually there
assert set(pgpy.__all__) <= { n for n, _ in inspect.getmembers(pgpy) }
@pytest.mark.parametrize('modname', modules)
def test_exports(modname):
module = importlib.import_module(modname)
assert get_module_all(module) == get_module_objs(module)