Skip to content

Commit

Permalink
Merge pull request #26 from seomoz/travis
Browse files Browse the repository at this point in the history
Travis
  • Loading branch information
dlecocq committed Jan 23, 2014
2 parents 2f25a08 + fc2a60f commit b2777f4
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 28 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: python
python:
- "2.7"
- "3.2"
- "3.3"
before_install:
- "pip install -r requirements.txt"
install: make install
script: make test
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
build:
python setup.py build

clean:
# Remove the build
sudo rm -rf build dist
Expand All @@ -6,14 +9,10 @@ clean:
# And lastly, .coverage files
find . -name .coverage | xargs rm

nose:
.PHONY: test
test:
rm -rf .coverage
nosetests --exe --cover-package=shovel --with-coverage --cover-branches -v

test: nose

build:
python setup.py build

install: build
python setup.py install
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Shovel
======
[![Build Status](https://travis-ci.org/seomoz/shovel.png?branch=travis)](https://travis-ci.org/seomoz/shovel)

Shovel is like Rake for python. Turn python functions into tasks simply, and
access and invoke them from the command line. 'Nuff said. __New__ Shovel also
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path.py==5.0
nose==1.3.0
8 changes: 5 additions & 3 deletions shovel/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'''Argument -parsing and -evaluating tools'''

from __future__ import print_function

import inspect
from collections import namedtuple

Expand All @@ -45,7 +47,7 @@ def __init__(self, spec):
# we'll add the required positional arguments and get a list of all
# args and whether or not they have defaults
self._defaults = list(reversed(
zip(reversed(spec.args), reversed(spec.defaults or []))
list(zip(reversed(spec.args or []), reversed(spec.defaults or [])))
))
# Now, take all the args that don't have a default
self._args = spec.args[:(len(spec.args) - len(self._defaults))]
Expand Down Expand Up @@ -85,13 +87,13 @@ def get(self, *args, **kwargs):
required = [arg for arg in self._args if arg not in kwargs]
if len(args) < len(required):
raise TypeError('Missing arguments %s' % required[len(args):])
required = zip(required, args)
required = list(zip(required, args))
args = args[len(required):]

# Now we'll look through our defaults, if there are any
defaulted = [(name, default) for name, default in self._defaults
if name not in kwargs]
overridden = zip([d[0] for d in defaulted], args)
overridden = list(zip([d[0] for d in defaulted], args))
args = args[len(overridden):]
defaulted = defaulted[len(overridden):]

Expand Down
2 changes: 1 addition & 1 deletion shovel/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def heirarchical_helper(shovel, prefix, level=0):
'''Return a list of tuples of (fullname, docstring, level) for all the
tasks in the provided shovel'''
result = []
for key, value in shovel.map.items():
for key, value in sorted(shovel.map.items()):
if prefix:
key = prefix + '.' + key
if isinstance(value, Shovel):
Expand Down
9 changes: 6 additions & 3 deletions shovel/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def keys(self):
keys.extend([key + '.' + k for k in value.keys()])
else:
keys.append(key)
return keys
return sorted(keys)

def items(self):
'''Return a list of tuples of all the keys and tasks'''
Expand All @@ -133,7 +133,7 @@ def items(self):
pairs.extend([(key + '.' + k, v) for k, v in value.items()])
else:
pairs.append((key, value))
return pairs
return sorted(pairs)

def tasks(self, name):
'''Get all the tasks that match a name'''
Expand Down Expand Up @@ -244,7 +244,10 @@ def capture(self, *args, **kwargs):
return value. Also, the traceback from the exception if there was
one'''
import traceback
from StringIO import StringIO
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
stdout, stderr = sys.stdout, sys.stderr
sys.stdout = out = StringIO()
sys.stderr = err = StringIO()
Expand Down
9 changes: 9 additions & 0 deletions test/examples/basic/shovel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'''Shovel tasks strictly for tests'''

from shovel import task


@task
def widget(arg, whiz, bang):
'''This is a dummy task'''
return arg + whiz + bang
7 changes: 6 additions & 1 deletion test/examples/capture/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'''Dummy shovel tasks for testing'''

from __future__ import print_function

from shovel import task


@task
def foo(a, b, c):
'''Dummy function'''
print 'foo'
print('foo')
return a + b + c


Expand Down
11 changes: 11 additions & 0 deletions test/examples/run/basic/shovel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'''Dummy shovel tasks for testing'''

from __future__ import print_function

from shovel import task


@task
def bar():
'''Dummy function'''
print('Hello from bar!')
8 changes: 6 additions & 2 deletions test/examples/run/multiple/shovel/whiz.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'''Dummy shovel tasks for testing'''

from __future__ import print_function

from shovel import task


@task
def bar():
'''Dummy function'''
print 'Hello from bar!'
print('Hello from bar!')


@task
def foo():
'''Dummy function'''
print 'Hello from foo!'
print('Hello from foo!')
18 changes: 9 additions & 9 deletions test/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ def setUp(self):
def test_heirarchical_helper(self):
'''Gets all the help tuples we'd expect'''
expected = [
('two', None, 0),
('two.widget', 'long doc, ' * 7, 1),
('one', None, 0),
('one.widget', 'A dummy function', 1)]
('one.widget', 'A dummy function', 1),
('two', None, 0),
('two.widget', 'long doc, ' * 7, 1)]
self.assertEqual(help.heirarchical_helper(self.shovel, ''), expected)

def test_heirarchical_help(self):
'''Gets the help message we'd expect from heirarchical_help'''
actual = [line.strip() for line in
help.heirarchical_help(self.shovel, '').split('\n')]
expected = [
'two/',
'two.widget => long doc, long doc, long doc, long doc, long do...',
'one/',
'one.widget => A dummy function']
'one.widget => A dummy function',
'two/',
'two.widget => long doc, long doc, long doc, long doc, long do...']
self.assertEqual(actual, expected)

def test_shovel_help_basic(self):
'''Gets the help message we'd expect from shovel_help for all tasks'''
actual = [line.strip() for line in
help.shovel_help(self.shovel).split('\n')]
expected = [
'two/',
'two.widget => long doc, long doc, long doc, long doc, long do...',
'one/',
'one.widget => A dummy function']
'one.widget => A dummy function',
'two/',
'two.widget => long doc, long doc, long doc, long doc, long do...']
self.assertEqual(actual, expected)

def test_shovel_help_specific_tasks(self):
Expand Down
6 changes: 5 additions & 1 deletion test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from path import path
import shovel
import sys
from cStringIO import StringIO
try:
from cStringIO import StringIO
except ImportError: # pragma: no cover
# Python 3 support
from io import StringIO


@contextmanager
Expand Down
2 changes: 0 additions & 2 deletions test/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_override(self):
pth = 'test/examples/overrides/%s' % name
shovel.read(pth, pth)
self.assertNotEqual(shovel, None)
print 'Tasks: %s' % shovel.items()
self.assertNotEqual(shovel['foo.bar'].overrides, None)

def test_keys_items(self):
Expand Down Expand Up @@ -142,7 +141,6 @@ def test_shovel(self):
top-level'''
shovel = Shovel.load('test/examples/toplevel/one',
'test/examples/toplevel/one')
print 'Shovel items: %s' % shovel.items()
_, tasks = zip(*shovel.items())
# self.assertEqual(len(tasks), 4)
self.assertEqual(set([t.fullname for t in tasks]),
Expand Down

0 comments on commit b2777f4

Please sign in to comment.