Repository: vanbalken/arris-tg2492lg (language: python)

Issue:
Replace unittest with pytest
Replace unittest with pytest


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml
index b1a8069..b7b4095 100644
--- a/.github/workflows/continuous-integration-workflow.yml
+++ b/.github/workflows/continuous-integration-workflow.yml
@@ -16,7 +16,7 @@ jobs:
         python -m pip install --upgrade pip setuptools wheel
         python -m pip install -r requirements.txt
     - name: Test
-      run: python -m unittest
+      run: python -m pytest
     - name: Lint and type check
       run: |
         python -m flake8
diff --git a/requirements.txt b/requirements.txt
index fc624d1..81630cf 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
 requests
 flake8
 mypy
+pytest


Test patch:
diff --git a/tests/test_mib_mapper.py b/tests/test_mib_mapper.py
index 498b5bb..68f659f 100644
--- a/tests/test_mib_mapper.py
+++ b/tests/test_mib_mapper.py
@@ -1,4 +1,3 @@
-import unittest
 import ipaddress
 import os
 from pathlib import Path
@@ -6,64 +5,64 @@
 import arris_tg2492lg.mib_mapper as mib_mapper
 
 
-class TestMibMapper(unittest.TestCase):
-    def test_to_devices(self):
+class TestMibMapper():
+    def test_to_devices(self) -> None:
         current_path = Path(os.path.dirname(os.path.realpath(__file__)))
         test_data_path = current_path / "getConnDevices-response.json"
         get_conn_devices_json = test_data_path.read_text()
 
         devices = mib_mapper.to_devices(get_conn_devices_json)
 
-        self.assertEqual(len(devices), 4)
+        assert len(devices) == 4
 
         device = devices[0]
 
-        self.assertEqual(device.ip, ipaddress.ip_address("192.168.178.2"))
-        self.assertEqual(device.hostname, "My Device")
-        self.assertEqual(device.mac, "12:34:56:78:90:AB")
-        self.assertEqual(device.adapter_type, "wireless1")
-        self.assertEqual(device.type, "1")
-        self.assertEqual(device.lease_end, "2019-11-03 16:51:04:00")
-        self.assertEqual(device.row_status, "1")
-        self.assertEqual(device.online, True)
-        self.assertEqual(device.comment, "")
-        self.assertEqual(device.device_name, "unknown device")
+        assert device.ip == ipaddress.ip_address("192.168.178.2")
+        assert device.hostname == "My Device"
+        assert device.mac == "12:34:56:78:90:AB"
+        assert device.adapter_type == "wireless1"
+        assert device.type == "1"
+        assert device.lease_end == "2019-11-03 16:51:04:00"
+        assert device.row_status == "1"
+        assert device.online
+        assert device.comment == ""
+        assert device.device_name == "unknown device"
 
         device2 = devices[1]
 
-        self.assertEqual(device2.ip, ipaddress.ip_address("192.168.178.3"))
-        self.assertEqual(device2.hostname, "My Device 2")
-        self.assertEqual(device2.mac, "BA:09:87:65:43:21")
-        self.assertEqual(device2.adapter_type, "ethernet2")
-        self.assertEqual(device2.type, "5")
-        self.assertEqual(device2.lease_end, "0000-00-00 00:00:00:00")
-        self.assertEqual(device2.row_status, "1")
-        self.assertEqual(device2.online, True)
-        self.assertEqual(device2.comment, "")
-        self.assertEqual(device2.device_name, "unknown device")
+        assert device2.ip == ipaddress.ip_address("192.168.178.3")
+        assert device2.hostname == "My Device 2"
+        assert device2.mac == "BA:09:87:65:43:21"
+        assert device2.adapter_type == "ethernet2"
+        assert device2.type == "5"
+        assert device2.lease_end == "0000-00-00 00:00:00:00"
+        assert device2.row_status == "1"
+        assert device2.online
+        assert device2.comment == ""
+        assert device2.device_name == "unknown device"
 
         device3 = devices[2]
 
