コード例 #1
0
    def test_load_from_deleted_file(self):
        """
        Deleting the config file could trigger a server reload.
        """

        config_file = tempfile.NamedTemporaryFile('w', delete=False)
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()
        finally:
            os.remove(config_file.name)
        with self.assertRaises(exceptions.ConfigurationError):
            base.load_config(config_file=config_file)
コード例 #2
0
    def test_load_default_file_prefer_yml(self):
        """
        test that `mkdocs.yml` will be loaded when '--config' is not set.
        """

        temp_dir = TemporaryDirectory()
        config_file1 = open(os.path.join(temp_dir.name, 'mkdocs.yml'), 'w')
        config_file2 = open(os.path.join(temp_dir.name, 'mkdocs.yaml'), 'w')
        os.mkdir(os.path.join(temp_dir.name, 'docs'))
        old_dir = os.getcwd()
        try:
            os.chdir(temp_dir.name)
            config_file1.write("site_name: MkDocs Test1\n")
            config_file1.flush()
            config_file1.close()
            config_file2.write("site_name: MkDocs Test2\n")
            config_file2.flush()
            config_file2.close()

            cfg = base.load_config(config_file=None)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test1')
        finally:
            os.chdir(old_dir)
            temp_dir.cleanup()
コード例 #3
0
    def test_load_from_file_with_relative_paths(self):
        """
        When explicitly setting a config file, paths should be relative to the
        config file, not the working directory.
        """

        config_dir = TemporaryDirectory()
        config_fname = os.path.join(config_dir.name, 'mkdocs.yml')
        docs_dir = os.path.join(config_dir.name, 'src')
        os.mkdir(docs_dir)

        config_file = open(config_fname, 'w')

        try:
            config_file.write("docs_dir: src\nsite_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
            self.assertEqual(cfg['docs_dir'], docs_dir)
            self.assertEqual(cfg.config_file_path, config_fname)
            self.assertIsInstance(cfg.config_file_path, str)
        finally:
            config_dir.cleanup()
コード例 #4
0
ファイル: base_tests.py プロジェクト: mkdocs/mkdocs
    def test_load_from_file_with_relative_paths(self):
        """
        When explicitly setting a config file, paths should be relative to the
        config file, not the working directory.
        """

        config_dir = TemporaryDirectory()
        config_fname = os.path.join(config_dir.name, 'mkdocs.yml')
        docs_dir = os.path.join(config_dir.name, 'src')
        os.mkdir(docs_dir)

        config_file = open(config_fname, 'w')

        try:
            config_file.write("docs_dir: src\nsite_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
            self.assertEqual(cfg['docs_dir'], docs_dir)
            self.assertEqual(cfg.config_file_path, config_fname)
            self.assertIsInstance(cfg.config_file_path, utils.text_type)
        finally:
            config_dir.cleanup()
コード例 #5
0
    def test_load_missing_required(self):
        """
        `site_name` is a required setting.
        """

        config_file = tempfile.NamedTemporaryFile('w', delete=False)
        try:
            config_file.write(
                "site_dir: output\nsite_uri: https://www.mkdocs.org\n")
            config_file.flush()
            config_file.close()

            with self.assertRaises(exceptions.Abort):
                base.load_config(config_file=config_file.name)
        finally:
            os.remove(config_file.name)
コード例 #6
0
def test_plugin():
    """Build our own documentation."""
    config = load_config()
    build(config)
    site_coverage_dir = Path(config["site_dir"]) / "coverage"
    for html_file in site_coverage_dir.iterdir():
        if html_file.suffix == ".html" and html_file.name != "index.html" and "tests" not in html_file.name:
            text = html_file.read_text()
            assert not re.search("covcovindex", text)
            assert not re.search('href="index.html"', text)
コード例 #7
0
    def test_load_from_closed_file(self):
        """
        The `serve` command with auto-reload may pass in a closed file descriptor.
        Ensure `load_config` reloads the closed file.
        """

        config_file = tempfile.NamedTemporaryFile('w', delete=False)
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
        finally:
            os.remove(config_file.name)
コード例 #8
0
    def test_load_from_file(self):
        """
        Users can explicitly set the config file using the '--config' option.
        Allows users to specify a config other than the default `mkdocs.yml`.
        """

        config_file = tempfile.NamedTemporaryFile('w', delete=False)
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file.name)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
        finally:
            os.remove(config_file.name)
コード例 #9
0
    def test_load_from_open_file(self):
        """
        `load_config` can accept an open file descriptor.
        """

        config_file = tempfile.NamedTemporaryFile('r+', delete=False)
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
            # load_config will always close the file
            self.assertTrue(config_file.closed)
        finally:
            os.remove(config_file.name)
コード例 #10
0
ファイル: base_tests.py プロジェクト: jimporter/mkdocs
    def test_load_from_file(self):
        """
        Users can explicitly set the config file using the '--config' option.
        Allows users to specify a config other than the default `mkdocs.yml`.
        """

        temp_dir = TemporaryDirectory()
        config_file = open(os.path.join(temp_dir.name, 'mkdocs.yml'), 'w')
        os.mkdir(os.path.join(temp_dir.name, 'docs'))
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file.name)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
        finally:
            os.remove(config_file.name)
