Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 105 additions & 22 deletions tests/cfg_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from .base_test_case import BaseTestCase
from pyt.node_types import EntryOrExitNode, Node
from pyt.node_types import (
EntryOrExitNode,
Node
)


class CFGGeneralTest(BaseTestCase):
Expand Down Expand Up @@ -215,35 +218,115 @@ def test_orelse(self):
print_good = 18
_exit = 19

self.assertInCfg([self.connected(entry, try_),
self.assertInCfg([
self.connected(entry, try_),

self.connected(try_, try_body),
self.connected(try_, try_body),

self.connected(try_body, print_a5),
self.connected(try_body, print_a5),

self.connected(print_a5, except_im),
self.connected(print_a5, save_node),
self.connected(print_a5, print_good),
self.connected(print_a5, except_im),
self.connected(print_a5, save_node),
self.connected(print_a5, print_good),

self.connected(except_im, except_im_body_1),
self.connected(except_im, except_im_body_1),

self.connected(except_im_body_1, value_equal_call_2),
self.connected(value_equal_call_2, print_wagyu),

self.connected(print_wagyu, print_good),

self.connected(except_im_body_1, value_equal_call_2),
self.connected(value_equal_call_2, print_wagyu),
self.connected(save_node, assign_to_temp),
self.connected(assign_to_temp, assign_from_temp),
self.connected(assign_from_temp, function_entry),
self.connected(function_entry, ret_of_subprocess_call),
self.connected(ret_of_subprocess_call, ret_does_this_kill_us_equal_call_5),
self.connected(ret_does_this_kill_us_equal_call_5, function_exit),
self.connected(function_exit, restore_node),
self.connected(restore_node, return_handler),
self.connected(return_handler, print_so),

self.connected(print_wagyu, print_good),
self.connected(print_so, print_good),
self.connected(print_good, _exit)
])

def test_orelse_with_no_variables_to_save(self):
self.cfg_create_from_file('examples/example_inputs/try_orelse_with_no_variables_to_save.py')

self.connected(save_node, assign_to_temp),
self.connected(assign_to_temp, assign_from_temp),
self.connected(assign_from_temp, function_entry),
self.connected(function_entry, ret_of_subprocess_call),
self.connected(ret_of_subprocess_call, ret_does_this_kill_us_equal_call_5),
self.connected(ret_does_this_kill_us_equal_call_5, function_exit),
self.connected(function_exit, restore_node),
self.connected(restore_node, return_handler),
self.connected(return_handler, print_so),
self.nodes = self.cfg_list_to_dict(self.cfg.nodes)
self.assert_length(self.cfg.nodes, expected_length=15)

self.connected(print_so, print_good),
self.connected(print_good, _exit)])
entry = 0
try_ = 1
print_a5 = 2
except_im = 3
print_wagyu = 4
temp_3_diff = 5
diff = 6
function_entry = 7
ret_subprocess_call = 8
ret_does_this_kill_us_4 = 9
exit_does_this_kill_us = 10
ret_does_this_kill_us_3 = 11
print_so = 12
print_good = 13
_exit = 14

self.assertInCfg([
self.connected(entry, try_),
self.connected(try_, print_a5),
self.connected(print_a5, except_im),
self.connected(print_a5, temp_3_diff),
self.connected(print_a5, print_good),
self.connected(except_im, print_wagyu),
self.connected(print_wagyu, print_good),
self.connected(temp_3_diff, diff),
self.connected(diff, function_entry),
self.connected(function_entry, ret_subprocess_call),
self.connected(ret_subprocess_call, ret_does_this_kill_us_4),
self.connected(ret_does_this_kill_us_4, exit_does_this_kill_us),
self.connected(exit_does_this_kill_us, ret_does_this_kill_us_3),
self.connected(ret_does_this_kill_us_3, print_so),
self.connected(print_so, print_good),
self.connected(print_good, _exit)
])

def test_try_orelse_with_no_variables_to_save_and_no_args(self):
self.cfg_create_from_file('examples/example_inputs/try_orelse_with_no_variables_to_save_and_no_args.py')

self.nodes = self.cfg_list_to_dict(self.cfg.nodes)
self.assert_length(self.cfg.nodes, expected_length=13)

entry = 0
try_ = 1
print_a5 = 2
except_im = 3
print_wagyu = 4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't imagine like that :)

function_entry = 5
ret_subprocess_call = 6
ret_does_this_kill_us_4 = 7
exit_does_this_kill_us = 8
ret_does_this_kill_us_3 = 9
print_so = 10
print_good = 11
_exit = 12

self.assertInCfg([
self.connected(entry, try_),
self.connected(try_, print_a5),
self.connected(print_a5, except_im),
self.connected(print_a5, function_entry),
self.connected(print_a5, print_good),
self.connected(except_im, print_wagyu),
self.connected(print_wagyu, print_good),
self.connected(function_entry, ret_subprocess_call),
self.connected(ret_subprocess_call, ret_does_this_kill_us_4),
self.connected(ret_does_this_kill_us_4, exit_does_this_kill_us),
self.connected(exit_does_this_kill_us, ret_does_this_kill_us_3),
self.connected(ret_does_this_kill_us_3, print_so),
self.connected(print_so, print_good),
self.connected(print_good, _exit)
])

def test_final(self):
self.cfg_create_from_file('examples/example_inputs/try_final.py')
Expand Down