Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  test_moznetwork.py

  Sprache: Python
 

#!/usr/bin/env python
"""
Unit-Tests for moznetwork
"""

import re
import shutil
import subprocess
from unittest import mock

import mozinfo
import moznetwork
import mozunit
import pytest


@pytest.fixture(scope="session")
def ip_addresses():
    """List of IP addresses associated with the host."""

    # Regex to match IPv4 addresses.
    # 0-255.0-255.0-255.0-255, note order is important here.
    regexip = re.compile(
        r"((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.){3}"
        r"(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)"
    )

    commands = (
        ["ip""addr""show"],
        ["ifconfig"],
        ["ipconfig"],
        # Explicitly search '/sbin' because it doesn't always appear
        # to be on the $PATH of all systems
        ["/sbin/ip""addr""show"],
        ["/sbin/ifconfig"],
    )

    cmd = None
    for command in commands:
        if shutil.which(command[0]):
            cmd = command
            break
    else:
        raise OSError(
            "No program for detecting ip address found! Ensure one of 'ip', "
            "'ifconfig' or 'ipconfig' exists on your $PATH."
        )

    ps = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    standardoutput, _ = ps.communicate()

    # Generate a list of IPs by parsing the output of ip/ifconfig
    return [x.group() for x in re.finditer(regexip, standardoutput.decode("UTF-8"))]


def test_get_ip(ip_addresses):
    """Attempt to test the IP address returned by
    moznetwork.get_ip() is valid"""
    assert moznetwork.get_ip() in ip_addresses


@pytest.mark.skipif(mozinfo.isWin, reason="Test is not supported in Windows")
def test_get_ip_using_get_interface(ip_addresses):
    """Test that the control flow path for get_ip() using
    _get_interface_list() is works"""
    with mock.patch("socket.gethostbyname"as byname:
        # Force socket.gethostbyname to return None
        byname.return_value = None
        assert moznetwork.get_ip() in ip_addresses


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

Messung V0.5 in Prozent
C=87 H=96 G=91

¤ Dauer der Verarbeitung: 0.18 Sekunden  (vorverarbeitet am  2026-06-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik