File: test_cli.py

package info (click to toggle)
chirp 1%3A20251108-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,728 kB
  • sloc: python: 156,369; ansic: 296; sh: 219; xml: 24; makefile: 19
file content (42 lines) | stat: -rw-r--r-- 1,219 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import unittest
from unittest import mock

from chirp.cli import main


class TestCLI(unittest.TestCase):
    def setUp(self):
        self.stdout_lines = []
        self.patches = []
        self.patches.append(mock.patch('sys.exit'))
        self.patches.append(mock.patch.object(main, 'print',
                                              new=self.fake_print))
        for patch in self.patches:
            patch.start()

        # A path to an image file we can pass to the CLI for testing
        self.testfile = os.path.join(
            os.path.abspath(
                os.path.join(
                    os.path.dirname(__file__), '..', 'images',
                    'Icom_IC-2820H.img')))

    def tearDown(self):
        for patch in self.patches:
            patch.stop()

    def fake_print(self, *a):
        for i in a:
            self.stdout_lines.append(str(i))

    @property
    def stdout(self):
        return '\n'.join(self.stdout_lines)

    def test_cli_simple(self):
        # Super simple, just print the first memory and make sure it
        # works
        args = ['--mmap', self.testfile, '--get-mem', 0]
        main.main(args=args)
        self.assertIn('147.56', self.stdout)