<s> '''<STR_LIT>''' <EOL> import unittest <EOL> from contextlib import contextmanager <EOL> import logging <EOL> import os <EOL> from path import path <EOL> import shovel <EOL> import sys <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from io import StringIO <EOL> @ contextmanager <EOL> def capture ( stream = '<STR_LIT>' ) : <EOL> original = getattr ( sys , stream ) <EOL> setattr ( sys , stream , StringIO ( ) ) <EOL> yield ( getattr ( sys , stream ) ) <EOL> setattr ( sys , stream , original ) <EOL> @ contextmanager <EOL> def logs ( ) : <EOL> stream = StringIO ( ) <EOL> handler = logging . StreamHandler ( stream ) <EOL> shovel . logger . addHandler ( handler ) <EOL> yield ( stream ) <EOL> handler . flush ( ) <EOL> shovel . logger . removeHandler ( handler ) <EOL> class TestRun ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def stdout ( self , pth , * args , ** kwargs ) : <EOL> with path ( pth ) : <EOL> with capture ( ) as out : <EOL> shovel . run ( * args , ** kwargs ) <EOL> return [ line . strip ( ) for line in <EOL> out . getvalue ( ) . strip ( ) . split ( '<STR_LIT:\n>' ) ] <EOL> def stderr ( self , pth , * args , ** kwargs ) : <EOL> with path ( pth ) : <EOL> with capture ( '<STR_LIT>' ) as out : <EOL> shovel . run ( * args , ** kwargs ) <EOL> return [ line . strip ( ) for line in <EOL> out . getvalue ( ) . strip ( ) . split ( '<STR_LIT:\n>' ) ] <EOL> def logs ( self , pth , * args , ** kwargs ) : <EOL> with path ( pth ) : <EOL> with logs ( ) as out : <EOL> shovel . run ( * args , ** kwargs ) <EOL> return [ line . strip ( ) for line in <EOL> out . getvalue ( ) . strip ( ) . split ( '<STR_LIT:\n>' ) ] <EOL> def test_basic ( self ) : <EOL> '''<STR_LIT>''' <EOL> actual = self . stdout ( '<STR_LIT>' , '<STR_LIT:bar>' ) <EOL> expected = [ <EOL> '<STR_LIT>' ] <EOL> self . assertEqual ( actual , expected ) <EOL> def test_basic_help ( self ) : <EOL> '''<STR_LIT>''' <EOL> actual = self . stdout ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> expected = [ <EOL> '<STR_LIT>' ] <EOL> self . assertEqual ( actual , expected ) <EOL> def test_verbose ( self ) : <EOL> '''<STR_LIT>''' <EOL> actual = self . logs ( '<STR_LIT>' , '<STR_LIT:bar>' , '<STR_LIT>' ) <EOL> actual = [ line . replace ( os . getcwd ( ) , '<STR_LIT>' ) for line in actual ] <EOL> expected_path = path ( '<STR_LIT>' ) . normpath ( ) <EOL> expected = [ <EOL> '<STR_LIT>' + expected_path , <EOL> '<STR_LIT>' ] <EOL> self . assertEqual ( actual , expected ) <EOL> def test_task_missing ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( <EOL> SystemExit , self . stderr , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_too_many_tasks ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaisesRegexp ( <EOL> SystemExit , '<STR_LIT:2>' , self . stderr , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_dry_run ( self ) : <EOL> '''<STR_LIT>''' <EOL> actual = self . stdout ( <EOL> '<STR_LIT>' , '<STR_LIT:bar>' , '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT:bar>' ] <EOL> self . assertEqual ( actual , expected ) <EOL> def test_tasks ( self ) : <EOL> '''<STR_LIT>''' <EOL> actual = self . stdout ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' ] <EOL> self . assertEqual ( actual , expected ) <EOL> def test_tasks_none_found ( self ) : <EOL> '''<STR_LIT>''' <EOL> actual = self . stdout ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> expected = [ '<STR_LIT>' ] <EOL> self . assertEqual ( actual , expected ) </s>
