Skip to content

Commit

Permalink
Update wrapping to use assert_any_call where necessary (since 3.12 pa…
Browse files Browse the repository at this point in the history
…th.join)
  • Loading branch information
Wout Feys committed Nov 5, 2024
1 parent be86542 commit 828abc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions aikido_zen/sinks/tests/builtins_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def test_open():
with pytest.raises(FileNotFoundError):
open(path)
args = (path,)
mock_run_vulnerability_scan.assert_called_with(kind=kind, op=op, args=args)
# Need to use assert_any_call, since python 3.12 it uses os.path.join
mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args)

path2 = PurePath("./test", "/test.py")
with pytest.raises(FileNotFoundError):
open(path2)
args = (path2,)
mock_run_vulnerability_scan.assert_called_with(kind=kind, op=op, args=args)
# Need to use assert_any_call, since python 3.12 it uses os.path.join
mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args)


def test_open_with_builtins_import():
Expand Down
16 changes: 10 additions & 6 deletions aikido_zen/sinks/tests/os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def test_ospath_commands():

with pytest.raises(FileNotFoundError):
os.path.getsize("aqkqjefbkqlleq_qkvfjksaicuaviel")
op = "os.path.getsize"
args = ("aqkqjefbkqlleq_qkvfjksaicuaviel",)
mock_run_vulnerability_scan.assert_called_with(kind=kind, op=op, args=args)
op = "os.path.getsize"
args = ("aqkqjefbkqlleq_qkvfjksaicuaviel",)
# Need to use assert_any_call, since python 3.12 it uses os.path.join
mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args)

os.path.realpath(b"te2st/test2")
op = "os.path.join"
Expand All @@ -34,7 +35,8 @@ def test_ospath_commands():

op = "os.path.getsize"
args = (path1,)
mock_run_vulnerability_scan.assert_called_with(kind=kind, op=op, args=args)
# Need to use assert_any_call, since python 3.12 it uses os.path.join
mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args)


def test_ospath_command_absolute_path():
Expand Down Expand Up @@ -65,14 +67,16 @@ def test_ospath_expanduser():
os.path.expanduser("../test/test2")
op = "os.path.expanduser"
args = ("../test/test2",)
mock_run_vulnerability_scan.assert_called_with(kind=kind, op=op, args=args)
# Need to use assert_any_call, since python 3.12 it uses os.path.join
mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args)

path1 = Path("./test", "test2", "test3")
os.path.expanduser(path1)

op = "os.path.expanduser"
args = (path1,)
mock_run_vulnerability_scan.assert_called_with(kind=kind, op=op, args=args)
# Need to use assert_any_call, since python 3.12 it uses os.path.join
mock_run_vulnerability_scan.assert_any_call(kind=kind, op=op, args=args)


def test_ospath_expandvars():
Expand Down

0 comments on commit 828abc0

Please sign in to comment.