Exemplo n.º 1
0
def get_tmp_dir(name):
    if 'REAL_TMP' in os.environ:  # Set in tests/__init__.py
        dir = LocalFolder(os.environ['REAL_TMP'])
    else:
        dir = LocalFolder(tempfile.gettempdir())
    #~ print("TMPDIR:", dir)

    dir = dir.folder('test_versioncontrol').folder(name)
    if dir.exists():
        dir.remove_children()
        dir.remove()
    assert not dir.exists()
    dir.touch()
    return dir
Exemplo n.º 2
0
 def setUp(self):
     folder = LocalFolder(XDG_DATA_HOME.subdir('zim/templates').path)
     assert 'tests/tmp' in folder.path.replace('\\', '/')
     if folder.exists():
         folder.remove_children()
     for name, content in (
         ('html/foo_test.html', 'Test 123\n'),
         ('html/bar_test.html', 'Test 123\n'),
     ):
         folder.file(name).write(content)
Exemplo n.º 3
0
	def setUp(self):
		folder = LocalFolder(XDG_DATA_HOME.subdir('zim/templates').path)
		assert 'tests/tmp' in folder.path.replace('\\', '/')
		if folder.exists():
			folder.remove_children()
		for name, content in (
			('html/foo_test.html', 'Test 123\n'),
			('html/bar_test.html', 'Test 123\n'),
		):
			folder.file(name).write(content)

		manager = ApplicationManager()
		entry = manager.create('text/plain', 'test', 'test')
		manager.set_default_application('text/plain', entry)
Exemplo n.º 4
0
	def export_iter(self, pages):
		basename = encode_filename(pages.name)
		folder = LocalFolder(get_tmpdir().subdir('mhtml_export_tmp_dir').path) # XXX
		if folder.exists():
			folder.remove_children()
		else:
			folder.touch()
		file = folder.file(basename + '.html')
		layout = SingleFileLayout(file, pages.prefix)
		exporter = SingleFileExporter(layout, self.template, 'html', document_root_url=self.document_root_url)

		for p in exporter.export_iter(pages):
			yield p

		encoder = MHTMLEncoder()
		linker = ExportLinker(pages.notebook, layout, output=file, usebase=True)
		self.file.write(encoder(layout, linker))
Exemplo n.º 5
0
	def testError(self):

		def creator_with_failure(*a):
			raise ThumbnailCreatorFailure

		def creator_with_error(*a):
			raise ValueError

		file = LocalFolder(tests.ZIM_DATADIR).file('zim.png')
		self.assertTrue(file.exists())
		self.assertTrue(file.isimage())

		for creator in creator_with_failure, creator_with_error:
			#~ print(">>", creator.__name__)
			queue = ThumbnailQueue(creator)
			queue.queue_thumbnail_request(file, 64)

			with tests.LoggingFilter('zim.plugins.attachmentbrowser', 'Exception'):
				queue.start()
				while not queue.queue_empty():
					r = queue.get_ready_thumbnail()
					self.assertIsNone(r[0], None)