Skip to content

Commit

Permalink
adding test for getNosec
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuczer committed Apr 7, 2023
1 parent e629095 commit 8462690
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/unit/core/test_get_nosec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import unittest
from bandit.core.utils import get_nosec

class TestGetNosec(unittest.TestCase):
def test_nested_dict_nosec(self):
# Mock the nosec lines and context with nested dictionary annotations
nosec_lines = {
5: "# nosec B101",
10: {
15: "# nosec B303"
}
}
context = {
"lineno": 10,
"linerange": [15]
}

# Mock the expected result
expected_result = {15: "# nosec B303"}
print(expected_result)

# Call the function and check the result
result = get_nosec(nosec_lines, context)
self.assertEqual(result, expected_result)

def test_higher_nosec_ignored(self):
# Mock the nosec lines and context with a higher level nosec annotation
nosec_lines = {
5: "# nosec B101",
10: "# nosec B303"
}
# Mock the context with a nested dictionary annotation
context = {
"lineno": 10,
"linerange": [15]
}

# Mock the expected result
expected_result = "# nosec B303"
print(expected_result)

# Call the function and check the result
result = get_nosec(nosec_lines, context)
self.assertEqual(result, expected_result)


if __name__ == '__main__':
unittest.main()

0 comments on commit 8462690

Please sign in to comment.