Esempio n. 1
0
class GroupByResultCalculationTest(TestCase):
    '''Test calculation of GroupByResult'''
    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1:
            GroupByResult({
                'a': 1,
                'b': 2,
                'c': 3
            }),
            2:
            GroupByResult({
                1: 1,
                2: 2
            }),
            3:
            GroupByResult({
                'PASSED': 10,
                'WAIVED': 20,
                'FAILED': 30,
                'PAUSED': 40
            }),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())
Esempio n. 2
0
class GroupByResultCalculationTest(TestCase):
    '''Test calculation of GroupByResult'''

    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1: GroupByResult({'a': 1,
                              'b': 2,
                              'c': 3}),
            2: GroupByResult({1: 1,
                              2: 2}),
            3: GroupByResult({'PASSED': 10,
                              'WAIVED': 20,
                              'FAILED': 30,
                              'PAUSED': 40}),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())
Esempio n. 3
0
class GroupByResultCalculationTest(unittest.TestCase):
    """Test calculation of GroupByResult"""
    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1:
            GroupByResult({
                'a': 1,
                'b': 2,
                'c': 3
            }),
            2:
            GroupByResult({
                1: 1,
                2: 2
            }),
            3:
            GroupByResult({
                'PASSED': 10,
                'WAIVED': 20,
                'FAILED': 30,
                'PAUSED': 40
            }),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())

    def test_get_total_after_add_data_based_on_empty_initial_data(self):
        result = GroupByResult()
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(200, result.total)

    def test_get_total_after_add_data_based_on_initial_data(self):
        result = GroupByResult({'FAILED': 20})
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(220, result.total)

    def test_total_is_updated_after_del_item(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        self.assertEqual(30, result.total)

    def test_total_is_updated_after_del_item_several_times(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        del result['FAILED']
        self.assertEqual(10, result.total)

    def test_percentage(self):
        result = GroupByResult({
            'IDLE': 20,
            'PASSED': 20,
            'RUNNING': 10,
        })
        self.assertEqual(40.0, result.PASSED_percent)

    def test_zero_percentage(self):
        result = GroupByResult({})
        self.assertEqual(.0, result.PASSED_percent)

    def test_arithmetic_operation(self):
        result = GroupByResult({'IDLE': 1, 'RUNNING': 1, 'FAILED': 2})
        result['IDLE'] += 1
        result['RUNNING'] += 100
        result['FAILED'] -= 2
        self.assertEqual(2, result['IDLE'])
        self.assertEqual(101, result['RUNNING'])
        self.assertEqual(0, result['FAILED'])
Esempio n. 4
0
class GroupByResultCalculationTest(unittest.TestCase):
    """Test calculation of GroupByResult"""

    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1: GroupByResult({'a': 1,
                              'b': 2,
                              'c': 3}),
            2: GroupByResult({1: 1,
                              2: 2}),
            3: GroupByResult({'PASSED': 10,
                              'WAIVED': 20,
                              'FAILED': 30,
                              'PAUSED': 40}),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())

    def test_get_total_after_add_data_based_on_empty_initial_data(self):
        result = GroupByResult()
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(200, result.total)

    def test_get_total_after_add_data_based_on_initial_data(self):
        result = GroupByResult({'FAILED': 20})
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(220, result.total)

    def test_total_is_updated_after_del_item(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        self.assertEqual(30, result.total)

    def test_total_is_updated_after_del_item_several_times(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        del result['FAILED']
        self.assertEqual(10, result.total)

    def test_percentage(self):
        result = GroupByResult({
            'IDLE': 20,
            'PASSED': 20,
            'RUNNING': 10,
        })
        self.assertEqual(40.0, result.PASSED_percent)

    def test_zero_percentage(self):
        result = GroupByResult({})
        self.assertEqual(.0, result.PASSED_percent)

    def test_default_zero(self):
        result = GroupByResult()
        result['RUNNING'] += 1
        self.assertEqual(1, result['RUNNING'])