Exemplo n.º 1
0
    def test_doc_dir_in_site_dir(self):

        j = os.path.join

        test_configs = (
            {
                'docs_dir': j('site', 'docs'),
                'site_dir': 'site'
            },
            {
                'docs_dir': 'docs',
                'site_dir': '.'
            },
            {
                'docs_dir': '.',
                'site_dir': '.'
            },
            {
                'docs_dir': 'docs',
                'site_dir': ''
            },
            {
                'docs_dir': '',
                'site_dir': ''
            },
            {
                'docs_dir': 'docs',
                'site_dir': 'docs'
            },
        )

        conf = {'config_file_path': j(os.path.abspath('..'), 'mkdocutils.yml')}

        for test_config in test_configs:

            patch = conf.copy()
            patch.update(test_config)

            # Same as the default schema, but don't verify the docs_dir exists.
            c = config.Config(schema=(('docs_dir',
                                       config_options.Dir(default='docs')),
                                      ('site_dir',
                                       config_options.SiteDir(default='site')),
                                      ('config_file_path',
                                       config_options.Type(str))))
            c.load_dict(patch)

            errors, warnings = c.validate()

            self.assertEqual(len(errors), 1)
            self.assertEqual(warnings, [])
Exemplo n.º 2
0
    def test_dir_is_config_dir_fails(self):
        cfg = Config(
            [('dir', config_options.Dir())],
            config_file_path=os.path.join(os.path.abspath('.'), 'mkdocutils.yml'),
        )

        test_config = {
            'dir': '.'
        }

        cfg.load_dict(test_config)

        fails, warns = cfg.validate()

        self.assertEqual(len(fails), 1)
        self.assertEqual(len(warns), 0)
Exemplo n.º 3
0
    def test_dir_bad_encoding_fails(self):
        cfg = Config(
            [('dir', config_options.Dir())],
            config_file_path=os.path.join(os.path.abspath('.'), 'mkdocutils.yml'),
        )

        test_config = {
            'dir': 'юникод'.encode(encoding='ISO 8859-5')
        }

        cfg.load_dict(test_config)

        fails, warns = cfg.validate()

        self.assertEqual(len(fails), 1)
        self.assertEqual(len(warns), 0)
Exemplo n.º 4
0
    def test_dir_filesystemencoding(self):
        cfg = Config(
            [('dir', config_options.Dir())],
            config_file_path=os.path.join(os.path.abspath('.'), 'mkdocutils.yml'),
        )

        test_config = {
            'dir': 'Übersicht'.encode(encoding=sys.getfilesystemencoding())
        }

        cfg.load_dict(test_config)

        fails, warns = cfg.validate()

        # str does not include byte strings so validation fails
        self.assertEqual(len(fails), 1)
        self.assertEqual(len(warns), 0)
Exemplo n.º 5
0
    def test_dir_unicode(self):
        cfg = Config(
            [('dir', config_options.Dir())],
            config_file_path=os.path.join(os.path.abspath('.'), 'mkdocutils.yml'),
        )

        test_config = {
            'dir': 'юникод'
        }

        cfg.load_dict(test_config)

        fails, warns = cfg.validate()

        self.assertEqual(len(fails), 0)
        self.assertEqual(len(warns), 0)
        self.assertIsInstance(cfg['dir'], str)
Exemplo n.º 6
0
    def test_config_dir_prepended(self):
        base_path = os.path.abspath('.')
        cfg = Config(
            [('dir', config_options.Dir())],
            config_file_path=os.path.join(base_path, 'mkdocutils.yml'),
        )

        test_config = {
            'dir': 'foo'
        }

        cfg.load_dict(test_config)

        fails, warns = cfg.validate()

        self.assertEqual(len(fails), 0)
        self.assertEqual(len(warns), 0)
        self.assertIsInstance(cfg['dir'], str)
        self.assertEqual(cfg['dir'], os.path.join(base_path, 'foo'))
Exemplo n.º 7
0
    def validate_config(self, config):
        """ Given a config with values for site_dir and doc_dir, run site_dir post_validation. """
        site_dir = config_options.SiteDir()
        docs_dir = config_options.Dir()

        fname = os.path.join(os.path.abspath('..'), 'mkdocutils.yml')

        config['docs_dir'] = docs_dir.validate(config['docs_dir'])
        config['site_dir'] = site_dir.validate(config['site_dir'])

        schema = [
            ('site_dir', site_dir),
            ('docs_dir', docs_dir),
        ]
        cfg = Config(schema, fname)
        cfg.load_dict(config)
        failed, warned = cfg.validate()

        if failed:
            raise config_options.ValidationError(failed)

        return True
Exemplo n.º 8
0
    ('pages', config_options.Nav()),

    # The full URL to where the documentation will be hosted
    ('site_url', config_options.URL()),

    # A description for the documentation project that will be added to the
    # HTML meta tags.
    ('site_description', config_options.Type(str)),
    # The name of the author to add to the HTML meta tags
    ('site_author', config_options.Type(str)),

    # The MkDocs theme for the documentation.
    ('theme', config_options.Theme(default='mkdocs')),

    # The directory containing the documentation markdown.
    ('docs_dir', config_options.Dir(default='docs', exists=True)),

    # The directory where the site will be built to
    ('site_dir', config_options.SiteDir(default='site')),

    # A copyright notice to add to the footer of documentation.
    ('copyright', config_options.Type(str)),

    # set of values for Google analytics containing the account IO and domain,
    # this should look like, ['UA-27795084-5', 'mkdocs.org']
    ('google_analytics', config_options.Type(list, length=2)),

    # The address on which to serve the live reloading docs server.
    ('dev_addr', config_options.IpAddress(default='127.0.0.1:8000')),

    # If `True`, use `<page_name>/index.hmtl` style files with hyperlinks to
Exemplo n.º 9
0
 def test_incorrect_type_type_error(self):
     option = config_options.Dir()
     self.assertRaises(config_options.ValidationError,
                       option.validate, [])
Exemplo n.º 10
0
 def test_file(self):
     d = __file__
     option = config_options.Dir(exists=True)
     self.assertRaises(config_options.ValidationError,
                       option.validate, d)
Exemplo n.º 11
0
    def test_missing_dir_but_required(self):

        d = os.path.join("not", "a", "real", "path", "I", "hope")
        option = config_options.Dir(exists=True)
        self.assertRaises(config_options.ValidationError,
                          option.validate, d)
Exemplo n.º 12
0
    def test_missing_dir(self):

        d = os.path.join("not", "a", "real", "path", "I", "hope")
        option = config_options.Dir()
        value = option.validate(d)
        self.assertEqual(os.path.abspath(d), value)
Exemplo n.º 13
0
    def test_valid_dir(self):

        d = os.path.dirname(__file__)
        option = config_options.Dir(exists=True)
        value = option.validate(d)
        self.assertEqual(d, value)