Skip to content

Commit

Permalink
Tests: unit/modulegraph: Add regression tests.
Browse files Browse the repository at this point in the history
These tests check for "recursion too deep" caused by the `__init__` module
being an extension module.

See pyinstaller#5131, pyinstaller#4346.
  • Loading branch information
htgoebel committed Sep 10, 2020
1 parent 168c286 commit b01a7f9
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/unit/test_modulegraph_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import py_compile
import textwrap
import zipfile
from importlib.machinery import EXTENSION_SUFFIXES

import pytest

Expand Down Expand Up @@ -69,6 +70,70 @@ def test_package(tmpdir):
assert node.packagepath == [pysrc.dirname]


#-- Extension modules

def test_package_init_is_extension_1(tmpdir):
# Regression: Recursion to deep
"""package's __init__ module is an extension"""
(tmpdir / 'stuff').mkdir()
extsrc = tmpdir / 'stuff' / ('__init__' + EXTENSION_SUFFIXES[0])
extsrc .write_text('###', encoding="ascii")
node = _import_and_get_node(tmpdir, 'stuff')
assert node.__class__ is modulegraph.Package
assert node.packagepath == [extsrc.dirname]


def test_package_init_is_extension_2(tmpdir):
# Regression: Recursion to deep
"""package's __init__ module is an extension and there also is a
__init__.py"""
(tmpdir / 'stuff').mkdir()
pysrc = tmpdir / 'stuff' / '__init__.py'
pysrc .write_text('###', encoding="ascii")
extsrc = tmpdir / 'stuff' / ('__init__' + EXTENSION_SUFFIXES[0])
extsrc .write_text('###', encoding="ascii")
node = _import_and_get_node(tmpdir, 'stuff')
assert node.__class__ is modulegraph.Package
assert node.packagepath == [extsrc.dirname]
assert node.filename == str(extsrc)


def test_package_init_is_extension_3(tmpdir):
(tmpdir / 'stuff').mkdir()
def wf(*args):
f = tmpdir.join(*args)
f.write_text('###', encoding="ascii")
return f
pysrc = wf('stuff', '__init__.py')
extsrc = wf('stuff', '__init__' + EXTENSION_SUFFIXES[0])
pysrc = wf('stuff', 'other.py')
extsrc = wf('stuff', 'other' + EXTENSION_SUFFIXES[0])
node = _import_and_get_node(tmpdir, 'stuff.other')
assert node.__class__ is modulegraph.Extension
assert node.packagepath == None # not a package
assert node.filename == str(extsrc)


def test_package_init_is_extension_4(tmpdir):
((tmpdir / 'stuff').mkdir() / 'stuff').mkdir()
def wf(*args):
f = tmpdir.join(*args)
f.write_text('###', encoding="ascii")
return f
pysrc = wf('stuff', '__init__.py')
extsrc = wf('stuff', '__init__' + EXTENSION_SUFFIXES[0])
pysrc = wf('stuff', 'other.py')
extsrc = wf('stuff', 'other' + EXTENSION_SUFFIXES[0])
pysrc = wf('stuff', 'stuff', '__init__.py')
extsrc = wf('stuff', 'stuff', '__init__' + EXTENSION_SUFFIXES[0])
pysrc = wf('stuff', 'stuff', 'other.py')
extsrc = wf('stuff', 'stuff', 'other' + EXTENSION_SUFFIXES[0])
node = _import_and_get_node(tmpdir, 'stuff.stuff.other')
assert node.__class__ is modulegraph.Extension
assert node.packagepath == None # not a package
assert node.filename == str(extsrc)


#-- Basic tests - these seem to be missing in the original modulegraph
#-- test-suite

Expand Down

0 comments on commit b01a7f9

Please sign in to comment.