-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e0505b
commit 7d27e37
Showing
2 changed files
with
30 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import logging | ||
|
||
import iterpipes | ||
from changes import config | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def execute(command, dry_run=True): | ||
log.debug('executing %s', command) | ||
if not dry_run: | ||
try: | ||
return [result for result in iterpipes.linecmd(command)(None)] | ||
except iterpipes.CalledProcessError, e: | ||
log.debug('return code: %s, output: %s', e.returncode, e.output) | ||
return False | ||
def handle_dry_run(function, *args): | ||
if not config.arguments.get('--dry-run', True): | ||
return function(*args) | ||
else: | ||
log.debug('dry run of %s %s, skipping' % (function, args)) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import sh | ||
from unittest2 import TestCase | ||
|
||
from changes import config, shell | ||
|
||
|
||
class ShellTestCase(TestCase): | ||
|
||
def test_handle_dry_run(self): | ||
self.assertEquals( | ||
'', | ||
shell.handle_dry_run( | ||
sh.diff, | ||
('README.md', 'README.md') | ||
) | ||
) | ||
|
||
def test_handle_dry_run_true(self): | ||
config.arguments['--dry-run'] = True | ||
self.assertTrue( | ||
shell.handle_dry_run( | ||
sh.diff, | ||
('README.md', 'README.md') | ||
) | ||
) |