Example #1
0
 def test_fix(self, tmpdir, cov_file_name, python_file_dir):
     dot_coverage_path = tmpdir.join('.coverage')
     copy_file(os.path.join(COVERAGE_FILES_DIR, cov_file_name),
               dot_coverage_path)
     fix_file_path(dot_coverage_path, python_file_dir)
     with sqlite3.connect(dot_coverage_path) as sql_connection:
         cursor = sql_connection.cursor()
         data = cursor.execute('SELECT * FROM file').fetchall()[0]
         assert data == (1, python_file_dir)
         cursor.close()
Example #2
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()
 def test_with_json_min_report(self, tmpdir, monkeypatch, caplog):
     monkeypatch.chdir(tmpdir)
     coverage_path = os.path.join(COVERAGE_FILES_DIR,
                                  'HealthCheckAnalyzeLargeInvestigations')
     temp_cover_file = tmpdir.join('.coverage')
     copy_file(coverage_path, temp_cover_file)
     fix_file_path(temp_cover_file, PYTHON_FILE_PATH)
     cov_report = CoverageReport(report_dir=str(tmpdir),
                                 report_type='json,json-min',
                                 coverage_file=temp_cover_file)
     with caplog.at_level(logging.INFO, logger='demisto-sdk'):
         cov_report.coverage_report()
     # assert re.fullmatch(self.patern('json-min', 'coverage-min', 'json'), caplog.records[2].msg)
     assert os.path.exists(tmpdir.join('coverage-min.json'))
 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%'
     ]
    def test_with_export_report_function(self, tmpdir, monkeypatch, caplog):
        monkeypatch.chdir(tmpdir)
        coverage_path = os.path.join(COVERAGE_FILES_DIR,
                                     'HealthCheckAnalyzeLargeInvestigations')
        temp_cover_file = tmpdir.join('.coverage')
        copy_file(coverage_path, temp_cover_file)
        fix_file_path(temp_cover_file, PYTHON_FILE_PATH)
        cov_report = CoverageReport(report_dir=str(tmpdir),
                                    report_type='html,json,xml',
                                    coverage_file=temp_cover_file)
        with caplog.at_level(logging.INFO, logger='demisto-sdk'):
            cov_report.coverage_report()

        assert re.fullmatch(self.patern('html', 'html/index', 'html'),
                            caplog.records[1].msg)
        assert re.fullmatch(self.patern('xml', 'coverage', 'xml'),
                            caplog.records[2].msg)
        assert re.fullmatch(self.patern('json', 'coverage', 'json'),
                            caplog.records[3].msg)
        assert len(caplog.records) == 4
Example #7
0
    def test_with_two_files(self, caplog, tmpdir, cov_file_names):
        logging_setup(3).propagate = True
        cov_files_paths = []
        for cov_file_name in cov_file_names:
            named_coverage_path = tmpdir.join(cov_file_name)
            copy_file(os.path.join(COVERAGE_FILES_DIR, cov_file_name),
                      named_coverage_path)
            cov_files_paths.append(named_coverage_path)
        dot_cov_file_path = tmpdir.join('.covergae')
        cov_obj = coverage.Coverage(data_file=dot_cov_file_path)
        cov_obj.combine(cov_files_paths)

        with caplog.at_level(logging.ERROR & logging.DEBUG,
                             logger='demisto-sdk'):
            fix_file_path(dot_cov_file_path, 'some_path')

        assert len(caplog.records) == 2
        assert caplog.records[
            0].msg == 'unexpected file list in coverage report'
        assert caplog.records[0].levelname == 'ERROR'
        assert caplog.records[
            1].msg == 'removing coverage report for some_path'
        assert caplog.records[1].levelname == 'DEBUG'
        assert not os.path.exists(dot_cov_file_path)