Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/testing/mozbase/mozpower/tests/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  test_powerbase.py   Sprache: Python

 
#!/usr/bin/env python

from unittest import mock

import mozunit
import pytest
from mozpower.powerbase import (
    IPGExecutableMissingError,
    PlatformUnsupportedError,
    PowerBase,
)


def test_powerbase_intialization():
    """Tests that the PowerBase class correctly raises
    a NotImplementedError when attempting to instantiate
    it directly.
    """
    with pytest.raises(NotImplementedError):
        PowerBase()


def test_powerbase_missing_methods(powermeasurer):
    """Tests that trying to call PowerBase methods
    without an implementation in the subclass raises
    the NotImplementedError.
    """
    with pytest.raises(NotImplementedError):
        powermeasurer.initialize_power_measurements()

    with pytest.raises(NotImplementedError):
        powermeasurer.finalize_power_measurements()

    with pytest.raises(NotImplementedError):
        powermeasurer.get_perfherder_data()


def test_powerbase_get_ipg_path_mac(powermeasurer):
    """Tests that getting the IPG path returns the expected results."""
    powermeasurer._os = "darwin"
    powermeasurer._cpu = "not-intel"

    def os_side_effect(arg):
        """Used to get around the os.path.exists check in
        get_ipg_path which raises an IPGExecutableMissingError
        otherwise.
        """
        return True

    with mock.patch("os.path.exists", return_value=Trueas m:
        m.side_effect = os_side_effect

        # None is returned when a non-intel based machine is
        # tested.
        ipg_path = powermeasurer.get_ipg_path()
        assert ipg_path is None

        # Check the path returned for mac intel-based machines.
        powermeasurer._cpu = "intel"
        ipg_path = powermeasurer.get_ipg_path()
        assert ipg_path == "/Applications/Intel Power Gadget/PowerLog"


def test_powerbase_get_ipg_path_errors(powermeasurer):
    """Tests that the appropriate error is output when calling
    get_ipg_path with invalid/unsupported _os and _cpu entries.
    """

    powermeasurer._cpu = "intel"
    powermeasurer._os = "Not-An-OS"

    def os_side_effect(arg):
        """Used to force the error IPGExecutableMissingError to occur
        (in case a machine running these tests is a mac, and has intel
        power gadget installed).
        """
        return False

    with pytest.raises(PlatformUnsupportedError):
        powermeasurer.get_ipg_path()

    with mock.patch("os.path.exists", return_value=Falseas m:
        m.side_effect = os_side_effect

        powermeasurer._os = "darwin"
        with pytest.raises(IPGExecutableMissingError):
            powermeasurer.get_ipg_path()


if __name__ == "__main__":
    mozunit.main()

Messung V0.5
C=90 H=92 G=90

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.