Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from yzq89/master
Browse files Browse the repository at this point in the history
Let managers handle get_kernel_path()
  • Loading branch information
devstein authored Jan 22, 2020
2 parents 58bf3e2 + a2a15f7 commit 58d2d55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hybridcontents/hybridmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,9 @@ def rename(self, old_path, new_path):
self._validate_path(new_prefix, new_mgr_path)

return new_mgr.rename(old_mgr_path, new_mgr_path)

@outside_root_to_404
def get_kernel_path(self, path, model=None):
prefix, mgr, mgr_path = _resolve_path(path, self.managers)

return mgr.get_kernel_path(mgr_path, model)
18 changes: 18 additions & 0 deletions hybridcontents/tests/test_hybrid_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,24 @@ def test_save_invalid_path(self):
with assertRaisesHTTPError(self, INVALID_PATH_ERROR):
cm.new_untitled(path='A', ext='.yaml')

def test_kernel_path(self):
# We are using FileContentsManager for all roots in test, so kernel
# paths should be same as notebook paths
cm = self.contents_manager

for prefix, real_dir in iteritems(self.temp_dir_names):
# Notebook in main dir - kernel path is '' (relative to main dir)
model = cm.new_untitled(path=prefix, type='notebook')
path = model['path']
self.assertEqual(cm.get_kernel_path(path), '')
# Test notebook in sub-directory
sub_dir = 'foo'
mkdir(osjoin(real_dir, sub_dir))
prefixed_sub_dir = pjoin(prefix, sub_dir)
model = cm.new_untitled(path=prefixed_sub_dir, type='notebook')
path = model['path']
self.assertEqual(cm.get_kernel_path(path), sub_dir)

def tearDown(self):
for dir_ in itervalues(self.temp_dirs):
dir_.cleanup()
Expand Down

0 comments on commit 58d2d55

Please sign in to comment.