mirror of
https://github.com/craigerl/aprsd.git
synced 2025-04-10 05:28:58 -04:00
Got unit tests working again
This commit is contained in:
parent
a270c75263
commit
f92b2ee364
@ -122,7 +122,7 @@ def get_installed_extensions():
|
||||
|
||||
|
||||
def show_built_in_plugins(console):
|
||||
modules = [email, fortune, location, notify, ping, query, time, version, weather]
|
||||
modules = [email, fortune, location, notify, ping, time, version, weather]
|
||||
plugins = []
|
||||
|
||||
for module in modules:
|
||||
|
@ -76,7 +76,11 @@ class WatchList(objectstore.ObjectStoreMixin):
|
||||
|
||||
def age(self, callsign):
|
||||
now = datetime.datetime.now()
|
||||
return str(now - self.last_seen(callsign))
|
||||
last_seen_time = self.last_seen(callsign)
|
||||
if last_seen_time:
|
||||
return str(now - last_seen_time)
|
||||
else:
|
||||
return None
|
||||
|
||||
def max_delta(self, seconds=None):
|
||||
if not seconds:
|
||||
|
@ -1,7 +1,8 @@
|
||||
import logging
|
||||
|
||||
import aprsd
|
||||
from aprsd import plugin, stats
|
||||
from aprsd import plugin
|
||||
from aprsd.stats import collector
|
||||
|
||||
|
||||
LOG = logging.getLogger("APRSD")
|
||||
@ -23,8 +24,8 @@ class VersionPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||
# fromcall = packet.get("from")
|
||||
# message = packet.get("message_text", None)
|
||||
# ack = packet.get("msgNo", "0")
|
||||
s = stats.APRSDStats().stats()
|
||||
s = collector.Collector().collect()
|
||||
return "APRSD ver:{} uptime:{}".format(
|
||||
aprsd.__version__,
|
||||
s["aprsd"]["uptime"],
|
||||
s["APRSDStats"]["uptime"],
|
||||
)
|
||||
|
@ -10,13 +10,23 @@ from aprsd import utils
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
@utils.singleton
|
||||
class APRSDStats:
|
||||
"""The AppStats class is used to collect stats from the application."""
|
||||
|
||||
_instance = None
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
"""Have to override the new method to make this a singleton
|
||||
|
||||
instead of using @singletone decorator so the unit tests work.
|
||||
"""
|
||||
if not cls._instance:
|
||||
cls._instance = super().__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
self.start_time = datetime.datetime.now()
|
||||
|
||||
@property
|
||||
def uptime(self):
|
||||
return datetime.datetime.now() - self.start_time
|
||||
|
||||
@ -24,7 +34,7 @@ class APRSDStats:
|
||||
current, peak = tracemalloc.get_traced_memory()
|
||||
stats = {
|
||||
"version": aprsd.__version__,
|
||||
"uptime": self.uptime,
|
||||
"uptime": self.uptime(),
|
||||
"callsign": CONF.callsign,
|
||||
"memory_current": int(current),
|
||||
"memory_current_str": utils.human_size(current),
|
||||
|
@ -1,3 +1,5 @@
|
||||
from unittest import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
import aprsd
|
||||
@ -11,7 +13,9 @@ CONF = cfg.CONF
|
||||
|
||||
class TestVersionPlugin(test_plugin.TestPlugin):
|
||||
|
||||
def test_version(self):
|
||||
@mock.patch("aprsd.stats.app.APRSDStats.uptime")
|
||||
def test_version(self, mock_stats):
|
||||
mock_stats.return_value = "00:00:00"
|
||||
expected = f"APRSD ver:{aprsd.__version__} uptime:00:00:00"
|
||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||
version = version_plugin.VersionPlugin()
|
||||
@ -31,10 +35,3 @@ class TestVersionPlugin(test_plugin.TestPlugin):
|
||||
)
|
||||
actual = version.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
packet = fake.fake_packet(
|
||||
message="Version",
|
||||
msg_number=1,
|
||||
)
|
||||
actual = version.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
|
@ -6,7 +6,7 @@ from oslo_config import cfg
|
||||
from aprsd import conf # noqa: F401
|
||||
from aprsd import packets
|
||||
from aprsd import plugin as aprsd_plugin
|
||||
from aprsd import plugins, stats
|
||||
from aprsd import plugins
|
||||
from aprsd.packets import core
|
||||
|
||||
from . import fake
|
||||
@ -89,7 +89,6 @@ class TestPlugin(unittest.TestCase):
|
||||
self.config_and_init()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
stats.APRSDStats._instance = None
|
||||
packets.WatchList._instance = None
|
||||
packets.SeenList._instance = None
|
||||
packets.PacketTrack._instance = None
|
||||
|
Loading…
Reference in New Issue
Block a user