<commit_before>#!/usr/bin/env python


import unittest
import ghstats


class TestStats(unittest.TestCase):

    def test_cli(self):
        """
        Test command line arguments.
        """
        count = ghstats.main_cli(["kefir500/apk-icon-editor", "-l", "-d"])
        self.assertTrue(count > 0)

    def test_releases(self):
        """
        Test statistics for all releases.
        """
        stats = ghstats.download_stats("kefir500", "apk-icon-editor", None, False, ghstats.get_env_token(), False)
        self.assertTrue(isinstance(stats, list))
        count = ghstats.get_stats_downloads(stats, False)
        self.assertTrue(count > 0)

    def test_release(self):
        """
        Test statistics for the latest release.
        """
        stats = ghstats.download_stats("kefir500", "apk-icon-editor", None, True, ghstats.get_env_token(), False)
        self.assertTrue(isinstance(stats, dict))
        count = ghstats.get_stats_downloads(stats, False)
        self.assertTrue(count > 0)

    def test_invalid_repo(self):
        """
        Test nonexistent repository.
        """
        with self.assertRaises(ghstats.GithubRepoError):
            ghstats.download_stats("kefir500", "foobar", None, False, ghstats.get_env_token(), True)

    def test_invalid_token(self):
        """
        Test invalid GitHub personal access token.
        """
        with self.assertRaises(ghstats.GithubTokenError):
            ghstats.download_stats("kefir500", "foobar", None, False, "FOOBAR", True)


if __name__ == "__main__":
    unittest.main()<commit_msg>Add unit test for sys.exit() functions<commit_after>#!/usr/bin/env python


import unittest
import ghstats


class TestStats(unittest.TestCase):

    def test_cli(self):
        """
        Test command line arguments.
        """
        count = ghstats.main_cli(["kefir500/apk-icon-editor", "-l", "-d"])
        self.assertTrue(count > 0)

    def test_releases(self):
        """
        Test statistics for all releases.
        """
        stats = ghstats.download_stats("kefir500", "apk-icon-editor", None, False, ghstats.get_env_token(), False)
        self.assertTrue(isinstance(stats, list))
        count = ghstats.get_stats_downloads(stats, False)
        self.assertTrue(count > 0)

    def test_release(self):
        """
        Test statistics for the latest release.
        """
        stats = ghstats.download_stats("kefir500", "apk-icon-editor", None, True, ghstats.get_env_token(), False)
        self.assertTrue(isinstance(stats, dict))
        count = ghstats.get_stats_downloads(stats, False)
        self.assertTrue(count > 0)

    def test_invalid_repo(self):
        """
        Test nonexistent repository.
        """
        with self.assertRaises(ghstats.GithubRepoError):
            ghstats.download_stats("kefir500", "foobar", None, False, ghstats.get_env_token(), True)

    def test_invalid_token(self):
        """
        Test invalid GitHub personal access token.
        """
        with self.assertRaises(ghstats.GithubTokenError):
            ghstats.download_stats("kefir500", "foobar", None, False, "FOOBAR", True)

    def test_exits(self):
        """
        Test if functions halt the script.
        """
        with self.assertRaises(SystemExit) as cm:
            ghstats.print_help()
        self.assertEqual(cm.exception.code, 0)
        with self.assertRaises(SystemExit) as cm:
            ghstats.error("Test")
        self.assertNotEqual(cm.exception.code, 0)


if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.1232722143864598, 'fraction_numerical': 0.010719322990126939, 'mean_word_length': 2.614678899082569, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1472413', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1057, 'n_words': 218}