mirror of
https://github.com/drewcassidy/yaclog.git
synced 2024-09-01 14:58:58 +00:00
Consolidate output checking and fix git error
This commit is contained in:
parent
a443724d2b
commit
32c09d82bd
@ -7,6 +7,10 @@ from yaclog.cli.__main__ import cli
|
|||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
|
||||||
|
|
||||||
|
def check_result(runner, result, expected=0):
|
||||||
|
runner.assertEqual(result.exit_code, expected, f'output: {result.output}\ntraceback: {result.exc_info}')
|
||||||
|
|
||||||
|
|
||||||
class TestCreation(unittest.TestCase):
|
class TestCreation(unittest.TestCase):
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
"""Test creating and overwriting a changelog"""
|
"""Test creating and overwriting a changelog"""
|
||||||
@ -16,7 +20,7 @@ class TestCreation(unittest.TestCase):
|
|||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
result = runner.invoke(cli, ['init'])
|
result = runner.invoke(cli, ['init'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file')
|
self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file')
|
||||||
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
||||||
|
|
||||||
@ -24,7 +28,7 @@ class TestCreation(unittest.TestCase):
|
|||||||
fp.write(err_str)
|
fp.write(err_str)
|
||||||
|
|
||||||
result = runner.invoke(cli, ['init'], input='y\n')
|
result = runner.invoke(cli, ['init'], input='y\n')
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertTrue(os.path.exists(os.path.abspath(location)), 'file no longer exists after overwrite')
|
self.assertTrue(os.path.exists(os.path.abspath(location)), 'file no longer exists after overwrite')
|
||||||
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
||||||
|
|
||||||
@ -38,7 +42,7 @@ class TestCreation(unittest.TestCase):
|
|||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
result = runner.invoke(cli, ['--path', location, 'init'])
|
result = runner.invoke(cli, ['--path', location, 'init'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file')
|
self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file')
|
||||||
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
||||||
|
|
||||||
@ -48,7 +52,7 @@ class TestCreation(unittest.TestCase):
|
|||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
result = runner.invoke(cli, ['show'])
|
result = runner.invoke(cli, ['show'])
|
||||||
self.assertNotEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result, 1)
|
||||||
self.assertIn('does not exist', result.output)
|
self.assertIn('does not exist', result.output)
|
||||||
|
|
||||||
|
|
||||||
@ -66,17 +70,17 @@ class TestTagging(unittest.TestCase):
|
|||||||
in_log.write()
|
in_log.write()
|
||||||
|
|
||||||
result = runner.invoke(cli, ['tag', 'tag1'])
|
result = runner.invoke(cli, ['tag', 'tag1'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
|
|
||||||
result = runner.invoke(cli, ['tag', 'tag2', '0.9.0'])
|
result = runner.invoke(cli, ['tag', 'tag2', '0.9.0'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
|
|
||||||
out_log = yaclog.read(location)
|
out_log = yaclog.read(location)
|
||||||
self.assertEqual(out_log.versions[0].tags, ['TAG1'])
|
self.assertEqual(out_log.versions[0].tags, ['TAG1'])
|
||||||
self.assertEqual(out_log.versions[1].tags, ['TAG2'])
|
self.assertEqual(out_log.versions[1].tags, ['TAG2'])
|
||||||
|
|
||||||
result = runner.invoke(cli, ['tag', 'tag3', '0.8.0'])
|
result = runner.invoke(cli, ['tag', 'tag3', '0.8.0'])
|
||||||
self.assertNotEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result, 2)
|
||||||
self.assertIn('not found in changelog', result.output)
|
self.assertIn('not found in changelog', result.output)
|
||||||
|
|
||||||
def test_tag_deletion(self):
|
def test_tag_deletion(self):
|
||||||
@ -96,16 +100,16 @@ class TestTagging(unittest.TestCase):
|
|||||||
in_log.write()
|
in_log.write()
|
||||||
|
|
||||||
result = runner.invoke(cli, ['tag', '-d', 'tag2', '0.8.0'])
|
result = runner.invoke(cli, ['tag', '-d', 'tag2', '0.8.0'])
|
||||||
self.assertNotEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result, 2)
|
||||||
self.assertIn('not found in changelog', result.output)
|
self.assertIn('not found in changelog', result.output)
|
||||||
|
|
||||||
result = runner.invoke(cli, ['tag', '-d', 'tag3', '0.9.0'])
|
result = runner.invoke(cli, ['tag', '-d', 'tag3', '0.9.0'])
|
||||||
self.assertNotEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result, 2)
|
||||||
self.assertIn('not found in version', result.output)
|
self.assertIn('not found in version', result.output)
|
||||||
|
|
||||||
result = runner.invoke(cli, ['tag', '-d', 'tag1'])
|
result = runner.invoke(cli, ['tag', '-d', 'tag1'])
|
||||||
self.assertNotIn('not found in version', result.output)
|
self.assertNotIn('not found in version', result.output)
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
|
|
||||||
out_log = yaclog.read(location)
|
out_log = yaclog.read(location)
|
||||||
self.assertEqual(out_log.versions[0].tags, [])
|
self.assertEqual(out_log.versions[0].tags, [])
|
||||||
@ -113,7 +117,7 @@ class TestTagging(unittest.TestCase):
|
|||||||
|
|
||||||
result = runner.invoke(cli, ['tag', '-d', 'tag2', '0.9.0'])
|
result = runner.invoke(cli, ['tag', '-d', 'tag2', '0.9.0'])
|
||||||
self.assertNotIn('not found in version', result.output)
|
self.assertNotIn('not found in version', result.output)
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
|
|
||||||
out_log = yaclog.read(location)
|
out_log = yaclog.read(location)
|
||||||
self.assertEqual(out_log.versions[0].tags, [])
|
self.assertEqual(out_log.versions[0].tags, [])
|
||||||
@ -130,7 +134,7 @@ class TestRelease(unittest.TestCase):
|
|||||||
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
|
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
|
||||||
|
|
||||||
result = runner.invoke(cli, ['release', '--version', '1.0.0'])
|
result = runner.invoke(cli, ['release', '--version', '1.0.0'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.0')
|
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.0')
|
||||||
self.assertIn('Unreleased', result.output)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertIn('1.0.0', result.output)
|
self.assertIn('1.0.0', result.output)
|
||||||
@ -138,7 +142,7 @@ class TestRelease(unittest.TestCase):
|
|||||||
runner.invoke(cli, ['entry', '-b', 'entry number 2'])
|
runner.invoke(cli, ['entry', '-b', 'entry number 2'])
|
||||||
|
|
||||||
result = runner.invoke(cli, ['release', '-p'])
|
result = runner.invoke(cli, ['release', '-p'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.1')
|
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.1')
|
||||||
self.assertIn('Unreleased', result.output)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertIn('1.0.1', result.output)
|
self.assertIn('1.0.1', result.output)
|
||||||
@ -146,7 +150,7 @@ class TestRelease(unittest.TestCase):
|
|||||||
runner.invoke(cli, ['entry', '-b', 'entry number 3'])
|
runner.invoke(cli, ['entry', '-b', 'entry number 3'])
|
||||||
|
|
||||||
result = runner.invoke(cli, ['release', '-m'])
|
result = runner.invoke(cli, ['release', '-m'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '1.1.0')
|
self.assertEqual(yaclog.read(location).versions[0].name, '1.1.0')
|
||||||
self.assertIn('Unreleased', result.output)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertIn('1.1.0', result.output)
|
self.assertIn('1.1.0', result.output)
|
||||||
@ -154,7 +158,7 @@ class TestRelease(unittest.TestCase):
|
|||||||
runner.invoke(cli, ['entry', '-b', 'entry number 4'])
|
runner.invoke(cli, ['entry', '-b', 'entry number 4'])
|
||||||
|
|
||||||
result = runner.invoke(cli, ['release', '-M'])
|
result = runner.invoke(cli, ['release', '-M'])
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '2.0.0')
|
self.assertEqual(yaclog.read(location).versions[0].name, '2.0.0')
|
||||||
self.assertIn('Unreleased', result.output)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertIn('2.0.0', result.output)
|
self.assertIn('2.0.0', result.output)
|
||||||
@ -167,16 +171,21 @@ class TestRelease(unittest.TestCase):
|
|||||||
os.chdir('testing')
|
os.chdir('testing')
|
||||||
repo.index.commit('initial commit')
|
repo.index.commit('initial commit')
|
||||||
|
|
||||||
|
with repo.config_writer() as cw:
|
||||||
|
cw.set_value('user', 'email', 'unit-tester@example.com')
|
||||||
|
cw.set_value('user', 'name', 'unit-tester')
|
||||||
|
|
||||||
runner.invoke(cli, ['init']) # create the changelog
|
runner.invoke(cli, ['init']) # create the changelog
|
||||||
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
|
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
|
||||||
|
|
||||||
result = runner.invoke(cli, ['release', '--version', '1.0.0', '-c'], input='y\n')
|
result = runner.invoke(cli, ['release', '--version', '1.0.0', '-c'], input='y\n')
|
||||||
self.assertEqual(result.exit_code, 0, f'output: {result.output}\ntraceback: {result.exc_info}')
|
check_result(self, result)
|
||||||
self.assertIn('Created commit', result.output)
|
self.assertIn('Created commit', result.output)
|
||||||
self.assertIn('Created tag', result.output)
|
self.assertIn('Created tag', result.output)
|
||||||
self.assertIn(repo.head.commit.hexsha[0:7], result.output)
|
self.assertIn(repo.head.commit.hexsha[0:7], result.output)
|
||||||
self.assertEqual(repo.tags[0].name, '1.0.0')
|
self.assertEqual(repo.tags[0].name, '1.0.0')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user