eric7/DataViews/PyCoverageJsonReportDialog.py

Thu, 19 May 2022 14:37:01 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 19 May 2022 14:37:01 +0200
branch
unittest
changeset 9078
44d1d68096b6
permissions
-rw-r--r--

Dataview Coverage
- added support to write coverage reports as HTML, JSON or LCOV files
- removed the support for writing annotated sources (deprecated in coverage.py)

# -*- coding: utf-8 -*-

# Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to enter the parameters for a coverage JSON
report.
"""

import os

from PyQt6.QtCore import pyqtSlot
from PyQt6.QtWidgets import QDialog, QDialogButtonBox

from EricWidgets.EricPathPicker import EricPathPickerModes

from .Ui_PyCoverageJsonReportDialog import Ui_PyCoverageJsonReportDialog


class PyCoverageJsonReportDialog(QDialog, Ui_PyCoverageJsonReportDialog):
    """
    Class implementing a dialog to enter the parameters for a coverage JSON
    report.
    """
    def __init__(self, defaultDirectory, parent=None):
        """
        Constructor
        
        @param defaultDirectory default directory for selecting the output
            directory
        @type str
        @param parent reference to the parent widget (defaults to None)
        @type QWidget (optional)
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.outputFilePicker.setMode(
            EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE)
        self.outputFilePicker.setDefaultDirectory(defaultDirectory)
        self.outputFilePicker.setFilters(
            self.tr("JSON Files (*.json);;All Files (*)"))
        self.outputFilePicker.setText(
            os.path.join(defaultDirectory, "coverage.json"))
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    @pyqtSlot(str)
    def on_outputFilePicker_textChanged(self, filename):
        """
        Private slot handling a change of the output file.
        
        @param filename current text of the file picker
        @type str
        """
        self.buttonBox.button(
            QDialogButtonBox.StandardButton.Ok).setEnabled(bool(filename))
    
    def getData(self):
        """
        Public method to get the entered data.
        
        @return tuple containing the output file and a flag indicating the
            creation of a compact JSON file
        
        @rtype tuple of (str, bool)
        """
        return (
            self.outputFilePicker.currentText(),
            self.compactCheckBox.isChecked(),
        )

eric ide

mercurial