def test_install_twice(self): """Installing an extension twice should fail gracefully.""" # Initilize app. clean_dir(_tmppath) app = keepnote.KeepNote(pref_dir=_pref_dir) app.init() # Install extension twice. [ext] = app.install_extension(_extension_file) self.assertTrue(app.install_extension(_extension_file) == [])
def test_disabled_extensions(self): """Extension disabled in preferences should not be enabled.""" # Initilize app. clean_dir(_tmppath) app = keepnote.KeepNote(pref_dir=_pref_dir) app.init() # Disable extension. ext = next(ext for ext in app.get_enabled_extensions() if ext.key != 'keepnote') ext.enable(False) ext_key = ext.key # Reload app. app.save() app = keepnote.KeepNote(pref_dir=_pref_dir) app.init() # Extension should still be disabled. self.assertFalse(app.get_extension(ext_key).is_enabled())
def test_open(self): filename = "test/data/notebook-v6" app = keepnote.KeepNote("keepnote") start = time.time() book = app.get_notebook(filename) def walk(node): for child in node.get_children(): walk(child) walk(book) t = time.time() - start print("seconds: ", t) book.close()
def test_notebook_lookup_node(self): export_filename = "test/tmp/notebook_export" app = keepnote.KeepNote() app.init() ext = app.get_extension("export_html") print("loading notebook...") book = notebooklib.NoteBook() book.load("test/data/notebook-v3") print("clearing output...") if os.path.exists(export_filename): shutil.rmtree(export_filename) print("exporting...") ext.export_notebook(book, export_filename)
def test_extension_api(self): """Extension API""" # Initilize app. clean_dir(_tmppath) app = keepnote.KeepNote(pref_dir=_pref_dir) app.init() # Ensure extension install file can be detected as one. self.assertTrue(extension.is_extension_install_file(_extension_file)) # Install extension using API. [ext] = app.install_extension(_extension_file) self.assertTrue( os.path.exists(_pref_dir + '/extensions/test_extension/info.xml')) # Ensure extension is installed. self.assertTrue( app.get_extension('test_extension').key == 'test_extension') self.assertTrue('test_extension' in app.get_installed_extensions()) # Extension should be auto-imported. self.assertTrue( 'test_extension' in (ext.key for ext in app.get_imported_extensions())) # Extension should be auto-enabled. self.assertTrue( 'test_extension' in (ext.key for ext in app.get_enabled_extensions())) # Check basic extension information is available. self.assertTrue(app.get_extension_base_dir('test_extension')) self.assertTrue(app.get_extension_data_dir('test_extension')) # Disable extension. ext.enable(False) self.assertTrue( 'test_extension' not in (ext.key for ext in app.get_enabled_extensions())) # Uninstall extension using API. self.assertTrue(app.can_uninstall(ext)) app.uninstall_extension('test_extension') self.assertFalse( os.path.exists(_pref_dir + '/extensions/test_extension/info.xml'))
def test_notebook_lookup_node(self): nodeid = "0841d4cc-2605-4fbb-9b3a-db5d4aeed7a6" filename = "test/data/notebook-v3" path = os.path.join(filename, "stress tests") app = keepnote.KeepNote("keepnote") book = app.get_notebook(filename) print "opened '%s'" % book.get_title() print "\t".join(["%d. '%s'" % (i+1, x.get_title()) for i, x in enumerate(app.iter_notebooks())]) app.close_notebook(book) print "notebook closed" print "\t".join(["%d. '%s'" % (i+1, x.get_title()) for i, x in enumerate(app.iter_notebooks())]) self.assert_(len(list(app.iter_notebooks())) == 0)