Example #1
0
    def test_disk_df_output_dict(self, run_mock):
        """Test method to get `df` output as a dict by mocking calls to `subprocess.run`"""
        with self.subTest('`df` regular output.'):
            run_mock.return_value.stdout = '\n'.join([
                "Filesystem               1024-blocks      Used     Available Capacity Mounted on",
                "/dev/nvme0n1p2             499581952 427458276      67779164      87% /",
                "tmpfs                        8127236       292       8126944       1% /tmp",
                "/dev/nvme0n1p1                523248     35908        487340       7% /boot",
                ""
            ])
            self.assertDictEqual(
                Disk._get_df_output_dict(),  # pylint: disable=protected-access
                {
                    '/': {
                        'device_path': '/dev/nvme0n1p2',
                        'used_blocks': 427458276,
                        'total_blocks': 499581952
                    },
                    '/tmp': {
                        'device_path': 'tmpfs',
                        'used_blocks': 292,
                        'total_blocks': 8127236
                    },
                    '/boot': {
                        'device_path': '/dev/nvme0n1p1',
                        'used_blocks': 35908,
                        'total_blocks': 523248
                    }
                })

        with self.subTest('`df` missing from system.'):
            run_mock.side_effect = FileNotFoundError()
            self.assertDictEqual(
                Disk._get_df_output_dict(),  # pylint: disable=protected-access
                {})
Example #2
0
    def test_disk_df_output_dict(self, run_mock):
        """Test method to get `df` output as a dict by mocking calls to `subprocess.run`"""
        with self.subTest('`df` regular output.'):
            run_mock.return_value.stdout = '\n'.join([
                "Filesystem               1024-blocks      Used     Available Capacity Mounted on",
                "/dev/nvme0n1p2             499581952 427458276      67779164      87% /",
                "tmpfs                        8127236       292       8126944       1% /tmp",
                "/dev/nvme0n1p1                523248     35908        487340       7% /boot",
                "/dev/sda1                       1624        42          1582       1% /what is  this",             # pylint: disable=line-too-long
                "map auto_home                      0         0             0     100% /System/Volumes/Data/home",  # pylint: disable=line-too-long
                "/Applications/Among Us.app/Wrapper 0         0             0     100% /System/Volumes/Data/game",  # pylint: disable=line-too-long
                ""
            ])
            self.assertDictEqual(
                Disk._get_df_output_dict(),  # pylint: disable=protected-access
                {
                    '/': {
                        'device_path': '/dev/nvme0n1p2',
                        'used_blocks': 427458276,
                        'total_blocks': 499581952
                    },
                    '/tmp': {
                        'device_path': 'tmpfs',
                        'used_blocks': 292,
                        'total_blocks': 8127236
                    },
                    '/boot': {
                        'device_path': '/dev/nvme0n1p1',
                        'used_blocks': 35908,
                        'total_blocks': 523248
                    },
                    '/what is  this': {
                        'device_path': '/dev/sda1',
                        'used_blocks': 42,
                        'total_blocks': 1624
                    }
                }
            )

        with self.subTest('`df` missing from system.'):
            run_mock.side_effect = FileNotFoundError()
            self.assertDictEqual(
                Disk._get_df_output_dict(),  # pylint: disable=protected-access
                {}
            )