Exemple #1
0
    def test_Config_del(self, mock_input):
        mock_input.side_effect = ['y', 'y', 'y', 'y', 'y']

        config = Config()
        config.restore()

        options = ['python', app_path,
                   'config',
                   '--suffix-del=py',
                   '--comment-del=#',
                   '--ignore-del=venv']
        sys.argv[1:] = options[2:]

        args = CodeCounterArgs()
        self.assertTrue(args.has_config_args())
        config.invoke(args.config())

        suffix = 'py'
        comment = '#'
        ignore = 'venv'

        self.assertFalse(suffix in config.suffix)
        self.assertFalse(comment in config.comment)
        self.assertFalse(ignore in config.ignore)

        config.restore()
Exemple #2
0
    def test_Config_reset2(self, mock_input):
        mock_input.side_effect = ['y', 'n', 'y', 'y', 'y']

        config = Config()
        config.restore()

        options = ['python', app_path,
                   'config',
                   '--suffix-reset=java,cpp,go,js,py',
                   '--comment-reset=//,#,/**',
                   '--ignore-reset=target,build,node_modules,__pycache__']
        sys.argv[1:] = options[2:]

        args = CodeCounterArgs()
        self.assertTrue(args.has_config_args())
        config.invoke(args.config())

        suffix = {'java', 'cpp', 'go', 'js', 'py'}
        comment = {'//', '#', '/**'}
        ignore = {'target', 'build', 'node_modules', '__pycache__'}

        self.assertEqual(config.suffix, self.default_suffix)
        self.assertEqual(config.comment, comment)
        self.assertEqual(config.ignore, ignore)

        config.restore()
Exemple #3
0
    def test_Config_add4(self, mock_input):
        mock_input.side_effect = ['y', 'y', 'y', 'n', 'y']

        config = Config()
        config.restore()

        options = ['python', app_path,
                   'config',
                   '--suffix-add=TEST_SUFFIX',
                   '--comment-add=TEST_COMMENT',
                   '--ignore-add=TEST_IGNORE']
        sys.argv[1:] = options[2:]

        args = CodeCounterArgs()
        self.assertTrue(args.has_config_args())
        config.invoke(args.config())

        suffix = 'TEST_SUFFIX'
        comment = 'TEST_COMMENT'
        ignore = 'TEST_IGNORE'

        self.assertTrue(suffix in config.suffix)
        self.assertTrue(comment in config.comment)
        self.assertTrue(ignore not in config.ignore)

        config.restore()
Exemple #4
0
    def test_Config_reset_duplicate(self, mock_input):
        mock_input.side_effect = ['y', 'y', 'y', 'y', 'y']

        config = Config()
        config.restore()

        options = ['python', app_path,
                   'config',
                   '--suffix-reset=py,py,py,py',
                   '--comment-reset=#,#,#',
                   '--ignore-reset=__pycache__,__pycache__']
        sys.argv[1:] = options[2:]

        args = CodeCounterArgs()
        self.assertTrue(args.has_config_args())
        config.invoke(args.config())

        suffix = {'py'}
        comment = {'#'}
        ignore = {'__pycache__'}

        self.assertEqual(len(config.suffix), 1)
        self.assertEqual(len(config.comment), 1)
        self.assertEqual(len(config.ignore), 1)

        self.assertEqual(config.suffix, suffix)
        self.assertEqual(config.comment, comment)
        self.assertEqual(config.ignore, ignore)

        config.restore()
Exemple #5
0
    def test_Config_restore(self, mock_input):
        mock_input.side_effect = ['y']

        options = ['python', app_path,
                   'config',
                   '--restore']
        sys.argv[1:] = options[2:]

        args = CodeCounterArgs()
        self.assertTrue(args.has_config_args())

        config = Config()
        config.invoke(args.config())

        self.assertEqual(config.suffix, self.default_suffix, "the suffix doesn't equal")
        self.assertEqual(config.comment, self.default_comment, "the comment doesn't equal")
        self.assertEqual(config.ignore, self.default_ignore, "the ignore doesn't equal")
Exemple #6
0
def main():
    args = args_parser()

    config = Config(args)

    if args.param == 'CONFIG':
        config.show()
        sys.exit(0)

    code_counter = CodeCounter(config)

    time_start = time.time()
    code_counter.count(args.param, args.verbose, args.use_list,
                       args.output_path)
    time_end = time.time()

    print('\n\tTotally cost {}s.'.format(time_end - time_start))

    if args.graph:
        code_counter.visualize()
Exemple #7
0
def main():
    args = CodeCounterArgs()

    config = Config()
    if args.has_config_args():
        config.invoke(args.config())
        return

    code_counter = CodeCounter(config)

    search_args = args.search()
    code_counter.setSearchArgs(search_args)

    time_start = time.time()
    code_counter.search()
    time_end = time.time()

    print('\n\tTotally cost {} s.'.format(time_end - time_start))

    if search_args.graph:
        code_counter.visualize()