Skip to content

Commit

Permalink
Add test coverage for get_log_paths
Browse files Browse the repository at this point in the history
Update `get_log_paths` to check all log names with `-` normalized to `_` (appeared to be the original intent)
Add `enclosure` and `admin` service logs used by Neon and legacy Mycroft/OVOS setups
  • Loading branch information
NeonDaniel committed Jul 18, 2024
1 parent f302252 commit 9d20e91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ovos_utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"ovos",
"phal",
"phal-admin",
"enclosure",
"admin",
"hivemind",
"hivemind-voice-sat"}

Expand Down Expand Up @@ -341,6 +343,7 @@ def get_log_path(service: str, directories: Optional[List[str]] = None) \
Returns:
path to log directory for service
(returned path may be `None` if `directories` is specified)
"""
if directories:
for directory in directories:
Expand Down Expand Up @@ -376,8 +379,8 @@ def get_log_paths() -> Set[str]:
set of paths to log directories
"""
paths = set()
ALL_SERVICES.union({s.replace("-", "_") for s in ALL_SERVICES})
for service in ALL_SERVICES:
svc_names = ALL_SERVICES.union({s.replace("-", "_") for s in ALL_SERVICES})
for service in svc_names:
paths.add(get_log_path(service))

return paths
Expand Down
18 changes: 17 additions & 1 deletion test/unittests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,25 @@ def test_get_log_path(self, get_config):

@patch('ovos_utils.log.get_log_path')
def test_get_log_paths(self, get_log_path):
from ovos_utils.log import get_log_paths
from ovos_utils.log import get_log_paths, ALL_SERVICES

def mock_get_path_different(service) -> str:
return service

def mock_get_path_same(service) -> str:
return "log_path"

# Test services with different configured paths
get_log_path.side_effect = mock_get_path_different
paths = get_log_paths()
for svc in ALL_SERVICES:
self.assertIn(svc, paths)
if '-' in svc:
self.assertIn(svc.replace('-', '_'), paths)

# Test services with same path
get_log_path.side_effect = mock_get_path_same
self.assertEqual(get_log_paths(), {"log_path"})

@patch('ovos_utils.log.get_log_paths')
def test_get_available_logs(self, get_log_paths):
Expand Down

0 comments on commit 9d20e91

Please sign in to comment.