コード例 #1
0
    def test_create_report_with_valid_history(  # pylint: disable=too-many-arguments
            self, mock_add_report, mock_filename, mock_process,
            mock_resource_listdir, mock_write_file, mock_create_dir,
            mock_project):
        """ Tests if it does add a history record when it has history file name."""
        mock_filename.return_value = 'history.json'
        mock_process.return_value = 'formatted report'
        mock_resource_listdir.return_value = []
        mock_project.return_value = MagicMock(metric_sources=MagicMock(
            return_value=[CompactHistory('')]))

        reporter = quality_report.Reporter('folder').create_report(
            'report_dir')

        mock_filename.assert_called_once()
        mock_add_report.assert_called_once_with(reporter)
        mock_write_file.assert_called()
        mock_create_dir.assert_called()
        self.assertTrue(reporter)
コード例 #2
0
    def test_create_report_with_empty_history(  # pylint: disable=too-many-arguments
            self, mock_name, mock_metrics, mock_process, mock_resource_listdir,
            mock_write_file, mock_create_dir, mock_project):
        """ Tests if it creates all report files and directories."""
        mock_name.return_value = 'QR Name'
        mock_metrics.return_value = MagicMock()
        mock_process.return_value = 'formatted report'
        mock_resource_listdir.return_value = []
        mock_create_dir.return_value = 'unimportant'
        mock_write_file.return_value = 'unimportant'
        mock_project.metric_sources.return_value = []

        reporter = quality_report.Reporter('folder').create_report(
            'report_dir', True)
        report_dir = pathlib.Path('report_dir').resolve()

        self.assertTrue(
            all(b in mock_create_dir.call_args_list for b in [
                call(report_dir),
                call(report_dir / 'json'),
                call(report_dir / 'img'),
                call(report_dir / 'dist'),
                call(report_dir / 'chart'),
            ]))
        mock_resource_listdir.assert_has_calls([
            call('hqlib.app', 'img'),
            call('hqlib.app', 'dist'),
            call('hqlib.app', 'html')
        ])
        mock_write_file.assert_has_calls([
            call('formatted report', report_dir / 'json' / 'metrics.json', 'w',
                 'utf-8'),
            call('[]\n', report_dir / 'json' / 'meta_history.json', 'w',
                 'utf-8'),
            call(ANY, report_dir / 'json' / 'meta_data.json', 'w', 'utf-8'),
            call('',
                 report_dir / 'json' / 'dates.txt',
                 encoding=None,
                 mode='w')
        ])
        self.assertEqual('QR Name', reporter.name())
コード例 #3
0
 def test_init(self, mock_project):
     """ Test if configuration project function is called """
     reporter = quality_report.Reporter('folder')
     mock_project.assert_called_once_with('folder')
     self.assertTrue(reporter)