コード例 #1
0
    def test_returns_the_current_value_for_a_metric_that_has_instances(self):
        utime_mock = Mock(netValues=[(Mock(inst=111), 'dummyprocess', 12345)],
                          netPrevValues=[(Mock(inst=111), 'dummyprocess',
                                          12354)])
        group = {'proc.psinfo.utime': utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('proc.psinfo.utime', 111)

        self.assertEquals(c_utime, 12345)
コード例 #2
0
    def test_returns_none_if_a_metric_does_not_exist_for_a_metric_that_has_no_instance(
            self):
        utime_mock = Mock(netValues=[('NULL', None, 12345)],
                          netPrevValues=[('NULL', None, 12354)])
        group = {'kernel.all.cpu.user': utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('kernel.all.cpu.guest', None)

        self.assertIsNone(c_utime)
コード例 #3
0
    def test_returns_none_if_a_metric_does_not_exist_for_an_instance(self):
        utime_mock = Mock(netValues=[(Mock(inst=111), 'dummyprocess', 12345)],
                          netPrevValues=[(Mock(inst=111), 'dummyprocess',
                                          12354)])
        group = {'proc.psinfo.utime': utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('proc.psinfo.time', 111)

        self.assertIsNone(c_utime)
コード例 #4
0
    def test_returns_the_current_value_for_a_metric_that_has_no_instances(
            self):
        utime_mock = Mock(netValues=[('NULL', None, 12345)],
                          netPrevValues=[('NULL', None, 12354)])
        group = {'kernel.all.cpu.user': utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('kernel.all.cpu.user', None)

        self.assertEquals(c_utime, 12345)
コード例 #5
0
    def test_returns_the_current_value_for_a_metric_that_has_instances(self):
        utime_mock = Mock(
            netValues = [(Mock(inst=111),'dummyprocess',12345)],
            netPrevValues = [(Mock(inst=111),'dummyprocess',12354)]
        )
        group = {'proc.psinfo.utime':utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('proc.psinfo.utime',111)

        self.assertEquals(c_utime,12345)
コード例 #6
0
    def test_returns_none_if_a_metric_does_not_exist_for_a_metric_that_has_no_instance(self):
        utime_mock = Mock(
            netValues = [('NULL',None,12345)],
            netPrevValues = [('NULL',None,12354)]
        )
        group = {'kernel.all.cpu.user':utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('kernel.all.cpu.guest',None)

        self.assertIsNone(c_utime)
コード例 #7
0
    def test_returns_none_if_a_metric_does_not_exist_for_an_instance(self):
        utime_mock = Mock(
            netValues = [(Mock(inst=111),'dummyprocess',12345)],
            netPrevValues = [(Mock(inst=111),'dummyprocess',12354)]
        )
        group = {'proc.psinfo.utime':utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('proc.psinfo.time',111)

        self.assertIsNone(c_utime)
コード例 #8
0
    def test_returns_the_current_value_for_a_metric_that_has_no_instances(self):
        utime_mock = Mock(
            netValues = [('NULL',None,12345)],
            netPrevValues = [('NULL',None,12354)]
        )
        group = {'kernel.all.cpu.user':utime_mock}
        m_repo = ReportingMetricRepository(group)

        c_utime = m_repo.current_value('kernel.all.cpu.user',None)

        self.assertEquals(c_utime,12345)
コード例 #9
0
    def test_checks_if_metric_values_are_fetched_only_once_if_not_available(self):
        proc_utime_mock = Mock(
            netValues = [(Mock(inst=111),'dummyprocess',12345)],
            netPrevValues = [(Mock(inst=111),'dummyprocess',12354)]
        )
        group = {'proc.psinfo.utime':proc_utime_mock}
        m_repo = ReportingMetricRepository(group)
        fetch_call_count = 0

        with mock.patch.object(m_repo,'_ReportingMetricRepository__fetch_current_values',return_value={111:12345}) as method:
            c_ptime = m_repo.current_value('proc.psinfo.utime',111)
            fetch_call_count = method.call_count

        self.assertEquals(fetch_call_count,1)