Add test for non atomic writing

Pierre Gerold 11 years ago
parent 48dcf2d319
commit 7cfd9b407a

@ -46,7 +46,7 @@ class TestFileContentsManager(TestCase):
def symlink(self, contents_manager, src, dst):
"""Make a symlink to src from dst
src and dst are api_paths
"""
src_os_path = contents_manager._get_os_path(src)
@ -106,7 +106,7 @@ class TestFileContentsManager(TestCase):
self.assertNotEqual(cp_dir, cp_subdir)
self.assertEqual(cp_dir, os.path.join(root, cpm.checkpoint_dir, cp_name))
self.assertEqual(cp_subdir, os.path.join(root, subd, cpm.checkpoint_dir, cp_name))
@dec.skip_win32
def test_bad_symlink(self):
with TemporaryDirectory() as td:
@ -120,7 +120,7 @@ class TestFileContentsManager(TestCase):
self.symlink(cm, "target", '%s/%s' % (path, 'bad symlink'))
model = cm.get(path)
self.assertEqual(model['content'], [file_model])
@dec.skip_win32
def test_good_symlink(self):
with TemporaryDirectory() as td:
@ -140,19 +140,19 @@ class TestFileContentsManager(TestCase):
sorted(dir_model['content'], key=lambda x: x['name']),
[symlink_model, file_model],
)
def test_403(self):
if hasattr(os, 'getuid'):
if os.getuid() == 0:
raise SkipTest("Can't test permissions as root")
if sys.platform.startswith('win'):
raise SkipTest("Can't test permissions on Windows")
with TemporaryDirectory() as td:
cm = FileContentsManager(root_dir=td)
model = cm.new_untitled(type='file')
os_path = cm._get_os_path(model['path'])
os.chmod(os_path, 0o400)
try:
with cm.open(os_path, 'w') as f:
@ -188,7 +188,7 @@ class TestFileContentsManager(TestCase):
class TestContentsManager(TestCase):
def setUp(self):
self._temp_dir = TemporaryDirectory()
self.td = self._temp_dir.name
@ -198,10 +198,10 @@ class TestContentsManager(TestCase):
def tearDown(self):
self._temp_dir.cleanup()
def make_dir(self, api_path):
"""make a subdirectory at api_path
override in subclasses if contents are not on the filesystem.
"""
_make_dir(self.contents_manager, api_path)
@ -247,7 +247,7 @@ class TestContentsManager(TestCase):
self.assertEqual(model['name'], 'Untitled Folder')
self.assertEqual(model['path'], 'Untitled Folder')
sub_dir = model['path']
model = cm.new_untitled(path=sub_dir)
assert isinstance(model, dict)
self.assertIn('name', model)
@ -528,3 +528,34 @@ class TestContentsManager(TestCase):
cm.mark_trusted_cells(nb, path)
cm.check_and_sign(nb, path)
assert cm.notary.check_signature(nb)
class TestContentsManagerNoAtomic(TestCase):
def setUp(self):
self._temp_dir = TemporaryDirectory()
self.td = self._temp_dir.name
self.contents_manager = FileContentsManager(
root_dir = self.td,
)
self.contents_manager.use_atomic_writing = False
def tearDown(self):
self._temp_dir.cleanup()
def new_notebook_no_atomic(self):
"""
"""
cm = self.contents_manager
model = cm.new_untitled(type="notebook")
name = model['name']
path = model['path']
full_model = cm.get(path)
nb = full_model['content']
nb['metadata']['counter'] = int(1e6 * time.time())
self.add_code_cell(nb)
cm.save(full_model, path)
return nb, name, path

Loading…
Cancel
Save