|
1 | 1 | from .base_test_case import BaseTestCase |
2 | | -from pyt.node_types import EntryOrExitNode, Node |
| 2 | +from pyt.node_types import ( |
| 3 | + EntryOrExitNode, |
| 4 | + Node |
| 5 | +) |
3 | 6 |
|
4 | 7 |
|
5 | 8 | class CFGGeneralTest(BaseTestCase): |
@@ -215,35 +218,115 @@ def test_orelse(self): |
215 | 218 | print_good = 18 |
216 | 219 | _exit = 19 |
217 | 220 |
|
218 | | - self.assertInCfg([self.connected(entry, try_), |
| 221 | + self.assertInCfg([ |
| 222 | + self.connected(entry, try_), |
219 | 223 |
|
220 | | - self.connected(try_, try_body), |
| 224 | + self.connected(try_, try_body), |
221 | 225 |
|
222 | | - self.connected(try_body, print_a5), |
| 226 | + self.connected(try_body, print_a5), |
223 | 227 |
|
224 | | - self.connected(print_a5, except_im), |
225 | | - self.connected(print_a5, save_node), |
226 | | - self.connected(print_a5, print_good), |
| 228 | + self.connected(print_a5, except_im), |
| 229 | + self.connected(print_a5, save_node), |
| 230 | + self.connected(print_a5, print_good), |
227 | 231 |
|
228 | | - self.connected(except_im, except_im_body_1), |
| 232 | + self.connected(except_im, except_im_body_1), |
| 233 | + |
| 234 | + self.connected(except_im_body_1, value_equal_call_2), |
| 235 | + self.connected(value_equal_call_2, print_wagyu), |
| 236 | + |
| 237 | + self.connected(print_wagyu, print_good), |
229 | 238 |
|
230 | | - self.connected(except_im_body_1, value_equal_call_2), |
231 | | - self.connected(value_equal_call_2, print_wagyu), |
| 239 | + self.connected(save_node, assign_to_temp), |
| 240 | + self.connected(assign_to_temp, assign_from_temp), |
| 241 | + self.connected(assign_from_temp, function_entry), |
| 242 | + self.connected(function_entry, ret_of_subprocess_call), |
| 243 | + self.connected(ret_of_subprocess_call, ret_does_this_kill_us_equal_call_5), |
| 244 | + self.connected(ret_does_this_kill_us_equal_call_5, function_exit), |
| 245 | + self.connected(function_exit, restore_node), |
| 246 | + self.connected(restore_node, return_handler), |
| 247 | + self.connected(return_handler, print_so), |
232 | 248 |
|
233 | | - self.connected(print_wagyu, print_good), |
| 249 | + self.connected(print_so, print_good), |
| 250 | + self.connected(print_good, _exit) |
| 251 | + ]) |
| 252 | + |
| 253 | + def test_orelse_with_no_variables_to_save(self): |
| 254 | + self.cfg_create_from_file('examples/example_inputs/try_orelse_with_no_variables_to_save.py') |
234 | 255 |
|
235 | | - self.connected(save_node, assign_to_temp), |
236 | | - self.connected(assign_to_temp, assign_from_temp), |
237 | | - self.connected(assign_from_temp, function_entry), |
238 | | - self.connected(function_entry, ret_of_subprocess_call), |
239 | | - self.connected(ret_of_subprocess_call, ret_does_this_kill_us_equal_call_5), |
240 | | - self.connected(ret_does_this_kill_us_equal_call_5, function_exit), |
241 | | - self.connected(function_exit, restore_node), |
242 | | - self.connected(restore_node, return_handler), |
243 | | - self.connected(return_handler, print_so), |
| 256 | + self.nodes = self.cfg_list_to_dict(self.cfg.nodes) |
| 257 | + self.assert_length(self.cfg.nodes, expected_length=15) |
244 | 258 |
|
245 | | - self.connected(print_so, print_good), |
246 | | - self.connected(print_good, _exit)]) |
| 259 | + entry = 0 |
| 260 | + try_ = 1 |
| 261 | + print_a5 = 2 |
| 262 | + except_im = 3 |
| 263 | + print_wagyu = 4 |
| 264 | + temp_3_diff = 5 |
| 265 | + diff = 6 |
| 266 | + function_entry = 7 |
| 267 | + ret_subprocess_call = 8 |
| 268 | + ret_does_this_kill_us_4 = 9 |
| 269 | + exit_does_this_kill_us = 10 |
| 270 | + ret_does_this_kill_us_3 = 11 |
| 271 | + print_so = 12 |
| 272 | + print_good = 13 |
| 273 | + _exit = 14 |
| 274 | + |
| 275 | + self.assertInCfg([ |
| 276 | + self.connected(entry, try_), |
| 277 | + self.connected(try_, print_a5), |
| 278 | + self.connected(print_a5, except_im), |
| 279 | + self.connected(print_a5, temp_3_diff), |
| 280 | + self.connected(print_a5, print_good), |
| 281 | + self.connected(except_im, print_wagyu), |
| 282 | + self.connected(print_wagyu, print_good), |
| 283 | + self.connected(temp_3_diff, diff), |
| 284 | + self.connected(diff, function_entry), |
| 285 | + self.connected(function_entry, ret_subprocess_call), |
| 286 | + self.connected(ret_subprocess_call, ret_does_this_kill_us_4), |
| 287 | + self.connected(ret_does_this_kill_us_4, exit_does_this_kill_us), |
| 288 | + self.connected(exit_does_this_kill_us, ret_does_this_kill_us_3), |
| 289 | + self.connected(ret_does_this_kill_us_3, print_so), |
| 290 | + self.connected(print_so, print_good), |
| 291 | + self.connected(print_good, _exit) |
| 292 | + ]) |
| 293 | + |
| 294 | + def test_try_orelse_with_no_variables_to_save_and_no_args(self): |
| 295 | + self.cfg_create_from_file('examples/example_inputs/try_orelse_with_no_variables_to_save_and_no_args.py') |
| 296 | + |
| 297 | + self.nodes = self.cfg_list_to_dict(self.cfg.nodes) |
| 298 | + self.assert_length(self.cfg.nodes, expected_length=13) |
| 299 | + |
| 300 | + entry = 0 |
| 301 | + try_ = 1 |
| 302 | + print_a5 = 2 |
| 303 | + except_im = 3 |
| 304 | + print_wagyu = 4 |
| 305 | + function_entry = 5 |
| 306 | + ret_subprocess_call = 6 |
| 307 | + ret_does_this_kill_us_4 = 7 |
| 308 | + exit_does_this_kill_us = 8 |
| 309 | + ret_does_this_kill_us_3 = 9 |
| 310 | + print_so = 10 |
| 311 | + print_good = 11 |
| 312 | + _exit = 12 |
| 313 | + |
| 314 | + self.assertInCfg([ |
| 315 | + self.connected(entry, try_), |
| 316 | + self.connected(try_, print_a5), |
| 317 | + self.connected(print_a5, except_im), |
| 318 | + self.connected(print_a5, function_entry), |
| 319 | + self.connected(print_a5, print_good), |
| 320 | + self.connected(except_im, print_wagyu), |
| 321 | + self.connected(print_wagyu, print_good), |
| 322 | + self.connected(function_entry, ret_subprocess_call), |
| 323 | + self.connected(ret_subprocess_call, ret_does_this_kill_us_4), |
| 324 | + self.connected(ret_does_this_kill_us_4, exit_does_this_kill_us), |
| 325 | + self.connected(exit_does_this_kill_us, ret_does_this_kill_us_3), |
| 326 | + self.connected(ret_does_this_kill_us_3, print_so), |
| 327 | + self.connected(print_so, print_good), |
| 328 | + self.connected(print_good, _exit) |
| 329 | + ]) |
247 | 330 |
|
248 | 331 | def test_final(self): |
249 | 332 | self.cfg_create_from_file('examples/example_inputs/try_final.py') |
|
0 commit comments