File: test_api.py

package info (click to toggle)
python-geopandas 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,752 kB
  • sloc: python: 26,021; makefile: 147; sh: 25
file content (40 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download
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
import os
import subprocess
import sys


def test_no_additional_imports():
    # test that 'import geopandas' does not import any of the optional or
    # development dependencies
    blacklist = {
        "pytest",
        "py",
        "ipython",
        # fiona actually gets imported if installed (but error suppressed until used)
        # "fiona",
        # "matplotlib",  # matplotlib gets imported by pandas, see below
        "mapclassify",
        "sqlalchemy",
        "psycopg",
        "psycopg2",
        "geopy",
        "geoalchemy2",
        "matplotlib",
    }

    code = f"""
import sys
import geopandas
blacklist = {blacklist!r}

mods = blacklist & set(m.split('.')[0] for m in sys.modules)
if mods:
    sys.stderr.write('err: geopandas should not import: {{}}'.format(', '.join(mods)))
    sys.exit(len(mods))
"""
    # remove COV_CORE_SOURCE to avoid pytest-cov importing itself in the subprocess
    env = os.environ.copy()
    env.pop("COV_CORE_SOURCE", None)
    call = [sys.executable, "-c", code]
    returncode = subprocess.run(call, check=False, env=env).returncode
    assert returncode == 0