Пример #1
0
    def runTest(self):
        defaults = XDGConfigFileIter('foo.conf')
        files = list(defaults)

        self.assertTrue(len(files) > 0)
        self.assertIsInstance(adapt_from_oldfs(files[0]), File)
        self.assertEqual(files[0].basename, 'foo.conf')
Пример #2
0
    def testInitializedEnvironment(self):
        '''Test config environment with non-default basedir paths'''
        my_environ = {
            'XDG_DATA_HOME': '/foo/data/home',
            'XDG_DATA_DIRS': '/foo/data/dir1:/foo/data/dir2   ',
            'XDG_CONFIG_HOME': '/foo/config/home',
            'XDG_CONFIG_DIRS': '/foo/config/dir1:/foo/config/dir2',
            'XDG_CACHE_HOME': '/foo/cache',
        }
        if os.name == 'nt':
            my_environ['XDG_DATA_DIRS'] = '/foo/data/dir1;/foo/data/dir2'
            my_environ['XDG_CONFIG_DIRS'] = '/foo/config/dir1;/foo/config/dir2'

        with EnvironmentConfigContext(my_environ):
            for k, v in (('XDG_DATA_HOME', '/foo/data/home'),
                         ('XDG_CONFIG_HOME', '/foo/config/home'),
                         ('XDG_CACHE_HOME', '/foo/cache')):
                self.assertEqual(
                    adapt_from_oldfs(getattr(zim.config.basedirs, k)),
                    value_to_folder(v))

            for k, v in (
                ('XDG_DATA_DIRS', '/foo/data/dir1:/foo/data/dir2'),
                ('XDG_CONFIG_DIRS', '/foo/config/dir1:/foo/config/dir2'),
            ):
                self.assertEqual(
                    list(map(adapt_from_oldfs, getattr(zim.config.basedirs,
                                                       k))),
                    list(map(value_to_folder, v.split(':'))))
Пример #3
0
    def marshalled_path_lookup(*arg, **kwarg):
        value = function(*arg, **kwarg)
        if isinstance(value, ConfigFile):
            p = value.file
        else:
            p = value

        p = adapt_from_oldfs(p)
        if not p is None:
            assert isinstance(p, (File, Folder)), 'BUG: get %r' % p
            assert p.ischild(_cwd), "ERROR: \"%s\" not below \"%s\"" % (p,
                                                                        _cwd)
        return value
Пример #4
0
    def testAllValid(self):
        '''Test config environment is valid'''
        for var in (
                ZIM_DATA_DIR,  # should always be set when running as test
                XDG_DATA_HOME,
                XDG_CONFIG_HOME,
                XDG_CACHE_HOME):
            self.assertTrue(isinstance(adapt_from_oldfs(var), Folder))

        for var in (
                XDG_DATA_DIRS,
                XDG_CONFIG_DIRS,
        ):
            self.assertTrue(
                isinstance(var, list)
                and isinstance(adapt_from_oldfs(var[0]), Folder))

        self.assertEqual(adapt_from_oldfs(ZIM_DATA_DIR), tests.ZIM_DATA_FOLDER)
        self.assertTrue(ZIM_DATA_DIR.file('zim.png').exists())
        self.assertTrue(data_file('zim.png').exists())
        self.assertTrue(data_dir('templates').exists())
        self.assertEqual(list(data_dirs(('foo', 'bar'))),
                         [d.subdir(['foo', 'bar']) for d in data_dirs()])
Пример #5
0
    def runTest(self):
        '''Test config environment setup of test'''
        zim.config.log_basedirs()

        for k, v in (('XDG_DATA_HOME', os.path.join(tests.TMPDIR,
                                                    'data_home')),
                     ('XDG_CONFIG_HOME',
                      os.path.join(tests.TMPDIR, 'config_home')),
                     ('XDG_CACHE_HOME', os.path.join(tests.TMPDIR,
                                                     'cache_home'))):
            self.assertEqual(adapt_from_oldfs(getattr(zim.config, k)),
                             LocalFolder(v))

        for k, v in (
                #~ ('XDG_DATA_DIRS', os.path.join(tests.TMPDIR, 'data_dir')),
            ('XDG_CONFIG_DIRS', os.path.join(tests.TMPDIR, 'config_dir')), ):
            self.assertEqual(
                list(map(adapt_from_oldfs, getattr(zim.config, k))),
                list(map(LocalFolder, v.split(os.pathsep))))
