Ejemplo n.º 1
0
 def test_access_method(self, cmd_mock: MagicMock) -> None:
     cmd_mock.return_value = 'something'
     self.assertEqual(lspci(access_method='somemethod'), 'something')
     self.assertEqual(cmd_mock.call_count, 1)
     self.assertEqual(
         cmd_mock.call_args,
         call(
             ['lspci', '-mm', '-Asomemethod', '-nn'],
             universal_newlines=True,
         ))
Ejemplo n.º 2
0
 def test_pcilib_params(self, cmd_mock: MagicMock) -> None:
     cmd_mock.return_value = 'something'
     self.assertEqual(lspci(pcilib_params={'a': 'b', 'c': 2}), 'something')
     self.assertEqual(cmd_mock.call_count, 1)
     self.assertEqual(
         cmd_mock.call_args,
         call(
             ['lspci', '-mm', '-nn', '-Oa=b', '-Oc=2'],
             universal_newlines=True,
         ))
Ejemplo n.º 3
0
 def test_hide_single_domain(self, cmd_mock: MagicMock) -> None:
     cmd_mock.return_value = 'something'
     self.assertEqual(lspci(hide_single_domain=False), 'something')
     self.assertEqual(cmd_mock.call_count, 1)
     self.assertEqual(
         cmd_mock.call_args,
         call(
             ['lspci', '-mm', '-D', '-nn'],
             universal_newlines=True,
         ))
Ejemplo n.º 4
0
 def test_bridge_paths(self, cmd_mock: MagicMock) -> None:
     cmd_mock.return_value = 'something'
     self.assertEqual(lspci(bridge_paths=True), 'something')
     self.assertEqual(cmd_mock.call_count, 1)
     self.assertEqual(
         cmd_mock.call_args,
         call(
             ['lspci', '-mm', '-PP', '-nn'],
             universal_newlines=True,
         ))
Ejemplo n.º 5
0
 def test_file(self, cmd_mock: MagicMock, is_file_mock: MagicMock) -> None:
     cmd_mock.return_value = 'something'
     is_file_mock.return_value = True
     self.assertEqual(lspci(file='/somewhere'), 'something')
     self.assertEqual(cmd_mock.call_count, 1)
     self.assertEqual(
         cmd_mock.call_args,
         call(
             ['lspci', '-mm', '-nn', '-F', '/somewhere'],
             universal_newlines=True,
         ))
     self.assertEqual(is_file_mock.call_count, 1)
Ejemplo n.º 6
0
 def test_id_resolve_option_name_only(self, cmd_mock: MagicMock) -> None:
     cmd_mock.return_value = 'something'
     self.assertEqual(
         lspci(id_resolve_option=IDResolveOption.NameOnly),
         'something',
     )
     self.assertEqual(cmd_mock.call_count, 1)
     self.assertEqual(cmd_mock.call_args,
                      call(
                          ['lspci', '-mm'],
                          universal_newlines=True,
                      ))
Ejemplo n.º 7
0
 def test_device_filter(self, cmd_mock: MagicMock) -> None:
     cmd_mock.return_value = 'something'
     self.assertEqual(
         lspci(device_filter=':13'),
         'something',
     )
     self.assertEqual(cmd_mock.call_count, 1)
     self.assertEqual(
         cmd_mock.call_args,
         call(
             ['lspci', '-mm', '-d', ':13:', '-nn'],
             universal_newlines=True,
         ))
Ejemplo n.º 8
0
    def run(self, **kwargs: Any) -> List[Device]:
        """
        Run the lspci command with the given arguments, defaulting to the
        parser's default arguments, and parse the result.

        :param \\**kwargs: Optional arguments to override the parser's default
           arguments. See :func:`lspci`'s documentation for a list of
           available arguments.
        :type \\**kwargs: Any
        :returns: A list of parsed devices.
        :rtype: List[Device]
        """
        from pylspci.command import lspci
        lspci_kwargs = self.default_lspci_args.copy()
        lspci_kwargs.update(kwargs)
        return self.parse(lspci(**lspci_kwargs))
Ejemplo n.º 9
0
    def test_everything(self, cmd_mock: MagicMock,
                        is_file_mock: MagicMock) -> None:
        cmd_mock.return_value = 'something'
        is_file_mock.return_value = True

        self.assertEqual(
            lspci(
                pciids='/pciids',
                pcimap='/pcimap',
                access_method='somemethod',
                pcilib_params={
                    'a': 'b',
                    'c': 42
                },
                file='/file',
                verbose=True,
                kernel_drivers=True,
                bridge_paths=True,
                hide_single_domain=False,
                id_resolve_option=IDResolveOption.IDOnly,
                slot_filter='c0fe:e:e',
                device_filter='c0fe::eeee',
            ), 'something')

        self.assertEqual(cmd_mock.call_count, 1)
        self.assertEqual(
            cmd_mock.call_args,
            call(
                [
                    'lspci', '-mm', '-vvv', '-k', '-PP', '-D', '-Asomemethod',
                    '-s', 'c0fe:e:e.', '-d', 'c0fe::eeee', '-n', '-i',
                    '/pciids', '-p', '/pcimap', '-F', '/file', '-Oa=b',
                    '-Oc=42'
                ],
                universal_newlines=True,
            ))
        self.assertEqual(is_file_mock.call_count, 3)
Ejemplo n.º 10
0
 def test_pcimap_missing(self, is_file_mock: MagicMock) -> None:
     is_file_mock.return_value = False
     with self.assertRaises(AssertionError):
         lspci(pcimap='/nowhere')
     self.assertEqual(is_file_mock.call_count, 1)