From f86410d8aa7d47691a02fa5484ce37f148b3424d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20G=C3=BCnal?= Date: Wed, 2 May 2018 00:56:32 +0300 Subject: [PATCH 1/3] Test for "try_orelse_with_no_variables_to_save" --- tests/cfg_test.py | 92 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/tests/cfg_test.py b/tests/cfg_test.py index f3a3a28a..ce73ccb9 100644 --- a/tests/cfg_test.py +++ b/tests/cfg_test.py @@ -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): @@ -215,35 +218,80 @@ 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(except_im_body_1, value_equal_call_2), + self.connected(value_equal_call_2, print_wagyu), + + self.connected(print_wagyu, print_good), + + 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_so, print_good), + self.connected(print_good, _exit) + ]) - self.connected(print_wagyu, print_good), + 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) + + 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), + + ]) - 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') From 54e9563a57c4273f58ae00dfb1306ce814ecbcf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20G=C3=BCnal?= Date: Wed, 2 May 2018 01:23:56 +0300 Subject: [PATCH 2/3] created new test created "test_try_orelse_with_no_variables_to_save_and_no_args" --- tests/cfg_test.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/cfg_test.py b/tests/cfg_test.py index ce73ccb9..2f7ef192 100644 --- a/tests/cfg_test.py +++ b/tests/cfg_test.py @@ -292,6 +292,43 @@ def test_orelse_with_no_variables_to_save(self): ]) + 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 + 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') From a7be197e26604754ba64930a34b18d7bb1113931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20G=C3=BCnal?= Date: Wed, 2 May 2018 11:46:35 +0300 Subject: [PATCH 3/3] unnecessary lines removed in self.assertInCfg --- tests/cfg_test.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/cfg_test.py b/tests/cfg_test.py index 2f7ef192..9bd49255 100644 --- a/tests/cfg_test.py +++ b/tests/cfg_test.py @@ -288,9 +288,8 @@ def test_orelse_with_no_variables_to_save(self): 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), - - ]) + 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') @@ -326,8 +325,7 @@ def test_try_orelse_with_no_variables_to_save_and_no_args(self): 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), - + self.connected(print_good, _exit) ]) def test_final(self):