Skip to content

Commit 74ae269

Browse files
authored
Preserve __package__ attribute from original module
Add tests as requested in #7
1 parent 383a668 commit 74ae269

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

test_apipkg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def test_initpkg_transfers_attrs(monkeypatch):
227227
mod.__version__ = 10
228228
mod.__file__ = "hello.py"
229229
mod.__loader__ = "loader"
230+
mod.__package__ = "package"
230231
mod.__doc__ = "this is the documentation"
231232
monkeypatch.setitem(sys.modules, 'hello', mod)
232233
apipkg.initpkg('hello', {})
@@ -235,6 +236,7 @@ def test_initpkg_transfers_attrs(monkeypatch):
235236
assert newmod.__file__ == py.path.local(mod.__file__)
236237
assert newmod.__version__ == mod.__version__
237238
assert newmod.__loader__ == mod.__loader__
239+
assert newmod.__package__ == mod.__package__
238240
assert newmod.__doc__ == mod.__doc__
239241

240242

@@ -261,12 +263,14 @@ def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
261263
mod = ModuleType('hello')
262264
mod.__file__ = "hello.py"
263265
assert not hasattr(mod, '__path__')
266+
assert not hasattr(mod, '__package__')
264267
monkeypatch.setitem(sys.modules, 'hello', mod)
265268
apipkg.initpkg('hello', {})
266269
newmod = sys.modules['hello']
267270
assert newmod != mod
268271
assert newmod.__file__ == py.path.local(mod.__file__)
269272
assert not hasattr(newmod, '__path__')
273+
assert not hasattr(newmod, '__package__')
270274

271275

272276
def test_initpkg_not_changing_jython_paths(monkeypatch):

0 commit comments

Comments
 (0)