Пример #6
0
    def spawn(self, args, callback=None):
        if callback:
            raise NotImplementedError(
                'os.startfile does not support a callback')

        for arg in args:
            arg = adapt_from_oldfs(arg)
            if isinstance(arg, (LocalFile, LocalFolder)):
                path = os.path.normpath(arg.path).replace(
                    '/', SEP)  # msys can use '/' instead of '\\'
            elif is_uri_re.match(arg) and not is_win32_path_re.match(arg):
                # URL or e.g. mailto: or outlook: URI
                path = str(arg)
            else:
                # must be file
                path = os.path.normpath(str(arg)).replace(
                    '/', SEP)  # msys can use '/' instead of '\\'

            logger.info('Opening with os.startfile: %s', path)
            if TEST_MODE:
                TEST_MODE_RUN_CB((self.__class__.__name__, path))
            else:
                os.startfile(path)
Пример #7
0
    def testDefaults(self):
        '''Test default basedir paths'''
        with EnvironmentConfigContext({
                'XDG_DATA_HOME': None,
                'XDG_DATA_DIRS': '   ',
                'XDG_CONFIG_HOME': None,
                'XDG_CONFIG_DIRS': '',
                'XDG_CACHE_HOME': None,
        }):
            for k, v in (('XDG_DATA_HOME', '~/.local/share'),
                         ('XDG_CONFIG_HOME', '~/.config'), ('XDG_CACHE_HOME',
                                                            '~/.cache')):
                self.assertEqual(
                    adapt_from_oldfs(getattr(zim.config.basedirs, k)),
                    LocalFolder(v))

            for k, v in (
                ('XDG_DATA_DIRS', '/usr/share:/usr/local/share'),
                ('XDG_CONFIG_DIRS', '/etc/xdg'),
            ):
                self.assertEqual(
                    list(map(adapt_from_oldfs, getattr(zim.config.basedirs,
                                                       k))),
                    list(map(LocalFolder, v.split(':'))))
Пример #8
0
 def setUp(self):
     data_dir = adapt_from_oldfs(XDG_DATA_DIRS[0])
     tests.TEST_DATA_FOLDER.file('png.xml').copyto(
         data_dir.file('mime/image/png.xml'))
Пример #9
0
	def testDialog(self):
		'''Test ExportDialog'''
		from zim.gui.exportdialog import ExportDialog, ExportDoneDialog

		dir = self.setUpFolder(mock=tests.MOCK_ALWAYS_REAL)
		notebook = self.setUpNotebook(content={'foo': 'test 123\n', 'bar': 'test 123\n'})

		window = Gtk.Window()
		window.notebook = notebook

		## Test export all pages
		dialog = ExportDialog(window, notebook, Path('foo'))
		dialog.set_page(0)

		page = dialog.get_page()
		page.form['selection'] = 'all'
		dialog.next_page()

		page = dialog.get_page()
		page.form['format'] = 'HTML'
		page.form['template'] = 'Print'
		dialog.next_page()

		page = dialog.get_page()
		page.form['folder'] = dir
		page.form['index'] = 'INDEX_PAGE'
		with tests.DialogContext(ExportDoneDialog):
			dialog.assert_response_ok()

		file = dir.file('foo.html')
		self.assertTrue(file.exists())
		text = file.read()
		self.assertTrue('<!-- Wiki content -->' in text, 'template used')

		#~ print dialog.uistate
		self.assertEqual(dialog.uistate, window.notebook.state['ExportDialog'])
		self.assertIsInstance(dialog.uistate['output_folder'], Dir)

		## Test export single page
		dialog = ExportDialog(window, notebook, Path('foo'))
		dialog.set_page(0)

		page = dialog.get_page()
		page.form['selection'] = 'page'
		page.form['page'] = 'foo'
		dialog.next_page()

		page = dialog.get_page()
		page.form['format'] = 'HTML'
		page.form['template'] = 'Print'
		dialog.next_page()

		page = dialog.get_page()
		page.form['file'] = dir.file('SINGLE_FILE_EXPORT.html').path
		with tests.DialogContext(ExportDoneDialog):
			dialog.assert_response_ok()

		file = dir.file('SINGLE_FILE_EXPORT.html')
		self.assertTrue(file.exists())
		text = file.read()
		self.assertTrue('<!-- Wiki content -->' in text, 'template used')

		#~ print dialog.uistate
		self.assertEqual(dialog.uistate, window.notebook.state['ExportDialog'])
		self.assertIsInstance(adapt_from_oldfs(dialog.uistate['output_file']), File)
		self.assertIsInstance(adapt_from_oldfs(dialog.uistate['output_folder']), Folder) # Keep this in state as well
Пример #10
0
 def runTest(self):
     '''Test config for user dirs'''
     dirs = user_dirs()
     self.assertEqual(adapt_from_oldfs(dirs['XDG_DOCUMENTS_DIR']),
                      LocalFolder('~/Documents'))