@@ -0,0 +1,2768 @@
+# Copyright (c) 2021 elParaguayo%0A#%0A# Permission is hereby granted, free of charge, to any person obtaining a copy%0A# of this software and associated documentation files (the %22Software%22), to deal%0A# in the Software without restriction, including without limitation the rights%0A# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A# copies of the Software, and to permit persons to whom the Software is%0A# furnished to do so, subject to the following conditions:%0A#%0A# The above copyright notice and this permission notice shall be included in%0A# all copies or substantial portions of the Software.%0A#%0A# THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0A# SOFTWARE.%0A%0A# Widget specific tests%0A%0Aimport sys%0Afrom importlib import reload%0Afrom types import ModuleType%0A%0Aimport pytest%0A%0Aimport libqtile.config%0Afrom libqtile.bar import Bar%0A%0A%0Adef no_op(*args, **kwargs):%0A    pass%0A%0A%0Aclass MockIwlib(ModuleType):%0A    DATA = %7B%0A        'wlan0': %7B%0A            'NWID': b'Auto',%0A            'Frequency': b'5.18 GHz',%0A            'Access Point': b'12:34:56:78:90:AB',%0A            'BitRate': b'650 Mb/s',%0A            'ESSID': b'QtileNet',%0A            'Mode': b'Managed',%0A            'stats': %7B%0A                'quality': 49,%0A                'level': 190,%0A                'noise': 0,%0A                'updated': 75%0A            %7D%0A        %7D%0A    %7D%0A%0A    @classmethod%0A    def get_iwconfig(cls, interface):%0A        return cls.DATA.get(interface, dict())%0A%0A%0A# Patch the widget with our mock iwlib module.%0A@pytest.fixture%0Adef patched_wlan(monkeypatch):%0A    monkeypatch.setitem(sys.modules, %22iwlib%22, MockIwlib(%22iwlib%22))%0A    from libqtile.widget import wlan%0A%0A    # Reload fixes cases where psutil may have been imported previously%0A    reload(wlan)%0A%0A    yield wlan%0A%0A%0A@pytest.mark.parametrize(%0A    %22kwargs,expected%22, %5B%0A        (%7B%7D, %22QtileNet 49/70%22),%0A        (%7B%22format%22: %22%7Bessid%7D %7Bpercent:2.0%25%7D%22%7D, %22QtileNet 70%25%22),%0A        (%7B%22interface%22: %22wlan1%22%7D, %22Disconnected%22)%0A    %5D%0A)%0Adef test_wlan_display(minimal_conf_noscreen, manager_nospawn, patched_wlan, kwargs, expected):%0A    widget = patched_wlan.Wlan(**kwargs)%0A    config = minimal_conf_noscreen%0A    config.screens = %5B%0A        libqtile.config.Screen(%0A            top=Bar(%5Bwidget%5D, 10)%0A        )%0A    %5D%0A    manager_nospawn.start(config)%0A%0A    text = manager_nospawn.c.bar%5B%22top%22%5D.info()%5B%22widgets%22%5D%5B0%5D%5B%22text%22%5D%0A    assert text == expected%0A

Add test for wlan widget