test_hostinfo.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2026 MOD Audio UG
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. """mod.hostinfo: what "Report a problem" says about a computer.
  5. Run with: python3 -m unittest discover -s test -p 'test_*.py'
  6. """
  7. import os
  8. import sys
  9. import tempfile
  10. import unittest
  11. REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. if REPO_ROOT not in sys.path:
  13. sys.path.insert(0, REPO_ROOT)
  14. from mod import hostinfo
  15. class TestCollect(unittest.TestCase):
  16. def test_answers_without_launcher_log(self):
  17. info = hostinfo.collect(['/nonexistent-folder'])
  18. self.assertTrue(info['os'])
  19. self.assertIsNone(info['launcher'])
  20. def test_launcher_log_start_and_problems_since_last_start(self):
  21. with tempfile.TemporaryDirectory() as folder:
  22. with open(os.path.join(folder, 'launcher.log'), 'w') as fh:
  23. fh.write("2026-10-11 10:00:00 Starting jackd using: -d portaudio -P OLD\n"
  24. "2026-10-11 10:00:01 Pa_OpenStream error = Invalid device\n"
  25. "2026-10-11 11:00:00 Starting jackd using: -d portaudio -P /home/me/Spk\n"
  26. "2026-10-11 11:00:01 \x1b[31mUnable to load model\x1b[0m\n"
  27. "2026-10-11 11:00:02 all fine\n")
  28. log = hostinfo.launcher_log([folder], '/home/me')
  29. self.assertEqual(log['jackd'], '-d portaudio -P ~/Spk')
  30. self.assertEqual(log['problems'], ['2026-10-11 11:00:01 Unable to load model'])
  31. if __name__ == '__main__':
  32. unittest.main()