コード例 #11
0
    def test_load_from_file(self):
        """
        Users can explicitly set the config file using the '--config' option.
        Allows users to specify a config other than the default `mkdocs.yml`.
        """

        temp_dir = TemporaryDirectory()
        config_file = open(os.path.join(temp_dir.name, 'mkdocs.yml'), 'w')
        os.mkdir(os.path.join(temp_dir.name, 'docs'))
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file.name)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
        finally:
            temp_dir.cleanup()
コード例 #12
0
ファイル: base_tests.py プロジェクト: jimporter/mkdocs
    def test_load_from_closed_file(self):
        """
        The `serve` command with auto-reload may pass in a closed file descriptor.
        Ensure `load_config` reloads the closed file.
        """

        temp_dir = TemporaryDirectory()
        config_file = open(os.path.join(temp_dir.name, 'mkdocs.yml'), 'w')
        os.mkdir(os.path.join(temp_dir.name, 'docs'))

        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
        finally:
            temp_dir.cleanup()
コード例 #13
0
    def test_load_from_closed_file(self):
        """
        The `serve` command with auto-reload may pass in a closed file descriptor.
        Ensure `load_config` reloads the closed file.
        """

        temp_dir = TemporaryDirectory()
        config_file = open(os.path.join(temp_dir.name, 'mkdocs.yml'), 'w')
        os.mkdir(os.path.join(temp_dir.name, 'docs'))

        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()
            config_file.close()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
        finally:
            temp_dir.cleanup()
コード例 #14
0
    def test_load_from_open_file(self):
        """
        `load_config` can accept an open file descriptor.
        """

        temp_dir = TemporaryDirectory()
        temp_path = temp_dir.name
        config_fname = os.path.join(temp_path, 'mkdocs.yml')

        config_file = open(config_fname, 'w+')
        os.mkdir(os.path.join(temp_path, 'docs'))
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
            # load_config will always close the file
            self.assertTrue(config_file.closed)
        finally:
            temp_dir.cleanup()
コード例 #15
0
ファイル: base_tests.py プロジェクト: jimporter/mkdocs
    def test_load_from_open_file(self):
        """
        `load_config` can accept an open file descriptor.
        """

        temp_dir = TemporaryDirectory()
        temp_path = temp_dir.name
        config_fname = os.path.join(temp_path, 'mkdocs.yml')

        config_file = open(config_fname, 'w+')
        os.mkdir(os.path.join(temp_path, 'docs'))
        try:
            config_file.write("site_name: MkDocs Test\n")
            config_file.flush()

            cfg = base.load_config(config_file=config_file)
            self.assertTrue(isinstance(cfg, base.Config))
            self.assertEqual(cfg['site_name'], 'MkDocs Test')
            # load_config will always close the file
            self.assertTrue(config_file.closed)
        finally:
            temp_dir.cleanup()
コード例 #16
0
    def test_load_from_missing_file(self):

        with self.assertRaises(exceptions.ConfigurationError):
            base.load_config(config_file='missing_file.yml')
コード例 #17
0
def test_plugin():
    """Build our own documentation."""
    build(load_config())
コード例 #18
0
def test_plugin(tmp_path):
    """Build our own documentation."""
    config = load_config()
    config["site_dir"] = tmp_path
    build(config)