mirror of
https://github.com/drewcassidy/yaclog.git
synced 2024-09-01 14:58:58 +00:00
Better test error logging
This commit is contained in:
parent
140faccb69
commit
2ba414f121
@ -16,17 +16,17 @@ 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)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
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.stdout, "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")
|
||||||
|
|
||||||
with open(location, 'w') as fp:
|
with open(location, 'w') as fp:
|
||||||
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)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
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.stdout, "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")
|
||||||
|
|
||||||
with open(location, 'r') as fp:
|
with open(location, 'r') as fp:
|
||||||
self.assertNotEqual(fp.read(), err_str, 'file was not overwritten')
|
self.assertNotEqual(fp.read(), err_str, 'file was not overwritten')
|
||||||
@ -38,9 +38,9 @@ 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)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
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.stdout, "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")
|
||||||
|
|
||||||
def test_does_not_exist(self):
|
def test_does_not_exist(self):
|
||||||
"""Test if an error is thrown when the file does not exist"""
|
"""Test if an error is thrown when the file does not exist"""
|
||||||
@ -48,8 +48,8 @@ class TestCreation(unittest.TestCase):
|
|||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
result = runner.invoke(cli, ['show'])
|
result = runner.invoke(cli, ['show'])
|
||||||
self.assertEqual(result.exit_code, 1)
|
self.assertNotEqual(result.exit_code, 0, result.output)
|
||||||
self.assertIn('does not exist', result.stdout)
|
self.assertIn('does not exist', result.output)
|
||||||
|
|
||||||
|
|
||||||
class TestTagging(unittest.TestCase):
|
class TestTagging(unittest.TestCase):
|
||||||
@ -66,18 +66,18 @@ 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)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
|
|
||||||
result = runner.invoke(cli, ['tag', 'tag2', '0.9.0'])
|
result = runner.invoke(cli, ['tag', 'tag2', '0.9.0'])
|
||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
|
|
||||||
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)
|
self.assertNotEqual(result.exit_code, 0, result.output)
|
||||||
self.assertIn('not found in changelog', result.stdout)
|
self.assertIn('not found in changelog', result.output)
|
||||||
|
|
||||||
def test_tag_deletion(self):
|
def test_tag_deletion(self):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
@ -96,24 +96,24 @@ 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)
|
self.assertNotEqual(result.exit_code, 0, result.output)
|
||||||
self.assertIn('not found in changelog', result.stdout)
|
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)
|
self.assertNotEqual(result.exit_code, 0, result.output)
|
||||||
self.assertIn('not found in version', result.stdout)
|
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.stdout)
|
self.assertNotIn('not found in version', result.output)
|
||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
|
|
||||||
out_log = yaclog.read(location)
|
out_log = yaclog.read(location)
|
||||||
self.assertEqual(out_log.versions[0].tags, [])
|
self.assertEqual(out_log.versions[0].tags, [])
|
||||||
self.assertEqual(out_log.versions[1].tags, ['TAG2'])
|
self.assertEqual(out_log.versions[1].tags, ['TAG2'])
|
||||||
|
|
||||||
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.stdout)
|
self.assertNotIn('not found in version', result.output)
|
||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
|
|
||||||
out_log = yaclog.read(location)
|
out_log = yaclog.read(location)
|
||||||
self.assertEqual(out_log.versions[0].tags, [])
|
self.assertEqual(out_log.versions[0].tags, [])
|
||||||
@ -128,32 +128,36 @@ class TestRelease(unittest.TestCase):
|
|||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
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'])
|
|
||||||
|
|
||||||
|
result = runner.invoke(cli, ['release', '--version', '1.0.0'])
|
||||||
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.0')
|
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.0')
|
||||||
self.assertTrue('Unreleased' in result.stdout)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertTrue('1.0.0' in result.stdout)
|
self.assertIn('1.0.0', result.output)
|
||||||
|
|
||||||
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, result.output)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.1')
|
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.1')
|
||||||
self.assertTrue('Unreleased' in result.stdout)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertTrue('1.0.1' in result.stdout)
|
self.assertIn('1.0.1', result.output)
|
||||||
|
|
||||||
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, result.output)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '1.1.0')
|
self.assertEqual(yaclog.read(location).versions[0].name, '1.1.0')
|
||||||
self.assertTrue('Unreleased' in result.stdout)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertTrue('1.1.0' in result.stdout)
|
self.assertIn('1.1.0', result.output)
|
||||||
|
|
||||||
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, result.output)
|
||||||
self.assertEqual(yaclog.read(location).versions[0].name, '2.0.0')
|
self.assertEqual(yaclog.read(location).versions[0].name, '2.0.0')
|
||||||
self.assertTrue('Unreleased' in result.stdout)
|
self.assertIn('Unreleased', result.output)
|
||||||
self.assertTrue('2.0.0' in result.stdout)
|
self.assertIn('2.0.0', result.output)
|
||||||
|
|
||||||
def test_commit(self):
|
def test_commit(self):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
@ -165,11 +169,12 @@ class TestRelease(unittest.TestCase):
|
|||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
self.assertIn('Created commit', result.stdout)
|
result = runner.invoke(cli, ['release', '--version', '1.0.0', '-c'], input='y\n')
|
||||||
self.assertIn('Created tag', result.stdout)
|
self.assertEqual(result.exit_code, 0, result.output)
|
||||||
self.assertIn(repo.head.commit.hexsha[0:7], result.stdout)
|
self.assertIn('Created commit', result.output)
|
||||||
|
self.assertIn('Created tag', 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')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user