def test_process_and_validate_params_csv_success(self): # append_csv param added cli_params = list([ '--project_name=UTEST Project', '--output_format=csv', '--append_csv', self.repo_folder, self.output_folder ]) config = Configuration(cli_params) args = config.get_args() self.assertEqual( args.git_repo, self.repo_folder, "test_process_and_validate_params_csv_success result git_repo is different than expected" ) self.assertEqual( args.output_path, self.output_folder, "test_process_and_validate_params_csv_success result output_path is different than expected" ) self.assertEqual( args.project_name, 'UTEST Project', "test_process_and_validate_params_csv_success result project_name is different than expected" ) self.assertEqual( args.output_format, 'csv', "test_process_and_validate_params_csv_success result output is different than expected" ) # Check options override init configuration self.assertTrue(config.is_csv_output()) self.assertFalse(config.is_html_output()) # append_csv param True expected self.assertTrue(config.is_append_csv())
def test_process_and_validate_params_html_success(self): expected_project_name = "UTEST HTML Project" cli_params = list([ '--project_name=' + expected_project_name, self.repo_folder, self.output_folder ]) config = Configuration(cli_params) args = config.get_args() self.assertEqual( args.git_repo, self.repo_folder, "test_process_and_validate_params_csv_success result git_repo is different than expected" ) self.assertEqual( args.output_path, self.output_folder, "test_process_and_validate_params_csv_success result output_path is different than expected" ) self.assertEqual( args.project_name, expected_project_name, "test_process_and_validate_params_csv_success result project_name is different than expected" ) self.assertTrue(config.is_html_output()) self.assertFalse(config.is_csv_output()) self.assertFalse(config.is_append_csv())
def run(self, args_orig): try: config = Configuration(args_orig) args = config.get_args() except ConfigurationException as ce: warnings.warn("Configuration exception occurred:") warnings.warn(ce) sys.exit(1) # check gnuplot version needed to HTML reports if config.is_html_output() and not config.is_valid_gnuplot_version(): warnings.warn("Invalid gnuplot version. Required " "minimal version: %s. Current version: %s" % (Configuration.GNUPLOT_MINIMAL_VERSION, config.get_gnuplot_version())) sys.exit(1) output_path = args.output_path run_dir = config.get_run_dir() print('Output path: %s' % output_path) cachefile = os.path.join(output_path, 'gitstats.cache') data = GitDataCollector(config.get_args_dict()) data.load_cache(cachefile) # todo: Check loop result. It seems every loop rewrite the collected information in data object. # Is this loop really needed? # for git_repo in args.git_repo: print('Git path: %s' % args.git_repo) prevdir = os.getcwd() os.chdir(args.git_repo) print('Collecting data...') data.collect(args.git_repo) os.chdir(prevdir) print('Refining data...') # data.saveCache(cachefile) data.refine() os.chdir(run_dir) print('Generating report...') # fixme: pass GitStatistics object directly when obsolete GitDataCollector is removed if config.is_html_output(): print('Generating HTML report...') report = HTMLReportCreator(config, data.repo_statistics) report.create(data, output_path) if sys.stdin.isatty(): print('You may now run:') print('') print(' sensible-browser \'%s\'' % os.path.join(output_path, 'general.html').replace("'", "'\\''")) print('') elif config.is_csv_output(): print('Generating CSV report...') report = CSVReportCreator() report.create(data.repo_statistics, output_path, config.get_args_dict(), config.is_append_csv()) print('CSV report created here: %s' % output_path) self.get_times()
def main(): try: config = Configuration(sys.argv[1:]) args = config.get_args() except ConfigurationException as ce: warnings.warn("Configuration exception occurred:") warnings.warn(ce) sys.exit(1) # check gnuplot version needed to HTML reports if config.is_html_output() and not config.is_valid_gnuplot_version(): warnings.warn("Invalid gnuplot version. Required " "minimal version: %s. Current version: %s" % (Configuration.GNUPLOT_MINIMAL_VERSION, config.get_gnuplot_version())) sys.exit(1) print('Git path: %s' % args.git_repo) print('Collecting data...') repository_statistics = GitStatistics(args.git_repo) output_path = args.output_path print('Output path: %s' % output_path) os.chdir(config.get_run_dir()) if config.is_html_output(): print('Generating HTML report...') report = HTMLReportCreator(config, repository_statistics) report.create(output_path) if sys.stdin.isatty(): print('You may now run:') print('') print(' sensible-browser \'%s\'' % os.path.join(output_path, 'general.html').replace("'", "'\\''")) print('') elif config.is_csv_output(): print('Generating CSV report...') report = CSVReportCreator() report.create(repository_statistics, output_path, config.get_args_dict(), config.is_append_csv()) print('CSV report created here: %s' % output_path) print_exec_times()