xref: /aosp_15_r20/external/rappor/pipeline/task_spec_test.py (revision 2abb31345f6c95944768b5222a9a5ed3fc68cc00)
1#!/usr/bin/python -S
2"""
3task_spec_test.py: Tests for task_spec.py
4"""
5
6import cStringIO
7import unittest
8
9import task_spec  # module under test
10
11
12class TaskSpecTest(unittest.TestCase):
13
14  def testCountReports(self):
15    f = cStringIO.StringIO("""\
161,2
173,4
185,6
19""")
20    c = task_spec.CountReports(f)
21    self.assertEqual(9, c)
22
23  def testDist(self):
24    # NOTE: These files are opened, in order to count the reports.  Maybe skip
25    # that step.
26    f = cStringIO.StringIO("""\
27_tmp/counts/2015-12-01/exp_counts.csv
28_tmp/counts/2015-12-01/gauss_counts.csv
29_tmp/counts/2015-12-02/exp_counts.csv
30_tmp/counts/2015-12-02/gauss_counts.csv
31""")
32    input_iter = task_spec.DistInputIter(f)
33    #for row in input_iter:
34    #  print row
35
36    field_id_lookup = {}
37
38    # var name -> map filename
39    f = cStringIO.StringIO("""\
40var,map_filename
41exp,map.csv
42unif,map.csv
43gauss,map.csv
44""")
45    dist_maps = task_spec.DistMapLookup(f, '_tmp/maps')
46
47    f2 = cStringIO.StringIO("""\
48metric,var,var_type,params
49exp,,string,params
50unif,,string,params
51gauss,,string,params
52""")
53    var_schema = task_spec.VarSchema(f2, '_tmp/config')
54
55    for row in task_spec.DistTaskSpec(
56        input_iter, field_id_lookup, var_schema, dist_maps, None):
57      print row
58
59
60if __name__ == '__main__':
61  unittest.main()
62