-        self.assertEqual(device3.ip, ipaddress.ip_address("2001:1c12:8d6:bb00:b0f6:855a:dcd:5528"))
-        self.assertEqual(device3.hostname, "My Device 3")
-        self.assertEqual(device3.mac, "AA:AA:AA:AA:AA:AA")
-        self.assertEqual(device3.adapter_type, "ethernet2")
-        self.assertEqual(device3.type, "5")
-        self.assertEqual(device3.lease_end, "0000-00-00 00:00:00:00")
-        self.assertEqual(device3.row_status, "1")
-        self.assertEqual(device3.online, True)
-        self.assertEqual(device3.comment, "")
-        self.assertEqual(device3.device_name, "device 3")
+        assert device3.ip == ipaddress.ip_address("2001:1c12:8d6:bb00:b0f6:855a:dcd:5528")
+        assert device3.hostname == "My Device 3"
+        assert device3.mac == "AA:AA:AA:AA:AA:AA"
+        assert device3.adapter_type == "ethernet2"
+        assert device3.type == "5"
+        assert device3.lease_end == "0000-00-00 00:00:00:00"
+        assert device3.row_status == "1"
+        assert device3.online
+        assert device3.comment == ""
+        assert device3.device_name == "device 3"
 
         device4 = devices[3]
 
-        self.assertEqual(device4.ip, ipaddress.ip_address("2001:1c12:8d6:bb00:b0f6:855a:dcd:5529"))
-        self.assertEqual(device4.hostname, "My Device")
-        self.assertEqual(device4.mac, "12:34:56:78:90:AB")
-        self.assertEqual(device4.adapter_type, "wireless1")
-        self.assertEqual(device4.type, "1")
-        self.assertEqual(device4.lease_end, "2019-11-03 16:51:04:00")
-        self.assertEqual(device4.row_status, "1")
-        self.assertEqual(device4.online, True)
-        self.assertEqual(device4.comment, "")
-        self.assertEqual(device4.device_name, "unknown device")
+        assert device4.ip == ipaddress.ip_address("2001:1c12:8d6:bb00:b0f6:855a:dcd:5529")
+        assert device4.hostname == "My Device"
+        assert device4.mac == "12:34:56:78:90:AB"
+        assert device4.adapter_type == "wireless1"
+        assert device4.type == "1"
+        assert device4.lease_end == "2019-11-03 16:51:04:00"
+        assert device4.row_status == "1"
+        assert device4.online
+        assert device4.comment == ""
+        assert device4.device_name == "unknown device"
diff --git a/tests/test_single_value_cache.py b/tests/test_single_value_cache.py
index 50f81a7..bc8044e 100644
--- a/tests/test_single_value_cache.py
+++ b/tests/test_single_value_cache.py
@@ -1,26 +1,32 @@
-import unittest
+import pytest
 
 from arris_tg2492lg.single_value_cache import SingleValueCache
 
 
-class TestSingleValueCache(unittest.TestCase):
-    count = 0
+class Counter:
+    def __init__(self) -> None:
+        self._count: int = 0
 
-    def counter(self):
-        self.count += 1
-        return self.count
+    def increment(self) -> str:
+        self._count += 1
+        return str(self._count)
 
-    def setUp(self):
-        self.count = 0
 
-    def test_cached_value_is_used_before_expired(self):
-        svc = SingleValueCache(100, self.counter)
+@pytest.fixture()
+def counter() -> Counter:
+    return Counter()
 
-        self.assertEqual(svc.get(), 1)
-        self.assertEqual(svc.get(), 1)
 
-    def test_supplier_method_is_used_after_value_expired(self):
-        svc = SingleValueCache(-100, self.counter)
+class TestSingleValueCache():
 
-        self.assertEqual(svc.get(), 1)
-        self.assertEqual(svc.get(), 2)
+    def test_cached_value_is_used_before_expired(self, counter: Counter) -> None:
+        svc = SingleValueCache(100, counter.increment)
+
+        assert svc.get() == "1"
+        assert svc.get() == "1"
+
+    def test_supplier_method_is_used_after_value_expired(self, counter: Counter) -> None:
+        svc = SingleValueCache(-100, counter.increment)
+
+        assert svc.get() == "1"
+        assert svc.get() == "2"