|
16 | 16 | class ViewServerTestCase(unittest.TestCase):
|
17 | 17 |
|
18 | 18 | def test_reset(self):
|
19 |
| - input = StringIO('["reset"]\n') |
| 19 | + input = StringIO(b'["reset"]\n') |
20 | 20 | output = StringIO()
|
21 | 21 | view.run(input=input, output=output)
|
22 |
| - self.assertEqual(output.getvalue(), 'true\n') |
| 22 | + self.assertEqual(output.getvalue(), b'true\n') |
23 | 23 |
|
24 | 24 | def test_add_fun(self):
|
25 |
| - input = StringIO('["add_fun", "def fun(doc): yield None, doc"]\n') |
| 25 | + input = StringIO(b'["add_fun", "def fun(doc): yield None, doc"]\n') |
26 | 26 | output = StringIO()
|
27 | 27 | view.run(input=input, output=output)
|
28 |
| - self.assertEqual(output.getvalue(), 'true\n') |
| 28 | + self.assertEqual(output.getvalue(), b'true\n') |
29 | 29 |
|
30 | 30 | def test_map_doc(self):
|
31 |
| - input = StringIO('["add_fun", "def fun(doc): yield None, doc"]\n' |
32 |
| - '["map_doc", {"foo": "bar"}]\n') |
| 31 | + input = StringIO(b'["add_fun", "def fun(doc): yield None, doc"]\n' |
| 32 | + b'["map_doc", {"foo": "bar"}]\n') |
33 | 33 | output = StringIO()
|
34 | 34 | view.run(input=input, output=output)
|
35 | 35 | self.assertEqual(output.getvalue(),
|
36 |
| - 'true\n' |
37 |
| - '[[[null, {"foo": "bar"}]]]\n') |
| 36 | + b'true\n' |
| 37 | + b'[[[null, {"foo": "bar"}]]]\n') |
38 | 38 |
|
39 | 39 | def test_i18n(self):
|
40 |
| - input = StringIO('["add_fun", "def fun(doc): yield doc[\\"test\\"], doc"]\n' |
41 |
| - '["map_doc", {"test": "b\xc3\xa5r"}]\n') |
| 40 | + input = StringIO(b'["add_fun", "def fun(doc): yield doc[\\"test\\"], doc"]\n' |
| 41 | + b'["map_doc", {"test": "b\xc3\xa5r"}]\n') |
42 | 42 | output = StringIO()
|
43 | 43 | view.run(input=input, output=output)
|
44 | 44 | self.assertEqual(output.getvalue(),
|
45 |
| - 'true\n' |
46 |
| - '[[["b\xc3\xa5r", {"test": "b\xc3\xa5r"}]]]\n') |
| 45 | + b'true\n' |
| 46 | + b'[[["b\xc3\xa5r", {"test": "b\xc3\xa5r"}]]]\n') |
47 | 47 |
|
48 | 48 | def test_map_doc_with_logging(self):
|
49 |
| - fun = 'def fun(doc): log(\'running\'); yield None, doc' |
50 |
| - input = StringIO('["add_fun", "%s"]\n' |
51 |
| - '["map_doc", {"foo": "bar"}]\n' % fun) |
| 49 | + fun = b'def fun(doc): log(\'running\'); yield None, doc' |
| 50 | + input = StringIO(b'["add_fun", "' + fun + b'"]\n' |
| 51 | + b'["map_doc", {"foo": "bar"}]\n') |
52 | 52 | output = StringIO()
|
53 | 53 | view.run(input=input, output=output)
|
54 | 54 | self.assertEqual(output.getvalue(),
|
55 |
| - 'true\n' |
56 |
| - '{"log": "running"}\n' |
57 |
| - '[[[null, {"foo": "bar"}]]]\n') |
| 55 | + b'true\n' |
| 56 | + b'{"log": "running"}\n' |
| 57 | + b'[[[null, {"foo": "bar"}]]]\n') |
58 | 58 |
|
59 | 59 | def test_map_doc_with_logging_json(self):
|
60 |
| - fun = 'def fun(doc): log([1, 2, 3]); yield None, doc' |
61 |
| - input = StringIO('["add_fun", "%s"]\n' |
62 |
| - '["map_doc", {"foo": "bar"}]\n' % fun) |
| 60 | + fun = b'def fun(doc): log([1, 2, 3]); yield None, doc' |
| 61 | + input = StringIO(b'["add_fun", "' + fun + b'"]\n' |
| 62 | + b'["map_doc", {"foo": "bar"}]\n') |
63 | 63 | output = StringIO()
|
64 | 64 | view.run(input=input, output=output)
|
65 | 65 | self.assertEqual(output.getvalue(),
|
66 |
| - 'true\n' |
67 |
| - '{"log": "[1, 2, 3]"}\n' |
68 |
| - '[[[null, {"foo": "bar"}]]]\n') |
| 66 | + b'true\n' |
| 67 | + b'{"log": "[1, 2, 3]"}\n' |
| 68 | + b'[[[null, {"foo": "bar"}]]]\n') |
69 | 69 |
|
70 | 70 | def test_reduce(self):
|
71 |
| - input = StringIO('["reduce", ' |
72 |
| - '["def fun(keys, values): return sum(values)"], ' |
73 |
| - '[[null, 1], [null, 2], [null, 3]]]\n') |
| 71 | + input = StringIO(b'["reduce", ' |
| 72 | + b'["def fun(keys, values): return sum(values)"], ' |
| 73 | + b'[[null, 1], [null, 2], [null, 3]]]\n') |
74 | 74 | output = StringIO()
|
75 | 75 | view.run(input=input, output=output)
|
76 |
| - self.assertEqual(output.getvalue(), '[true, [6]]\n') |
| 76 | + self.assertEqual(output.getvalue(), b'[true, [6]]\n') |
77 | 77 |
|
78 | 78 | def test_reduce_with_logging(self):
|
79 |
| - input = StringIO('["reduce", ' |
80 |
| - '["def fun(keys, values): log(\'Summing %r\' % (values,)); return sum(values)"], ' |
81 |
| - '[[null, 1], [null, 2], [null, 3]]]\n') |
| 79 | + input = StringIO(b'["reduce", ' |
| 80 | + b'["def fun(keys, values): log(\'Summing %r\' % (values,)); return sum(values)"], ' |
| 81 | + b'[[null, 1], [null, 2], [null, 3]]]\n') |
82 | 82 | output = StringIO()
|
83 | 83 | view.run(input=input, output=output)
|
84 | 84 | self.assertEqual(output.getvalue(),
|
85 |
| - '{"log": "Summing (1, 2, 3)"}\n' |
86 |
| - '[true, [6]]\n') |
| 85 | + b'{"log": "Summing (1, 2, 3)"}\n' |
| 86 | + b'[true, [6]]\n') |
87 | 87 |
|
88 | 88 | def test_rereduce(self):
|
89 |
| - input = StringIO('["rereduce", ' |
90 |
| - '["def fun(keys, values, rereduce): return sum(values)"], ' |
91 |
| - '[1, 2, 3]]\n') |
| 89 | + input = StringIO(b'["rereduce", ' |
| 90 | + b'["def fun(keys, values, rereduce): return sum(values)"], ' |
| 91 | + b'[1, 2, 3]]\n') |
92 | 92 | output = StringIO()
|
93 | 93 | view.run(input=input, output=output)
|
94 |
| - self.assertEqual(output.getvalue(), '[true, [6]]\n') |
| 94 | + self.assertEqual(output.getvalue(), b'[true, [6]]\n') |
95 | 95 |
|
96 | 96 | def test_reduce_empty(self):
|
97 |
| - input = StringIO('["reduce", ' |
98 |
| - '["def fun(keys, values): return sum(values)"], ' |
99 |
| - '[]]\n') |
| 97 | + input = StringIO(b'["reduce", ' |
| 98 | + b'["def fun(keys, values): return sum(values)"], ' |
| 99 | + b'[]]\n') |
100 | 100 | output = StringIO()
|
101 | 101 | view.run(input=input, output=output)
|
102 | 102 | self.assertEqual(output.getvalue(),
|
103 |
| - '[true, [0]]\n') |
| 103 | + b'[true, [0]]\n') |
104 | 104 |
|
105 | 105 |
|
106 | 106 | def suite():
|
|
0 commit comments