Skip to content

Commit

Permalink
[flake8] Just fix flake8 errors for PR #114
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHock committed Jun 14, 2018
1 parent 052c850 commit 7854cb4
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 109 deletions.
2 changes: 1 addition & 1 deletion pyt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)


def main(command_line_args=sys.argv[1:]):
def main(command_line_args=sys.argv[1:]): # noqa: C901
args = parse_args(command_line_args)

ui_mode = UImode.NORMAL
Expand Down
2 changes: 1 addition & 1 deletion pyt/cfg/stmt_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def append_node(self, node):
self.nodes.append(node)
return node

def add_module(
def add_module( # noqa: C901
self,
module,
module_or_package_name,
Expand Down
2 changes: 1 addition & 1 deletion pyt/core/ast_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def convert_to_3(path): # pragma: no cover
try:
print('##### Trying to convert file to Python 3. #####')
subprocess.call(['2to3', '-w', path])
except:
except subprocess.SubprocessError:
print('Check if 2to3 is installed. '
'https://docs.python.org/2/library/2to3.html')
exit(1)
Expand Down
20 changes: 17 additions & 3 deletions pyt/core/project_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ def get_modules(path):
for root, directories, filenames in os.walk(path):
for filename in filenames:
if is_python_file(filename):
directory = os.path.dirname(os.path.realpath(os.path.join(root, filename))).split(module_root)[-1].replace(os.sep, '.')
directory = os.path.dirname(
os.path.realpath(
os.path.join(
root,
filename
)
)
).split(module_root)[-1].replace(
os.sep, # e.g. '/'
'.'
)
directory = directory.replace('.', '', 1)
if directory:
modules.append(('.'.join((module_root, directory, filename.replace('.py', ''))), os.path.join(root, filename)))
modules.append(
('.'.join((module_root, directory, filename.replace('.py', ''))), os.path.join(root, filename))
)
else:
modules.append(('.'.join((module_root, filename.replace('.py', ''))), os.path.join(root, filename)))
modules.append(
('.'.join((module_root, filename.replace('.py', ''))), os.path.join(root, filename))
)

return modules

Expand Down
62 changes: 42 additions & 20 deletions tests/analysis/reaching_definitions_taint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def test_linear_program(self):
"Label: ~call_1 = ret_input(): Label: ~call_1 = ret_input()",
"Label: x = ~call_1: Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: y = x - 1: Label: y = x - 1, Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: ~call_2 = ret_print(x): Label: ~call_2 = ret_print(x), Label: y = x - 1, Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: Exit module: Label: ~call_2 = ret_print(x), Label: y = x - 1, Label: x = ~call_1, Label: ~call_1 = ret_input()"
"""Label: ~call_2 = ret_print(x): Label: ~call_2 = ret_print(x), Label: y = x - 1,
Label: x = ~call_1, Label: ~call_1 = ret_input()""",
"""Label: Exit module: Label: ~call_2 = ret_print(x), Label: y = x - 1, Label: x = ~call_1,
Label: ~call_1 = ret_input()"""
]
i = 0
for k, v in constraint_table.items():
Expand All @@ -31,8 +33,10 @@ def test_if_program(self):
"Label: x = ~call_1: Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: if x > 0:: Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: y = x + 1: Label: y = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: ~call_2 = ret_print(x): Label: ~call_2 = ret_print(x), Label: y = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: Exit module: Label: ~call_2 = ret_print(x), Label: y = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_input()"
"""Label: ~call_2 = ret_print(x): Label: ~call_2 = ret_print(x), Label: y = x + 1,
Label: x = ~call_1, Label: ~call_1 = ret_input()""",
"""Label: Exit module: Label: ~call_2 = ret_print(x), Label: y = x + 1, Label: x = ~call_1,
Label: ~call_1 = ret_input()"""
]
i = 0
for k, v in constraint_table.items():
Expand All @@ -49,16 +53,28 @@ def test_example(self):
"Label: x = ~call_1: Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: ~call_2 = ret_int(x): Label: ~call_2 = ret_int(x), Label: x = ~call_1, Label: ~call_1 = ret_input()",
"Label: x = ~call_2: Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: while x > 1:: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: y = x / 2: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: if y > 3:: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: x = x - y: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: z = x - 4: Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: if z > 0:: Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: x = x / 2: Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: z = z - 1: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: ~call_3 = ret_print(x): Label: ~call_3 = ret_print(x), Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()",
"Label: Exit module: Label: ~call_3 = ret_print(x), Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()"
"""Label: while x > 1:: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2,
Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: y = x / 2: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2,
Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: if y > 3:: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2,
Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: x = x - y: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2,
Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: z = x - 4: Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2,
Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: if z > 0:: Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2,
Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: x = x / 2: Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2, Label: x = ~call_2,
Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: z = z - 1: Label: z = z - 1, Label: x = x / 2, Label: z = x - 4, Label: x = x - y, Label: y = x / 2,
Label: x = ~call_2, Label: ~call_2 = ret_int(x), Label: ~call_1 = ret_input()""",
"""Label: ~call_3 = ret_print(x): Label: ~call_3 = ret_print(x), Label: z = z - 1, Label: x = x / 2, Label: z = x - 4,
Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x),
Label: ~call_1 = ret_input()""",
"""Label: Exit module: Label: ~call_3 = ret_print(x), Label: z = z - 1, Label: x = x / 2, Label: z = x - 4,
Label: x = x - y, Label: y = x / 2, Label: x = ~call_2, Label: ~call_2 = ret_int(x),
Label: ~call_1 = ret_input()"""
]
i = 0
for k, v in constraint_table.items():
Expand Down Expand Up @@ -88,13 +104,19 @@ def test_while(self):
"Label: ~call_2 = ret_input(): Label: ~call_2 = ret_input()",
"Label: ~call_1 = ret_int(~call_2): Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()",
"Label: x = ~call_1: Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()",
"Label: while x < 10:: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input(",
"Label: x = x + 1: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()",
"Label: if x == 5:: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()",
"Label: BreakNode: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()",
"""Label: while x < 10:: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2),
Label: ~call_2 = ret_input(""",
"""Label: x = x + 1: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2),
Label: ~call_2 = ret_input()""",
"""Label: if x == 5:: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2),
Label: ~call_2 = ret_input()""",
"""Label: BreakNode: Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2),
Label: ~call_2 = ret_input()""",
"Label: x = 6: Label: x = 6, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()",
"Label: ~call_3 = ret_print(x): Label: ~call_3 = ret_print(x), Label: x = 6, Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()",
"Label: Exit module: Label: ~call_3 = ret_print(x), Label: x = 6, Label: x = x + 1, Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()"
"""Label: ~call_3 = ret_print(x): Label: ~call_3 = ret_print(x), Label: x = 6, Label: x = x + 1,
Label: x = ~call_1, Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()""",
"""Label: Exit module: Label: ~call_3 = ret_print(x), Label: x = 6, Label: x = x + 1, Label: x = ~call_1,
Label: ~call_1 = ret_int(~call_2), Label: ~call_2 = ret_input()"""
]
i = 0
for k, v in constraint_table.items():
Expand Down
Loading

0 comments on commit 7854cb4

Please sign in to comment.