better readme and colors

This commit is contained in:
Gabriel Falcao 2012-07-30 15:50:32 -04:00
parent 2576986812
commit 61e445e02a
3 changed files with 63 additions and 16 deletions

View File

@ -1,4 +1,5 @@
# Steady Mark
> version 0.1.2
[![Build Status](https://secure.travis-ci.org/gabrielfalcao/steadymark.png)](http://travis-ci.org/gabrielfalcao/steadymark)
# Turning your github readme files into python test suites since 2012
@ -8,28 +9,61 @@ markdown.
## How it works:
Write your documentation using github-flavored markdown, surround your
Write your documentation using [github-flavored markdown](http://github.github.com/github-flavored-markdown/), surround your
snippets with python code blocks and steadymark will automatically
find and run them, if there is a header preceeding your python snippet
it will be used as title for your test.
# Advantages:
* Add test coverage to your app/library while documenting it
* Never have old malfunctional examples on your project's main page in github
* It uses [misaka](http://misaka.61924.nl/) which is a python-binding of [sundown](https://github.com/tanoku/sundown), the markdown engine that github uses in itself
# Example
Given the following `README.md`:
## unicode.lower transforms string into lowercase
```python
assert u"FOOBAR".lower() == "foobar"
```
## python can add numbers
```python
assert (2 + 2) == 5, 'oops baby'
```
# Start using steady mark now!
This is the code for the example above, copy and paste in you python
project right now and start keeping your documentation up-to-date with
the code.
# My project name
`version 0.1`
## usage
## unicode.lower transforms string into lowercase
```python
from mylibrary import whatever
assert u"FOOBAR".lower() == "foobar"
```
whatever.awesome()
## python can add numbers
```python
assert (2 + 2) == 5, 'oops baby'
```
Just run with:
```console
```bash
$ steadymark README.md
```
# Steadymark tests itself :+1:
```python
from steadymark import version
assert version == '0.1.2'
```

View File

@ -25,7 +25,6 @@
# OTHER DEALINGS IN THE SOFTWARE.
import os
from steadymark import version
from setuptools import setup
@ -39,7 +38,7 @@ def get_packages():
return packages
setup(name='steadymark',
version=version,
version='0.1.2',
description=(u'Markdown-based test runner for python. '
'Good for github projects'),
author=u'Gabriel Falcao',

View File

@ -24,7 +24,8 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
version = '0.1.1'
version = '0.1.2'
import os
import sys
import traceback
@ -57,15 +58,25 @@ class READMETestRunner(BaseRenderer):
u'title': unicode(title),
})
def print_red(self, text):
print "\033[1;31m{0}\033[0m".format(text)
def print_green(self, text):
print "\033[1;32m{0}\033[0m".format(text)
def format_ms(self, ms):
return "\033[1;33m{0}ms\033[0m".format(ms)
def postprocess(self, full_document):
actual_tests = [t for t in self.tests if 'code' in t]
if actual_tests:
print "Running code snippets from {0}".format(self.filename)
print "Running code snippets from {0}\n".format(self.filename)
else:
print "No tests found in {0}".format(self.filename)
failed = False
for test in actual_tests:
sys.stdout.write("{0} ...".format(test['title']))
sys.stdout.write("{0} ".format(test['title']))
before = datetime.now()
failure = None
lines = test['code'].splitlines()
@ -80,15 +91,18 @@ class READMETestRunner(BaseRenderer):
shift = before - after
ms = shift.microseconds / 1000
if not failure:
print "OK ({0}ms)".format(ms)
self.print_green('\xe2\x9c\x93 {0}'.format(self.format_ms(ms)))
else:
print "Failed ({0}ms)".format(ms)
self.print_red('\xe2\x9c\x97 {0}'.format(self.format_ms(ms)))
failed = True
exc, name, tb = failure
tb = tb.tb_next
line = lines[tb.tb_lineno - 1]
print "Traceback (most recent call last):"
print "{0} {1}".format(traceback.format_tb(tb)[-1], line)
# print u' File README.md, line {0}'.format(tb.next)
self.print_red("Traceback (most recent call last):")
formatted_tb = traceback.format_tb(tb)[-1]
self.print_red("{0} {1}".format(formatted_tb, line))
sys.exit(int(failed))
def main():