From 2ba414f1213886e8412029855f623ef148f90603 Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Sun, 25 Apr 2021 23:05:16 -0700 Subject: [PATCH] Better test error logging --- tests/test_cli.py | 77 +++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 2a19709..abe75ce 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -16,17 +16,17 @@ class TestCreation(unittest.TestCase): with runner.isolated_filesystem(): 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.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: fp.write(err_str) 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.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: self.assertNotEqual(fp.read(), err_str, 'file was not overwritten') @@ -38,9 +38,9 @@ class TestCreation(unittest.TestCase): with runner.isolated_filesystem(): 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.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): """Test if an error is thrown when the file does not exist""" @@ -48,8 +48,8 @@ class TestCreation(unittest.TestCase): with runner.isolated_filesystem(): result = runner.invoke(cli, ['show']) - self.assertEqual(result.exit_code, 1) - self.assertIn('does not exist', result.stdout) + self.assertNotEqual(result.exit_code, 0, result.output) + self.assertIn('does not exist', result.output) class TestTagging(unittest.TestCase): @@ -66,18 +66,18 @@ class TestTagging(unittest.TestCase): in_log.write() 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']) - self.assertEqual(result.exit_code, 0) + self.assertEqual(result.exit_code, 0, result.output) out_log = yaclog.read(location) self.assertEqual(out_log.versions[0].tags, ['TAG1']) self.assertEqual(out_log.versions[1].tags, ['TAG2']) result = runner.invoke(cli, ['tag', 'tag3', '0.8.0']) - self.assertNotEqual(result.exit_code, 0) - self.assertIn('not found in changelog', result.stdout) + self.assertNotEqual(result.exit_code, 0, result.output) + self.assertIn('not found in changelog', result.output) def test_tag_deletion(self): runner = CliRunner() @@ -96,24 +96,24 @@ class TestTagging(unittest.TestCase): in_log.write() result = runner.invoke(cli, ['tag', '-d', 'tag2', '0.8.0']) - self.assertNotEqual(result.exit_code, 0) - self.assertIn('not found in changelog', result.stdout) + self.assertNotEqual(result.exit_code, 0, result.output) + self.assertIn('not found in changelog', result.output) result = runner.invoke(cli, ['tag', '-d', 'tag3', '0.9.0']) - self.assertNotEqual(result.exit_code, 0) - self.assertIn('not found in version', result.stdout) + self.assertNotEqual(result.exit_code, 0, result.output) + self.assertIn('not found in version', result.output) result = runner.invoke(cli, ['tag', '-d', 'tag1']) - self.assertNotIn('not found in version', result.stdout) - self.assertEqual(result.exit_code, 0) + self.assertNotIn('not found in version', result.output) + self.assertEqual(result.exit_code, 0, result.output) out_log = yaclog.read(location) self.assertEqual(out_log.versions[0].tags, []) self.assertEqual(out_log.versions[1].tags, ['TAG2']) result = runner.invoke(cli, ['tag', '-d', 'tag2', '0.9.0']) - self.assertNotIn('not found in version', result.stdout) - self.assertEqual(result.exit_code, 0) + self.assertNotIn('not found in version', result.output) + self.assertEqual(result.exit_code, 0, result.output) out_log = yaclog.read(location) self.assertEqual(out_log.versions[0].tags, []) @@ -128,32 +128,36 @@ class TestRelease(unittest.TestCase): with runner.isolated_filesystem(): runner.invoke(cli, ['init']) # create the changelog 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.assertTrue('Unreleased' in result.stdout) - self.assertTrue('1.0.0' in result.stdout) + self.assertIn('Unreleased', result.output) + self.assertIn('1.0.0', result.output) 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.assertTrue('Unreleased' in result.stdout) - self.assertTrue('1.0.1' in result.stdout) + self.assertIn('Unreleased', result.output) + self.assertIn('1.0.1', result.output) 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.assertTrue('Unreleased' in result.stdout) - self.assertTrue('1.1.0' in result.stdout) + self.assertIn('Unreleased', result.output) + self.assertIn('1.1.0', result.output) 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.assertTrue('Unreleased' in result.stdout) - self.assertTrue('2.0.0' in result.stdout) + self.assertIn('Unreleased', result.output) + self.assertIn('2.0.0', result.output) def test_commit(self): runner = CliRunner() @@ -165,11 +169,12 @@ class TestRelease(unittest.TestCase): runner.invoke(cli, ['init']) # create the changelog 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) - self.assertIn('Created tag', result.stdout) - self.assertIn(repo.head.commit.hexsha[0:7], result.stdout) + result = runner.invoke(cli, ['release', '--version', '1.0.0', '-c'], input='y\n') + self.assertEqual(result.exit_code, 0, result.output) + 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')