-
Notifications
You must be signed in to change notification settings - Fork 9
/
posttests.py
46 lines (34 loc) · 1.36 KB
/
posttests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Unit tests to be run on the data produced.
Note: this file is not up to date, and will fail.
"""
from __future__ import unicode_literals
import decimal
import json
import os
import unittest
OUTPUT_DIR = 'out'
class TestAggregatedValues(unittest.TestCase):
def setUp(self):
with open(os.path.join(OUTPUT_DIR, 'aggregated.json')) as fp:
self.aggregated = json.load(fp, parse_float=decimal.Decimal)
def test_activity_sum(self):
a = self.aggregated
for key in ['activities_per_year']:
self.assertEqual(a['activities'], sum(a[key].values()), msg=key)
def test_spend_sum(self):
a = self.aggregated
for key in ['spend_per_year', 'spend_per_country']:
self.assertAlmostEqual(a['spend'], sum(a[key].values()), places=2)
def test_activities_upper_bound(self):
a = self.aggregated
for key in ['activities_per_country', 'activities_per_year']:
for value in a[key].values():
self.assertLessEqual(value, a['activities'], msg='{0} {1}'.format(key, value))
def test_publishers_upper_bound(self):
a = self.aggregated
for key in ['publishers_per_country']:
for value in a[key].values():
self.assertLessEqual(value, a['publishers'], msg='{0} {1}'.format(key, value))
if __name__ == '__main__':
unittest.main()