Skip to content

Commit

Permalink
Clean up rules in Makefile.
Browse files Browse the repository at this point in the history
Add a couple of basic tests and the configuration needed to run them.
Refactor format_post() to create a function that is easier to test.
  • Loading branch information
dhellmann committed Feb 12, 2012
1 parent 644061b commit 593a406
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist
build
*.egg-info
.tox
17 changes: 1 addition & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ help:
sdist: html
python setup.py sdist

# Documentation
.PHONY: html
html:
python setup.py build_sphinx
Expand All @@ -26,23 +25,9 @@ docclean:
installwebsite: html
(cd build/sphinx/html && rsync --rsh=ssh --archive --delete --verbose . www.doughellmann.com:/var/www/doughellmann/DocumentRoot/docs/rst2blogger/)

# Register the new version on pypi
.PHONY: register
register:
echo "USE upload target"
exit 1
python setup.py register

.PHONY: upload
upload:
python setup.py sdist upload

# Testing
test:
tox

test-quick:
tox -e py27

develop:
python setup.py develop
python setup.py nosetests
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ History
1.0.1

- Include fix from btbytes that removes lingering call to BeautifulSoup.
- Add a couple of basic tests.

1.0

Expand Down
7 changes: 6 additions & 1 deletion rst2blogger/rst2post.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ def format_post(rst_file, initial_header_level=4):
"""Read the rst file and return a tuple containing the title and
an HTML string for the post.
"""
# Convert RST to HTML
with open(rst_file, 'r') as f:
body = f.read()
return format_post_from_string(body, initial_header_level)

def format_post_from_string(body, initial_header_level=4):
"""Returns a tuple containing the title and an HTML string for the
post body.
"""
try:
html = publish_string(
body,
Expand Down
23 changes: 23 additions & 0 deletions tests/test_rst2post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

from rst2blogger.rst2post import format_post_from_string

def test_find_title():
title, content = format_post_from_string("""
Title Goes Here
===============
this is the rest of the body
""")
assert title == 'Title Goes Here'
return

def test_find_body():
title, content = format_post_from_string("""
Title Goes Here
===============
this is the rest of the body
""")
assert 'this is the rest of the body' in content
return

12 changes: 12 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tox]
envlist = py27
#,py32

[testenv]
commands = nosetests tests
deps =
pyquery>=1.1.1
distribute
docutils>=0.8.1
gdata>=2.0.16
nose

0 comments on commit 593a406

Please sign in to comment.