Example #1
0
    def test_convert(self):
        with TemporaryDirectory() as tempdir:
            # Prepare test files
            with open(os.path.join(tempdir, "test.md"), 'w') as f:
                f.write("# Hello\n")
            with open(os.path.join(tempdir, "meta.md"), 'w') as f:
                f.write("Title: title\nTemplate: other\n\n# Hello\n")
            templates_path = os.path.join(tempdir, "_templates")
            os.mkdir(templates_path)
            with open(os.path.join(templates_path, "default.html"), 'w') as f:
                f.write("Default: {{ content }}")
            with open(os.path.join(templates_path, "other.html"), 'w') as f:
                f.write("Other {{ title }}: {{ content }}")

            # Without metadata
            mc = MarkdownConverter(tempdir, "test.md")
            mc.convert()
            with open(os.path.join(tempdir, "test.html")) as f:
                self.assertEqual(f.read(), "Default: <h1>Hello</h1>")

            # With metadata
            mc = MarkdownConverter(tempdir, "meta.md")
            mc.convert()
            with open(os.path.join(tempdir, "meta.html")) as f:
                self.assertEqual(f.read(), "Other title: <h1>Hello</h1>")
Example #2
0
    def test_empty_file(self):
        with TemporaryDirectory() as tempdir:
            # Prepare test files
            with open(os.path.join(tempdir, "test.md"), 'w') as f:
                f.write("")
            templates_path = os.path.join(tempdir, "_templates")
            os.mkdir(templates_path)
            with open(os.path.join(templates_path, "default.html"), 'w') as f:
                f.write("Default: {{ content }}")

            mc = MarkdownConverter(tempdir, "test.md")
            mc.convert()
            with open(os.path.join(tempdir, "test.html")) as f:
                self.assertEqual(f.read(), "Default: ")