|
1 | 1 | from natrix.rules.unused_arg import UnusedArgRule |
2 | | -from natrix.ast_tools import parse_file |
3 | 2 |
|
4 | 3 |
|
5 | | -def test_unused_arg(): |
| 4 | +def test_unused_arg(test_unused_arg_contract): |
6 | 5 | """ |
7 | 6 | Test that the UnusedArgRule correctly identifies unused function arguments. |
8 | | - |
| 7 | +
|
9 | 8 | This test verifies that: |
10 | 9 | 1. Unused arguments in regular functions are flagged |
11 | 10 | 2. Interface function definitions are not flagged |
12 | 11 | """ |
13 | | - # Parse the test file with unused arguments |
14 | | - ast = parse_file("tests/test_unused_arg.vy") |
15 | | - |
16 | 12 | rule = UnusedArgRule() |
17 | | - issues = rule.run(ast) |
18 | | - |
| 13 | + issues = rule.run(test_unused_arg_contract) |
| 14 | + |
19 | 15 | # Check that only the unused argument is flagged |
20 | 16 | assert len(issues) == 1 |
21 | | - assert issues[0].position == "2:49" # Line for _unused_arg |
| 17 | + assert issues[0].position == "3:49" # Line for _unused_arg |
22 | 18 | assert "_unused_arg" in issues[0].message |
23 | 19 | assert "function_with_unused_arg" in issues[0].message |
24 | | - |
| 20 | + |
25 | 21 | # Verify that used arguments are not flagged |
26 | 22 | for issue in issues: |
27 | 23 | assert "_used_arg" not in issue.message |
28 | 24 | assert "_arg1" not in issue.message |
29 | 25 | assert "_arg2" not in issue.message |
30 | 26 |
|
31 | 27 |
|
32 | | -def test_interface_functions_not_flagged(): |
| 28 | +def test_interface_functions_not_flagged(twocrypto_contract): |
33 | 29 | """ |
34 | 30 | Test that the UnusedArgRule does not flag interface function arguments. |
35 | | - |
| 31 | +
|
36 | 32 | Uses the Twocrypto.vy contract which has interface function definitions. |
37 | 33 | """ |
38 | | - # Load the Twocrypto contract directly |
39 | | - twocrypto_contract = parse_file("tests/contracts/Twocrypto.vy") |
40 | | - |
41 | 34 | rule = UnusedArgRule() |
42 | 35 | issues = rule.run(twocrypto_contract) |
43 | | - |
| 36 | + |
44 | 37 | # Check that no interface function arguments are flagged |
45 | 38 | for issue in issues: |
46 | 39 | # Make sure none of the interface function arguments are flagged |
|
0 commit comments