From 23cbb297d922426a1c0b3040331e746b98466f07 Mon Sep 17 00:00:00 2001 From: JP White Date: Tue, 2 Mar 2021 22:04:56 -0500 Subject: [PATCH] More tests --- tests/test_changes.py | 97 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/test_changes.py diff --git a/tests/test_changes.py b/tests/test_changes.py new file mode 100644 index 0000000..784eaec --- /dev/null +++ b/tests/test_changes.py @@ -0,0 +1,97 @@ +import unittest +from gitinspector import changes + + +FAKE_FILE_NAME = 'Arbitrary.ext' +FAKE_COMMIT_STRING = "1614563270|2021-02-28|53d81bcd2612dbc47e73c71ee43baae83c1ec252|JP White|jpwhite3@gmail.com" + + +class TestAuthorInfo(unittest.TestCase): + + def test_AuthorInfo_attrs(self): + author = changes.AuthorInfo() + expected_email = None + expected_insertions = 0 + expected_deletions = 0 + expected_commits = 0 + self.assertEqual(expected_email, author.email) + self.assertEqual(expected_insertions, author.insertions) + self.assertEqual(expected_deletions, author.deletions) + self.assertEqual(expected_commits, author.commits) + + +class TestFileDiff(unittest.TestCase): + + @classmethod + def setUpClass(cls): + pass + + def setUp(self): + pass + + def test_FileDiff_init(self): + test_string = 'ArbitraryName|-++-+' + file_diff = changes.FileDiff(test_string) + expected_name = 'ArbitraryName' + self.assertEqual(expected_name, file_diff.name) + expected_insertions = 3 + self.assertEqual(expected_insertions, file_diff.insertions) + expected_deletions = 2 + self.assertEqual(expected_deletions, file_diff.deletions) + + def test_is_not_filediff_line(self): + actual = changes.FileDiff.is_filediff_line(FAKE_FILE_NAME) + self.assertFalse(actual) + + def test_is_filediff_line(self): + test_file_diff_string = "arbitrary|--- a/file.txt" + actual = changes.FileDiff.is_filediff_line(test_file_diff_string) + self.assertTrue(actual) + + def test_get_extension(self): + expected = 'ext' + actual = changes.FileDiff.get_extension(FAKE_FILE_NAME) + self.assertEqual(actual, expected) + + def test_get_extension_from_file_without_extension(self): + test_file_name = 'Arbitrary' + expected = '' + actual = changes.FileDiff.get_extension(test_file_name) + self.assertEqual(actual, expected) + + def test_get_filename(self): + expected = FAKE_FILE_NAME + actual = changes.FileDiff.get_filename(expected) + self.assertEqual(actual, expected) + + def test_is_not_valid_extension(self): + result = changes.FileDiff.is_valid_extension(FAKE_FILE_NAME) + self.assertFalse(result) + + def test_is_valid_extension(self): + test_file_name = 'Arbitrary.cpp' + result = changes.FileDiff.is_valid_extension(test_file_name) + self.assertTrue(result) + + +class TestCommitClass(unittest.TestCase): + + @classmethod + def setUpClass(cls): + pass + + def setUp(self): + pass + + def test_Commit_init(self): + commit = changes.Commit(FAKE_COMMIT_STRING) + expected_timestamp = '1614563270' + expected_date = '2021-02-28' + expected_sha = '53d81bcd2612dbc47e73c71ee43baae83c1ec252' + expected_author = 'JP White' + expected_email = 'jpwhite3@gmail.com' + self.assertEqual(expected_timestamp, commit.timestamp) + self.assertEqual(expected_date, commit.date) + self.assertEqual(expected_sha, commit.sha) + self.assertEqual(expected_author, commit.author) + self.assertEqual(expected_email, commit.email) \ No newline at end of file