Skip to content

Commit

Permalink
Merge 5d2aff9 into c5369fd
Browse files Browse the repository at this point in the history
  • Loading branch information
ayang committed Oct 30, 2013
2 parents c5369fd + 5d2aff9 commit 5e585ec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
26 changes: 19 additions & 7 deletions doc2dash/__main__.py
Expand Up @@ -69,12 +69,20 @@ def main():
'--icon', '-i',
help='add PNG icon to docset'
)
parser.add_argument(
'--index-page', '-I',
help='set index html file for docset'
)
args = parser.parse_args()

if args.icon and not args.icon.endswith('.png'):
print('Please supply a PNG icon.')
sys.exit(1)

if args.index_page and not os.path.exists(args.index_page):
print('Index file %s dose not exists.' % args.index_page)
sys.exit(1)

try:
level = determine_log_level(args)
logging.basicConfig(format='%(message)s', level=level)
Expand Down Expand Up @@ -175,14 +183,18 @@ def prepare_docset(args, dest):
)
db_conn.commit()

plist_cfg = {
'CFBundleIdentifier': args.name,
'CFBundleName': args.name,
'DocSetPlatformFamily': args.name.lower(),
'DashDocSetFamily': 'python',
'isDashDocset': True,
}
if args.index_page is not None:
plist_cfg['dashIndexFilePath'] = args.index_page

plistlib.writePlist(
{
'CFBundleIdentifier': args.name,
'CFBundleName': args.name,
'DocSetPlatformFamily': args.name.lower(),
'DashDocSetFamily': 'python',
'isDashDocset': True,
},
plist_cfg,
os.path.join(dest, 'Contents/Info.plist')
)

Expand Down
33 changes: 32 additions & 1 deletion tests/test_main.py
Expand Up @@ -39,6 +39,16 @@ def test_fails_with_unknown_icon(capsys, monkeypatch):
assert 'Please supply a PNG icon.' in out


def test_fails_with_not_exist_index_page(capsys, monkeypatch):
monkeypatch.setattr(sys, 'argv', ['doc2dash', 'foo', '-I', 'bar.html'])
with pytest.raises(SystemExit):
main.main()

out, err = capsys.readouterr()
assert err == ''
assert 'Index file bar.html dose not exists.' in out


def test_handles_unknown_doc_types(monkeypatch):
with tempfile.TemporaryDirectory() as td:
monkeypatch.chdir(td)
Expand Down Expand Up @@ -158,7 +168,8 @@ def test_prepare_docset(monkeypatch):
m_ct = MagicMock()
monkeypatch.setattr(shutil, 'copytree', m_ct)
os.mkdir('bar')
args.configure_mock(source='some/path/foo', name='foo')
args.configure_mock(
source='some/path/foo', name='foo', index_page=None)
main.prepare_docset(args, 'bar')
m_ct.assert_called_once_with(
'some/path/foo',
Expand All @@ -180,6 +191,26 @@ def test_prepare_docset(monkeypatch):
assert cur.fetchone()[0] == 0


def test_prepare_docset_index_page(monkeypatch):
with tempfile.TemporaryDirectory() as td:
monkeypatch.chdir(td)
m_ct = MagicMock()
monkeypatch.setattr(shutil, 'copytree', m_ct)
os.mkdir('bar')
args.configure_mock(
source='some/path/foo', name='foo', index_page='foo.html')
main.prepare_docset(args, 'bar')
p = plistlib.readPlist('bar/Contents/Info.plist')
assert p == {
'CFBundleIdentifier': 'foo',
'CFBundleName': 'foo',
'DocSetPlatformFamily': 'foo',
'DashDocSetFamily': 'python',
'isDashDocset': True,
'dashIndexFilePath': 'foo.html',
}


###########################################################################
# setup_logging tests #
###########################################################################
Expand Down

0 comments on commit 5e585ec

Please sign in to comment.