-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
70 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import unittest | ||
import os | ||
import platform | ||
import shutil | ||
from tempfile import mkdtemp, mkstemp | ||
|
||
from coalib.results.Result import Result | ||
from bears.vcs.actions.AddNewlineAction import AddNewlineAction | ||
from coala_utils.ContextManagers import retrieve_stdout | ||
from coalib.misc.Shell import run_shell_command | ||
|
||
|
||
class AddNewlineActionTest(unittest.TestCase): | ||
|
||
@staticmethod | ||
def run_git_command(*args, stdin=None): | ||
return run_shell_command(' '.join(('git',) + args), stdin) | ||
|
||
def setUp(self): | ||
self.shortlog = 'file.py: Add something' | ||
self.body = ('Added something, wrote some things\n' | ||
'Wrote tests\n' | ||
'\n' | ||
'Fixes #issue') | ||
self.uut = AddNewlineAction(self.shortlog, self.body) | ||
self.result = Result('origin', 'message') | ||
|
||
self._old_cwd = os.getcwd() | ||
self.gitdir = mkdtemp() | ||
os.chdir(self.gitdir) | ||
self.gitfile = mkstemp(dir=self.gitdir) | ||
self.run_git_command('init') | ||
self.run_git_command('config', 'user.email [email protected]') | ||
self.run_git_command('config', 'user.name coala') | ||
msg = self.shortlog + '\n' + self.body | ||
self.run_git_command('add .') | ||
self.run_git_command('commit', | ||
'--file=-', | ||
stdin=msg) | ||
|
||
def tearDown(self): | ||
os.chdir(self._old_cwd) | ||
if platform.system() == 'Windows': | ||
onerror = self._windows_rmtree_remove_readonly | ||
else: | ||
onerror = None | ||
shutil.rmtree(self.gitdir, onerror=onerror) | ||
|
||
def test_is_applicable(self): | ||
applicable = self.uut.is_applicable(self.result, | ||
{}, | ||
{'filename': 'Diff'}) | ||
self.assertTrue(applicable) | ||
|
||
applicable = self.uut.is_applicable(self.result, | ||
{}, | ||
{'filename': 'Diff', | ||
'AddNewlineAction': True}) | ||
self.assertFalse(applicable) | ||
|
||
def test_apply(self): | ||
with retrieve_stdout() as stdout: | ||
file_diff_dict = self.uut.apply(self.result, {}, {}) | ||
self.assertEqual(file_diff_dict, {'AddNewlineAction': True}) | ||
self.assertEqual(stdout.getvalue(), '') | ||
|
||
new_message, _ = run_shell_command('git log -1 --pretty=%B') | ||
new_message = new_message.rstrip('\n') | ||
self.assertEqual(new_message, | ||
self.shortlog + '\n\n' + self.body) |
Empty file.