File: test_00_exports.py

package info (click to toggle)
python-pgpy 0.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,212 kB
  • sloc: python: 8,448; makefile: 155; sh: 10
file content (42 lines) | stat: -rw-r--r-- 1,367 bytes parent folder | download | duplicates (3)
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)