Example #1
0
    def test_print_report_header_without_process_user(self):
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer, self.options)

        reporter.print_report(123, 4, "  ", "    ")

        printer.assert_any_call("Timestamp  UID\tPID\tusr\tsystem\tguest\t%CPU\tCPU\tCommand")
    def test_print_report_without_filtering(self):
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer, self.options)

        reporter.print_report(123, 4)

        printer.assert_called_with("123\t1000\t1\t2.43\t1.24\t0.0\t3.67\t1\tprocess_1")
    def test_print_report_with_system_percent_none(self):
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        self.processes[0].system_percent = Mock(return_value=None)
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer, self.options)

        reporter.print_report(123, 4)

        printer.assert_called_with("123\t1000\t1\t2.43\tNone\t0.0\t3.67\t1\tprocess_1")
Example #4
0
    def test_print_report_with_per_processor_usage(self):
        self.options.per_processor_usage = True
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer, self.options)

        reporter.print_report(123, 4, "  ", "    ")

        printer.assert_called_with("123    1000\t1\t2.43\t1.24\t0.0\t0.92\t1\tprocess_1")
Example #5
0
    def test_print_report_with_user_name(self):
        self.options.show_process_user = '******'
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer, self.options)

        reporter.print_report(123, 4, "  ", "    ")

        printer.assert_called_with("123    pcp\t1\t2.43\t1.24\t0.0\t3.67\t1\tprocess_1")
Example #6
0
    def test_print_report_with_total_percent_none(self):
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        self.processes[0].total_percent = Mock(return_value=None)
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer,
                                    self.options)

        reporter.print_report(123, 4)

        printer.assert_called_with(
            "123\t1000\t1\t2.43\t1.24\t0.0\t?\t1\tprocess_1")
    def test_print_report_with_per_processor_usage(self):
        self.options.per_processor_usage = True
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer,
                                    self.options)

        reporter.print_report(123, 4)

        printer.assert_called_with(
            "123\t1000\t1\t2.43\t1.24\t0.0\t0.92\t1\tprocess_1")
    def test_print_report_with_user_name(self):
        self.options.show_process_user = '******'
        cpu_usage = Mock()
        process_filter = Mock()
        printer = Mock()
        process_filter.filter_processes = Mock(return_value=self.processes)
        reporter = CpuUsageReporter(cpu_usage, process_filter, 1, printer,
                                    self.options)

        reporter.print_report(123, 4)

        printer.assert_called_with(
            "123\tpcp\t1\t2.43\t1.24\t0.0\t3.67\t1\tprocess_1")