本文整理汇总了Python中tests.new_notebook函数的典型用法代码示例。如果您正苦于以下问题:Python new_notebook函数的具体用法?Python new_notebook怎么用?Python new_notebook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了new_notebook函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupGtkInterface
def setupGtkInterface(test, klass=None, notebook=None):
'''Setup a new GtkInterface object for testing.
Will have test notebook, and default preferences.
@param test: the test that wants to use this ui object
@param klass: the klass to use, defaults to L{GtkInterface}, but
could be partially mocked subclass
'''
if klass is None:
klass = zim.gui.GtkInterface
# start filtering
filter = FilterNoSuchImageWarning()
filter.wrap_test(test)
# create interface object with new notebook
if notebook is None:
dirpath = test.get_tmp_name()
notebook = tests.new_notebook(fakedir=dirpath)
config = VirtualConfigManager()
ui = klass(config=config, notebook=notebook)
ui.mainwindow.init_uistate()
ui.open_page(Path('Test:foo:bar'))
return ui
示例2: runTest
def runTest(self):
'''Test proper linking of files in export'''
notebook = tests.new_notebook(fakedir='/source/dir/')
linker = StaticLinker('html', notebook)
linker.set_usebase(True) # normally set by html format module
linker.set_path(Path('foo:bar')) # normally set by exporter
linker.set_base(Dir('/source/dir/foo')) # normally set by exporter
self.assertEqual(linker.link_page('+dus'), './bar/dus.html')
self.assertEqual(linker.link_page('dus'), './dus.html')
self.assertEqual(linker.link_file('./dus.pdf'), './bar/dus.pdf')
self.assertEqual(linker.link_file('../dus.pdf'), './dus.pdf')
self.assertEqual(linker.link_file('../../dus.pdf'), '../dus.pdf')
## setup environment for interwiki link
if os.name == 'nt':
uri = 'file:///C:/foo'
else:
uri = 'file:///foo'
list = get_notebook_list()
list.append(NotebookInfo(uri, interwiki='foo'))
list.write()
##
href = interwiki_link('foo?Ideas:Task List')
self.assertIsNotNone(href)
self.assertEqual(linker.link('foo?Ideas:Task List'), uri + '/Ideas/Task_List.txt')
示例3: testTemplate
def testTemplate(self):
pluginklass = zim.plugins.get_plugin_class('calendar')
plugin = pluginklass()
notebook = tests.new_notebook()
template = get_template('wiki', 'Journal')
zim.datetimetz.FIRST_DAY_OF_WEEK = \
zim.datetimetz.MONDAY
plugin.preferences['namespace'] = Path('Calendar')
for path in (
'Calendar:2012',
'Calendar:2012:04:27',
'Calendar:2012:Week 17',
'Calendar:2012:04',
):
page = notebook.get_page(Path(path))
lines = template.process(notebook, page)
text = ''.join(lines)
#~ print text
self.assertTrue(not 'Created' in text) # No fall back
if 'Week' in path:
days = [l for l in lines if l.startswith('=== ')]
self.assertEqual(len(days), 7)
示例4: setupGtkInterface
def setupGtkInterface(test, klass=None):
'''Setup a new GtkInterface object for testing.
Will have test notebook, and default preferences.
@param test: the test that wants to use this ui object
@param klass: the klass to use, defaults to L{GtkInterface}, but
could be partially mocked subclass
'''
if klass is None:
klass = zim.gui.GtkInterface
# start filtering
filter = FilterNoSuchImageWarning()
filter.wrap_test(test)
# flush preferences
preferences = config_file('preferences.conf')
preferences.file.remove()
# create interface object with new notebook
dirpath = test.get_tmp_name()
notebook = tests.new_notebook(fakedir=dirpath)
path = Path('Test:foo:bar')
ui = klass(notebook=notebook, page=path)
# finalize plugins
for plugin in ui.plugins:
plugin.finalize_ui(ui)
ui.mainwindow.init_uistate()
return ui
示例5: runTest
def runTest(self):
'Test WWW interface'
config = VirtualConfigManager()
notebook = tests.new_notebook(fakedir=self.get_tmp_name())
notebook.index.update()
interface = WWWInterface(notebook, config=config, template=self.template)
validator = wsgiref.validate.validator(interface)
def call(command, path):
environ = {
'REQUEST_METHOD': command,
'SCRIPT_NAME': '',
'PATH_INFO': path,
'QUERY_STRING': '',
'SERVER_NAME': 'localhost',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': '1.0'
}
rfile = StringIO('')
wfile = StringIO()
handler = wsgiref.handlers.SimpleHandler(rfile, wfile, sys.stderr, environ)
if os.name == 'nt':
# HACK: on windows we have no file system encoding,
# but use unicode instead for os API.
# However wsgiref.validate fails on unicode param
# in environmnet.
for k, v in handler.os_environ.items():
if isinstance(v, unicode):
handler.os_environ[k] = v.encode('utf-8')
handler.run(validator)
#~ print '>>>>\n', wfile.getvalue(), '<<<<'
return wfile.getvalue()
# index
for path in ('/', '/Test/'):
response = call('HEAD', path)
self.assertResponseOK(response, expectbody=False)
response = call('GET', path)
#~ print '>'*80, '\n', response, '<'*80
self.assertResponseOK(response)
self.assertTrue('<li><a href="/Test/foo.html" title="foo" class="page">foo</a>' in response)
# page
response = call('GET', '/Test/foo.html')
self.assertResponseOK(response)
self.assertTrue('<h1>Foo</h1>' in response)
# page not found
with Filter404():
for path in self.file_not_found_paths:
response = call('GET', path)
header, body = self.assertResponseWellFormed(response)
self.assertEqual(header[0], 'HTTP/1.0 404 Not Found')
# favicon and other files
for path in self.file_found_paths:
response = call('GET', path)
header, body = self.assertResponseWellFormed(response)
self.assertEqual(header[0], 'HTTP/1.0 200 OK')
示例6: testTaskListTreeView
def testTaskListTreeView(self):
klass = PluginManager.get_plugin_class('tasklist')
plugin = klass()
notebook = tests.new_notebook()
plugin.extend(notebook.index)
index_ext = plugin.get_extension(IndexExtension)
self.assertIsNotNone(index_ext)
notebook.index.flush()
notebook.index.update()
from zim.plugins.tasklist import TaskListTreeView
opener = tests.MockObject()
treeview = TaskListTreeView(index_ext, opener)
menu = treeview.get_popup()
# Check these do not cause errors - how to verify state ?
tests.gtk_activate_menu_item(menu, _("Expand _All"))
tests.gtk_activate_menu_item(menu, _("_Collapse All"))
# Copy tasklist -> csv
from zim.gui.clipboard import Clipboard
tests.gtk_activate_menu_item(menu, 'gtk-copy')
text = Clipboard.get_text()
lines = text.splitlines()
self.assertTrue(len(lines) > 10)
self.assertTrue(len(lines[0].split(',')) > 3)
self.assertFalse(any('<span' in l for l in lines)) # make sure encoding is removed
示例7: testParseExec
def testParseExec(self):
"""Test parsing of custom tool Exec strings"""
# %f for source file as tmp file current page
# %d for attachment directory
# %s for real source file (if any)
# %n for notebook location (file or directory)
# %D for document root
# %t for selected text or word under cursor
# %T for selected text or word under cursor with wiki format
path = self.get_tmp_name()
notebook = tests.new_notebook(fakedir=path)
page = notebook.get_page(Path("Test:Foo"))
pageview = StubPageView()
args = (notebook, page, pageview)
tmpfile = TmpFile("tmp-page-source.txt").path
dir = notebook.dir
tool = CustomToolDict()
tool.update({"Name": "Test", "Description": "Test 1 2 3", "X-Zim-ExecTool": "foo"})
for cmd, wanted in (
("foo %f", ("foo", tmpfile)),
("foo %d", ("foo", dir.subdir("Test/Foo").path)),
("foo %s", ("foo", "")), # no file source
("foo %n", ("foo", dir.path)),
("foo %D", ("foo", "")), # no document root
("foo %t", ("foo", "FooBar")),
("foo %T", ("foo", "**FooBar**")),
):
# ~ print '>>>', cmd
tool["Desktop Entry"]["X-Zim-ExecTool"] = cmd
self.assertEqual(tool.parse_exec(args), wanted)
示例8: testTemplate
def testTemplate(self):
pluginklass = PluginManager.get_plugin_class('calendar')
plugin = pluginklass()
plugin.preferences['namespace'] = Path('Calendar')
notebook = tests.new_notebook()
plugin.extend(notebook)
dumper = get_dumper('wiki')
zim.datetimetz.FIRST_DAY_OF_WEEK = \
zim.datetimetz.MONDAY
for path in (
Path('Calendar:2012'),
Path('Calendar:2012:04:27'),
Path('Calendar:2012:Week 17'),
Path('Calendar:2012:04'),
):
tree = notebook.get_template(path)
lines = dumper.dump(tree)
#~ print lines
self.assertTrue(not 'Created' in ''.join(lines)) # No fall back
if 'Week' in path.name:
days = [l for l in lines if l.startswith('=== ')]
self.assertEqual(len(days), 7)
示例9: setUp
def setUp(self):
# Note that in this test our index is not the default index
# for the notebook. So any assumption from the notebook about
# the index will be wrong.
self.index = Index(dbfile=':memory:')
self.notebook = tests.new_notebook()
self.index.set_notebook(self.notebook)
示例10: setUp
def setUp(self):
self.ui = tests.MockObject()
self.ui.page = Path('Test')
self.notebook = tests.new_notebook()
self.ui.notebook = self.notebook
self.model = PageTreeStore(self.notebook.index)
self.treeview = PageTreeView(self.ui, self.model)
treepath = self.treeview.set_current_page(Path('Test'))
self.treeview.select_treepath(treepath)
示例11: testDefaulPlugins
def testDefaulPlugins(self):
'''Test loading default plugins'''
# Note that we use parent interface class here, so plugins
# will not really attach - just testing loading and prereq
# checks are OK.
notebook = tests.new_notebook()
interface = zim.NotebookInterface(notebook)
interface.uistate = zim.config.ConfigDict()
interface.load_plugins()
self.assertTrue(len(interface.plugins) > 3)
示例12: setUp
def setUp(self):
path = self.get_tmp_name()
self.nb = tests.new_notebook(fakedir=path)
self.assertIsNone(self.nb.profile)
with FilterFailedToLoadPlugin():
self.ui = NotebookInterface(self.nb)
configfile = self.ui.preferences.file
configfile.file.remove() # just in case
示例13: testExport
def testExport(self):
"""test the export of a wiki page to latex"""
with LatexLoggingFilter():
format = get_format("LaTeX")
testpage = tests.WikiTestData.get("Test:wiki")
tree = get_format("wiki").Parser().parse(testpage)
output = format.Dumper(linker=StubLinker()).dump(tree)
# ~ print '>>>\n' + ''.join(output) + '<<<'
self.assertTrue("\chapter{Foo Bar}\n" in output)
# Test template_options.document_type
input = r"""
[% options.document_type = 'book' -%]
\title{[% page.basename %]}
\begin{document}
\maketitle
\tableofcontents
[% page.body %]
\end{document}
"""
wanted = r"""
\title{FooBar}
\begin{document}
\maketitle
\tableofcontents
\textbf{foo bar !}
\chapter{Heading 2}
duss
\end{document}
"""
notebook = tests.new_notebook()
page = notebook.get_page(Path("FooBar"))
page.parse(
"wiki",
"""\
====== Page Heading ======
**foo bar !**
===== Heading 2 =====
duss
""",
)
template = Template(input, "latex", linker=StubLinker())
result = template.process(notebook, page)
self.assertEqual("".join(result), wanted)
示例14: runTest
def runTest(self):
input = u'''\
Version [% zim.version %]
<title>[% page.title %]</title>
Created [% page.properties['Creation-Date'] %]
<h1>[% notebook.name %]: [% page.name %]</h1>
<h2>[% page.heading %]</h2>
[% options.foo = "bar" %]
[%- page.body -%]
Option: [% options.foo %]
'''
wantedresult = u'''\
Version %s
<title>Page Heading</title>
Created TODAY
<h1>Unnamed Notebook: FooBar</h1>
<h2>Page Heading</h2>
<p>
<b>foo bar !</b>
</p>
Option: bar
''' % zim.__version__
notebook = tests.new_notebook()
page = notebook.get_page(Path('FooBar'))
page.parse('wiki', '''\
====== Page Heading ======
**foo bar !**
''')
page.properties['Creation-Date'] = 'TODAY'
self.assertTrue(len(page.dump('html', linker=StubLinker())) > 0)
template = Template(input, 'html', linker=StubLinker())
result = template.process(notebook, page)
self.assertEqual(''.join(result), wantedresult)
self.assertEqual(template.template_options['foo'], 'bar')
# Check new page template
notebook = tests.new_notebook()
page = notebook.get_page(Path('Some New None existing page'))
template = notebook.get_template(page)
tree = template.process_to_parsetree(notebook, page) # No linker !
head = tree.find('h').gettext()
self.assertEqual(head, u'Some New None existing page')
示例15: runTest
def runTest(self):
'Test PrintToBrowser plugin'
pluginklass = PluginManager.get_plugin_class('printtobrowser')
plugin = pluginklass()
notebook = tests.new_notebook()
page = notebook.get_page(Path('Test:foo'))
file = plugin.print_to_file(notebook, page)
self.assertTrue(file.exists())
content = file.read()
self.assertTrue('<h1>Foo</h1>' in content)