-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5957 from afshin/contents-manager
Allow jupyter_server-based contents managers in notebook
- Loading branch information
Showing
4 changed files
with
486 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pytest | ||
from traitlets import HasTraits, TraitError | ||
from traitlets.utils.importstring import import_item | ||
|
||
from notebook.traittypes import ( | ||
InstanceFromClasses, | ||
TypeFromClasses | ||
) | ||
from notebook.services.contents.largefilemanager import LargeFileManager | ||
|
||
|
||
class DummyClass: | ||
"""Dummy class for testing Instance""" | ||
|
||
|
||
class DummyInt(int): | ||
"""Dummy class for testing types.""" | ||
|
||
|
||
class Thing(HasTraits): | ||
|
||
a = InstanceFromClasses( | ||
default_value=2, | ||
klasses=[ | ||
int, | ||
str, | ||
DummyClass, | ||
] | ||
) | ||
|
||
b = TypeFromClasses( | ||
default_value=None, | ||
allow_none=True, | ||
klasses=[ | ||
DummyClass, | ||
int, | ||
'notebook.services.contents.manager.ContentsManager' | ||
] | ||
) | ||
|
||
|
||
class TestInstanceFromClasses: | ||
|
||
@pytest.mark.parametrize( | ||
'value', | ||
[1, 'test', DummyClass()] | ||
) | ||
def test_good_values(self, value): | ||
thing = Thing(a=value) | ||
assert thing.a == value | ||
|
||
@pytest.mark.parametrize( | ||
'value', | ||
[2.4, object()] | ||
) | ||
def test_bad_values(self, value): | ||
with pytest.raises(TraitError) as e: | ||
thing = Thing(a=value) | ||
|
||
|
||
class TestTypeFromClasses: | ||
|
||
@pytest.mark.parametrize( | ||
'value', | ||
[DummyClass, DummyInt, LargeFileManager, | ||
'notebook.services.contents.manager.ContentsManager'] | ||
) | ||
def test_good_values(self, value): | ||
thing = Thing(b=value) | ||
if isinstance(value, str): | ||
value = import_item(value) | ||
assert thing.b == value | ||
|
||
@pytest.mark.parametrize( | ||
'value', | ||
[float, object] | ||
) | ||
def test_bad_values(self, value): | ||
with pytest.raises(TraitError) as e: | ||
thing = Thing(b=value) |
Oops, something went wrong.