Skip to content

Commit

Permalink
expand Subprocess testing
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Sjögren <[email protected]>
  • Loading branch information
konstruktoid authored and mschwager committed Oct 14, 2020
1 parent f674212 commit 3320d9a
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions tests/test_bad_subprocess_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ def test_bad_subprocess_usage(self):
"""
import subprocess
command = "/bin/echo"
subprocess.call(shell=True)
subprocess.check_call(shell=True)
subprocess.check_output(shell=True)
subprocess.Popen(shell=True)
subprocess.run(shell=True)
subprocess.run(command,shell=True)
"""
)

Expand All @@ -33,15 +36,61 @@ def test_bad_subprocess_usage(self):
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=4,
lineno=6,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=7,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=8,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=5,
lineno=9,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=10,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=11,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
]

assert result == expected

def test_subprocess_usage(self):
python_node = self.get_ast_node(
"""
import subprocess
command = "/bin/echo"
subprocess.call(command)
subprocess.call(shell=False)
subprocess.check_call(shell=False)
subprocess.check_output(shell=False)
subprocess.Popen(shell=False)
subprocess.run(command)
subprocess.run(shell=False)
"""
)

linter = dlint.linters.BadSubprocessUseLinter()
linter.visit(python_node)

result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=0,
Expand All @@ -57,9 +106,29 @@ def test_bad_subprocess_usage(self):
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=9,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=10,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=11,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=12,
col_offset=0,
message=dlint.linters.BadSubprocessUseLinter._error_tmpl
),
]

assert result == expected
assert result != expected


if __name__ == "__main__":
Expand Down

0 comments on commit 3320d9a

Please sign in to comment.