3c4ba62fb264292111d865f50b6021eb68371368
2 # Copyright (C) 2019 EfficiOS Inc.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; only version 2
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 class QueryExecutorTestCase(unittest
.TestCase
):
27 class MySink(bt2
._UserSinkComponent
):
31 def _graph_is_configured(self
):
35 def _query(cls
, query_exec
, obj
, params
, log_level
):
45 'array': ['coucou', 23, None],
54 res
= bt2
.QueryExecutor().query(MySink
, 'obj', params
)
55 self
.assertEqual(query_params
, params
)
56 self
.assertEqual(res
, {
62 def test_query_params_none(self
):
63 class MySink(bt2
._UserSinkComponent
):
67 def _graph_is_configured(self
):
71 def _query(cls
, query_exec
, obj
, params
, log_level
):
76 res
= bt2
.QueryExecutor().query(MySink
, 'obj', None)
77 self
.assertEqual(query_params
, None)
80 def test_query_logging_level(self
):
81 class MySink(bt2
._UserSinkComponent
):
85 def _graph_is_configured(self
):
89 def _query(cls
, query_exec
, obj
, params
, log_level
):
90 nonlocal query_log_level
91 query_log_level
= log_level
93 query_log_level
= None
94 res
= bt2
.QueryExecutor().query(MySink
, 'obj', None,
95 bt2
.LoggingLevel
.INFO
)
96 self
.assertEqual(query_log_level
, bt2
.LoggingLevel
.INFO
)
99 def test_query_gen_error(self
):
100 class MySink(bt2
._UserSinkComponent
):
104 def _graph_is_configured(self
):
108 def _query(cls
, query_exec
, obj
, params
, log_level
):
111 with self
.assertRaises(bt2
.Error
):
112 res
= bt2
.QueryExecutor().query(MySink
, 'obj', [17, 23])
114 def test_query_invalid_object(self
):
115 class MySink(bt2
._UserSinkComponent
):
119 def _graph_is_configured(self
):
123 def _query(cls
, query_exec
, obj
, params
, log_level
):
124 raise bt2
.InvalidObject
126 with self
.assertRaises(bt2
.InvalidObject
):
127 res
= bt2
.QueryExecutor().query(MySink
, 'obj', [17, 23])
129 def test_query_logging_level_invalid_type(self
):
130 class MySink(bt2
._UserSinkComponent
):
134 def _graph_is_configured(self
):
138 def _query(cls
, query_exec
, obj
, params
, log_level
):
141 with self
.assertRaises(TypeError):
142 res
= bt2
.QueryExecutor().query(MySink
, 'obj', [17, 23], 'yeah')
144 def test_query_logging_level_invalid_value(self
):
145 class MySink(bt2
._UserSinkComponent
):
149 def _graph_is_configured(self
):
153 def _query(cls
, query_exec
, obj
, params
, log_level
):
156 with self
.assertRaises(ValueError):
157 res
= bt2
.QueryExecutor().query(MySink
, 'obj', [17, 23], 12345)
159 def test_query_invalid_params(self
):
160 class MySink(bt2
._UserSinkComponent
):
164 def _graph_is_configured(self
):
168 def _query(cls
, query_exec
, obj
, params
, log_level
):
169 raise bt2
.InvalidParams
171 with self
.assertRaises(bt2
.InvalidParams
):
172 res
= bt2
.QueryExecutor().query(MySink
, 'obj', [17, 23])
174 def test_query_try_again(self
):
175 class MySink(bt2
._UserSinkComponent
):
179 def _graph_is_configured(self
):
183 def _query(cls
, query_exec
, obj
, params
, log_level
):
186 with self
.assertRaises(bt2
.TryAgain
):
187 res
= bt2
.QueryExecutor().query(MySink
, 'obj', [17, 23])
189 def test_cancel_no_query(self
):
190 query_exec
= bt2
.QueryExecutor()
191 self
.assertFalse(query_exec
.is_canceled
)
193 self
.assertTrue(query_exec
.is_canceled
)
195 def test_query_canceled(self
):
196 class MySink(bt2
._UserSinkComponent
):
200 def _graph_is_configured(self
):
204 def _query(cls
, query_exec
, obj
, params
, log_level
):
207 query_exec
= bt2
.QueryExecutor()
210 with self
.assertRaises(bt2
.Canceled
):
211 res
= query_exec
.query(MySink
, 'obj', [17, 23])
This page took 0.033111 seconds and 3 git commands to generate.