Ejemplo n.º 1
0
 def test_load_old(self, monkeypatch, tmpdir):
     monkeypatch.chdir(tmpdir)
     copy_file(
         os.path.join(COVERAGE_FILES_DIR,
                      'HealthCheckAnalyzeLargeInvestigations'),
         tmpdir.join('.coverage'))
     fix_file_path(tmpdir.join('.coverage'), PYTHON_FILE_PATH)
     # will raise 'coverage.misc.CoverageException' if the file will not be loaded
     get_coverage_obj(coverage_file=None, report_dir=None,
                      load_old=True).report()
Ejemplo n.º 2
0
    def test_combine(self, monkeypatch, tmpdir, mocker):
        cov_file_names = [
            'HealthCheckAnalyzeLargeInvestigations', 'VirusTotalV3'
        ]
        tmp_cov_file_names = []
        monkeypatch.chdir(tmpdir)
        for cov_file_name in cov_file_names:
            tmp_cov_file_name = tmpdir.join(cov_file_name)
            tmp_cov_file_names.append(tmp_cov_file_name)
            copy_file(os.path.join(COVERAGE_FILES_DIR, cov_file_name),
                      tmp_cov_file_name)
        mocker.patch(
            'demisto_sdk.commands.coverage_analyze.helpers.coverage_files',
            return_value=map(lambda x: x, tmp_cov_file_names))

        # will raise 'coverage.misc.CoverageException' if the file will not be loaded
        coverage_obj = get_coverage_obj(coverage_file=None,
                                        report_dir=None,
                                        combine_from_content_repo=True)
        with sqlite3.connect(coverage_obj.config.data_file) as sql_connection:
            cursor = sql_connection.cursor()
            data = list(cursor.execute('SELECT * FROM file').fetchall())
            cursor.close()
        assert len(data) == 2
        assert data[0] == (
            1, '/Users/username/dev/demisto/content/Packs/HealthCheck/Scripts/'
            'HealthCheckAnalyzeLargeInvestigations/HealthCheckAnalyzeLargeInvestigations.py'
        )
        assert data[1] == (
            2,
            '/Users/username/dev/demisto/content/Packs/VirusTotal/Integrations/VirusTotalV3/VirusTotalV3.py'
        )
 def test_files(self, tmpdir, monkeypatch):
     monkeypatch.chdir(tmpdir)
     coverage_path = os.path.join(COVERAGE_FILES_DIR,
                                  'HealthCheckAnalyzeLargeInvestigations')
     temp_coverage_path = tmpdir.join('.coverage')
     copy_file(coverage_path, temp_coverage_path)
     fix_file_path(temp_coverage_path, PYTHON_FILE_PATH)
     cov_report = CoverageReport(coverage_file=temp_coverage_path)
     cov_report._cov = get_coverage_obj(coverage_file=temp_coverage_path,
                                        report_dir=None,
                                        load_old=True)
     file_path, cover = list(cov_report.files.items())[0]
     assert os.path.abspath(file_path) == PYTHON_FILE_PATH
     assert isinstance(cover, float)
 def test_get_report_str(self, tmpdir, monkeypatch):
     monkeypatch.chdir(tmpdir)
     coverage_path = os.path.join(COVERAGE_FILES_DIR,
                                  'HealthCheckAnalyzeLargeInvestigations')
     temp_coverage_path = tmpdir.join('.coverage')
     copy_file(coverage_path, temp_coverage_path)
     fix_file_path(temp_coverage_path, PYTHON_FILE_PATH)
     cov_report = CoverageReport(coverage_file=temp_coverage_path)
     cov_report._cov = get_coverage_obj(coverage_file=temp_coverage_path,
                                        report_dir=None,
                                        load_old=True)
     report_str = cov_report.report_str
     assert report_str.split('\n')[2].split() == [
         PYTHON_FILE_PATH, '38', '10', '73.68%'
     ]
Ejemplo n.º 5
0
 def cov(self) -> coverage.Coverage:
     if self._cov is None:
         self._cov = get_coverage_obj(coverage_file=self.coverage_file, report_dir=self.report_dir, load_old=True)
     return self._cov
Ejemplo n.º 6
0
 def test_report_dir(self, monkeypatch, tmpdir):
     monkeypatch.chdir(tmpdir)
     coverage_obj = get_coverage_obj(coverage_file=None, report_dir=tmpdir)
     assert coverage_obj.config.html_dir == tmpdir.join('html')
     assert coverage_obj.config.xml_output == tmpdir.join('coverage.xml')
     assert coverage_obj.config.json_output == tmpdir.join('coverage.json')
Ejemplo n.º 7
0
 def test_cov_file(self, tmpdir):
     cov_file = tmpdir.join('.coverage')
     coverage_obj = get_coverage_obj(coverage_file=cov_file,
                                     report_dir=None)
     assert coverage_obj.config.data_file == cov_file
Ejemplo n.º 8
0
 def test_without_data(self, monkeypatch, tmpdir):
     monkeypatch.chdir(tmpdir)
     with pytest.raises(coverage.misc.CoverageException):
         get_coverage_obj(None, None).report()