Fix a Unicode Issue with mkdocs new

Fixes #441
This commit is contained in:
Dougal Matthews
2015-04-09 13:25:17 +01:00
parent 74d3191e41
commit 92c66ee0ab
3 changed files with 37 additions and 5 deletions

View File

@@ -55,7 +55,7 @@ def main(cmd, args, options=None):
build(config, clean_site_dir=clean_site_dir)
gh_deploy(config)
elif cmd == 'new':
new(args, options)
new(args)
else:
print('MkDocs (version {0})'.format(__version__))
print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')

View File

@@ -1,10 +1,13 @@
# coding: utf-8
from __future__ import print_function
import os
from io import open
config_text = 'site_name: My Docs\n'
index_text = """# Welcome to MkDocs
from mkdocs import compat
config_text = compat.unicode('site_name: My Docs\n')
index_text = compat.unicode("""# Welcome to MkDocs
For full documentation visit [mkdocs.org](http://mkdocs.org).
@@ -21,10 +24,11 @@ For full documentation visit [mkdocs.org](http://mkdocs.org).
docs/
index.md # The documentation homepage.
... # Other markdown pages, images and other files.
"""
""")
def new(args, options):
def new(args):
if len(args) != 1:
print("Usage 'mkdocs new [directory-name]'")
return

28
mkdocs/tests/new_tests.py Normal file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env python
# coding: utf-8
import tempfile
import unittest
import os
from mkdocs import new
class NewTests(unittest.TestCase):
def test_new(self):
tempdir = tempfile.mkdtemp()
os.chdir(tempdir)
new.new(["myproject", ])
expected_paths = [
os.path.join(tempdir, "myproject"),
os.path.join(tempdir, "myproject", "mkdocs.yml"),
os.path.join(tempdir, "myproject", "docs"),
os.path.join(tempdir, "myproject", "docs", "index.md"),
]
for expected_path in expected_paths:
self.assertTrue(os.path.exists(expected_path))