|
| 1 | +""" |
| 2 | +Live Test Python File for Tier 2 Native Fixer Validation |
| 3 | +
|
| 4 | +This file contains INTENTIONAL issues that should be fixed by tier 2 native tools: |
| 5 | +- F401: Unused imports (ruff --fix, autoflake) |
| 6 | +- F632: is comparison with literal (ruff --fix) |
| 7 | +- E711: comparison to None (ruff --unsafe-fixes) |
| 8 | +- E712: comparison to True/False (ruff --unsafe-fixes) |
| 9 | +- Formatting issues (black, ruff format) |
| 10 | +
|
| 11 | +DO NOT manually fix these issues - they are test fixtures. |
| 12 | +""" |
| 13 | + |
| 14 | +# F401: Unused imports - should be removed by ruff --fix or autoflake |
| 15 | +import os |
| 16 | +import sys |
| 17 | +import json |
| 18 | +import re |
| 19 | +import datetime |
| 20 | +from typing import List, Dict, Optional, Any, Tuple, Union |
| 21 | + |
| 22 | +# Only these imports are actually used |
| 23 | +import hashlib |
| 24 | + |
| 25 | + |
| 26 | +def calculate_hash(data: str) -> str: |
| 27 | + """Calculate MD5 hash of input string.""" |
| 28 | + return hashlib.md5(data.encode()).hexdigest() |
| 29 | + |
| 30 | + |
| 31 | +# F632: is comparison with literal - should use == instead |
| 32 | +# ruff --fix can auto-fix this |
| 33 | +def check_status(status: str) -> bool: |
| 34 | + """Check if status matches expected values.""" |
| 35 | + if status is "active": # F632: use == for literal comparison |
| 36 | + return True |
| 37 | + if status is "pending": # F632: use == for literal comparison |
| 38 | + return True |
| 39 | + if status is "completed": # F632: use == for literal comparison |
| 40 | + return False |
| 41 | + return False |
| 42 | + |
| 43 | + |
| 44 | +# E711: comparison to None using == instead of is |
| 45 | +# ruff --unsafe-fixes can fix this |
| 46 | +def validate_input(value: str) -> bool: |
| 47 | + """Validate that input is not None.""" |
| 48 | + if value == None: # E711: comparison to None should use 'is None' |
| 49 | + return False |
| 50 | + if value != None: # E711: comparison to None should use 'is not None' |
| 51 | + return len(value) > 0 |
| 52 | + return True |
| 53 | + |
| 54 | + |
| 55 | +# E712: comparison to True/False using == instead of direct boolean |
| 56 | +# ruff --unsafe-fixes can fix this |
| 57 | +def check_flags(enabled: bool, active: bool) -> str: |
| 58 | + """Check boolean flags.""" |
| 59 | + if enabled == True: # E712: comparison to True should be 'if enabled' |
| 60 | + if active == False: # E712: comparison to False should be 'if not active' |
| 61 | + return "enabled_but_inactive" |
| 62 | + return "fully_active" |
| 63 | + if enabled == False: # E712: should be 'if not enabled' |
| 64 | + return "disabled" |
| 65 | + return "unknown" |
| 66 | + |
| 67 | + |
| 68 | +# Formatting issues for black/ruff format |
| 69 | +def poorly_formatted_function(arg1:str,arg2:int,arg3:bool=True)->Dict[str,Any]: |
| 70 | + """Function with poor formatting that black/ruff format should fix.""" |
| 71 | + result={"arg1":arg1,"arg2":arg2,"arg3":arg3} |
| 72 | + if arg3==True: |
| 73 | + result["status"]="active" |
| 74 | + return result |
| 75 | + |
| 76 | + |
| 77 | +# Long line that exceeds PEP 8 limit (E501) |
| 78 | +def function_with_long_line(very_long_parameter_name_one: str, very_long_parameter_name_two: str, very_long_parameter_name_three: str) -> str: |
| 79 | + """Function with overly long line.""" |
| 80 | + return f"{very_long_parameter_name_one}_{very_long_parameter_name_two}_{very_long_parameter_name_three}" |
| 81 | + |
| 82 | + |
| 83 | +# Missing whitespace around operators |
| 84 | +def bad_spacing(x:int,y:int)->int: |
| 85 | + """Function with bad spacing.""" |
| 86 | + result=x+y*2 |
| 87 | + if result>100: |
| 88 | + result=100 |
| 89 | + return result |
| 90 | + |
| 91 | + |
| 92 | +# Class with formatting issues |
| 93 | +class BadlyFormattedClass: |
| 94 | + """Class with various formatting issues.""" |
| 95 | + |
| 96 | + def __init__(self,name:str,value:int)->None: |
| 97 | + self.name=name |
| 98 | + self.value=value |
| 99 | + |
| 100 | + def get_info(self)->Dict[str,Any]: |
| 101 | + """Get class info.""" |
| 102 | + return {"name":self.name,"value":self.value} |
| 103 | + |
| 104 | + def compare(self,other:"BadlyFormattedClass")->bool: |
| 105 | + """Compare with another instance.""" |
| 106 | + if other==None: # E711 |
| 107 | + return False |
| 108 | + if self.value is 0: # F632 |
| 109 | + return other.value is 0 # F632 |
| 110 | + return self.value==other.value |
| 111 | + |
| 112 | + |
| 113 | +# Mixed issues in one function |
| 114 | +def complex_function(data: Optional[str], flag: bool) -> Optional[str]: |
| 115 | + """Function combining multiple issues.""" |
| 116 | + if data is "test": # F632 |
| 117 | + if flag == True: # E712 |
| 118 | + return "test_active" |
| 119 | + if data == None: # E711 |
| 120 | + return None |
| 121 | + if flag == False: # E712 |
| 122 | + return data.lower() |
| 123 | + return data |
| 124 | + |
| 125 | + |
| 126 | +# Trailing whitespace and inconsistent indentation (formatting) |
| 127 | +def whitespace_issues(items): |
| 128 | + """Function with whitespace issues.""" |
| 129 | + for item in items: |
| 130 | + if item is "skip": |
| 131 | + continue |
| 132 | + yield item |
| 133 | + |
| 134 | + |
| 135 | +if __name__ == "__main__": |
| 136 | + # Test the functions |
| 137 | + print(calculate_hash("test")) |
| 138 | + print(check_status("active")) |
| 139 | + print(validate_input("hello")) |
| 140 | + print(check_flags(True, False)) |
| 141 | + print(poorly_formatted_function("test", 42)) |
0 commit comments